z4blockchain 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/z4blockchain/version.rb +1 -1
- data/lib/z4blockchain.rb +47 -47
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0a4f9f56971749fdb31d87e61c323dd9d8ea4226b7797223740f15cb1d81da5
|
4
|
+
data.tar.gz: 20d63d9b42018b3efd07832227b780d280a88a5d052534207215bf73e61acf66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e06d93943e3b88130f6ccf0d42cc9bb067b73c0c20e1dbcb08f54b391154352f6d4e62b9c317c8e29b8d0c1005974ab20d94b74f3a81addc50a367fc428f7f55
|
7
|
+
data.tar.gz: b02547f8bd6289f513f7e2df59dcedc624b526fa75f37a5f8afa6aa2eb33b1bde6567724388bf8145c655670ca7426b9becde633267966efda626003363b119b
|
data/lib/z4blockchain/version.rb
CHANGED
data/lib/z4blockchain.rb
CHANGED
@@ -17,21 +17,21 @@ if !Dir.exist? 'db'
|
|
17
17
|
end
|
18
18
|
|
19
19
|
module Z4BC
|
20
|
-
|
20
|
+
|
21
21
|
BLOCKCHAIN = Blockchain.new
|
22
|
-
|
22
|
+
|
23
23
|
MINES = PStore.new("db/mines.pstore")
|
24
24
|
|
25
25
|
BANKS = PStore.new("db/banks.pstore")
|
26
|
-
|
26
|
+
|
27
27
|
BANK = Hash.new { |h,k| h[k] = Bank.new(k) }
|
28
|
-
|
28
|
+
|
29
29
|
GAMES = PStore.new("db/games.pstore")
|
30
30
|
|
31
31
|
GAME = Hash.new { |h,k| h[k] = Game.new(k) }
|
32
|
-
|
32
|
+
|
33
33
|
LVLS = PStore.new("db/lvls.pstore")
|
34
|
-
|
34
|
+
|
35
35
|
LVL = Hash.new { |h,k| h[k] = Lvls.new(k) }
|
36
36
|
|
37
37
|
USER = Hash.new { |h,k| h[k] = User.new(k) }
|
@@ -41,11 +41,11 @@ module Z4BC
|
|
41
41
|
def self.digest k
|
42
42
|
Digest::SHA256.hexdigest(k)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def self.chain
|
46
46
|
BLOCKCHAIN
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def self.last
|
50
50
|
BLOCKCHAIN[-1]
|
51
51
|
end
|
@@ -53,20 +53,20 @@ module Z4BC
|
|
53
53
|
def self.<< h={}
|
54
54
|
BLOCKCHAIN << JSON.generate(h)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
##
|
58
58
|
# Economy
|
59
59
|
#
|
60
60
|
# Each channel controls it's own "Bank".
|
61
61
|
# Users within the channel fund it through payment for channel services.
|
62
62
|
# Users may reconcile obligations between each other for a fee.
|
63
|
-
|
63
|
+
|
64
64
|
def self.free
|
65
65
|
x = 0
|
66
66
|
BANKS.transaction { |db| db.keys.each { |e| x += db[e] } }
|
67
67
|
return x
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def self.mined
|
71
71
|
x = 0
|
72
72
|
MINES.transaction { |db| db.keys.each { |e| x += db[e] } }
|
@@ -85,13 +85,13 @@ module Z4BC
|
|
85
85
|
BANK.each_pair { |k,v| h[k] = v[u] }
|
86
86
|
return h
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def self.balance u
|
90
90
|
x = 0
|
91
91
|
BANK.each_pair { |k,v| x += v[u] }
|
92
92
|
return x
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def self.bank b
|
96
96
|
BANK[b]
|
97
97
|
end
|
@@ -114,15 +114,15 @@ module Z4BC
|
|
114
114
|
BLOCKCHAIN << JSON.generate(h)
|
115
115
|
return nil
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
def self.game
|
119
119
|
GAME
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def self.user
|
123
123
|
USER
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
def self.level
|
127
127
|
LVLS
|
128
128
|
end
|
@@ -134,7 +134,7 @@ module Z4BC
|
|
134
134
|
class User
|
135
135
|
|
136
136
|
attr_accessor :id
|
137
|
-
|
137
|
+
|
138
138
|
attr_reader :game, :wins, :lvls
|
139
139
|
|
140
140
|
def initialize i
|
@@ -143,7 +143,7 @@ module Z4BC
|
|
143
143
|
@wins = PStore.new("db/player-wins-#{i}.pstore")
|
144
144
|
@lvls = PStore.new("db/player-lvls-#{i}.pstore")
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
def to_h
|
148
148
|
h = { game: {}, wins: {}, lvls: {} }
|
149
149
|
@game.transaction { |db| db.keys.each { |e| h[:game][e] = db[e] } }
|
@@ -152,11 +152,11 @@ module Z4BC
|
|
152
152
|
return h
|
153
153
|
end
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
class Game
|
157
|
-
|
157
|
+
|
158
158
|
attr_accessor :id
|
159
|
-
|
159
|
+
|
160
160
|
attr_reader :game, :wins, :lvls
|
161
161
|
|
162
162
|
def initialize i
|
@@ -172,36 +172,36 @@ module Z4BC
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def play h={}
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
175
|
+
GAMES.transaction { |db| x = db[@id].to_i; db[@id] = x + 1 }
|
176
|
+
@wins.transaction { |db|
|
177
|
+
x = db[h[:winner]].to_i;
|
178
|
+
db[h[:winner]] = x + 1;
|
179
|
+
u = USER[h[:winner]]
|
180
|
+
u.wins.transaction { |ddb| x = ddb[@id].to_i; ddb[@id] = x + 1; }
|
181
|
+
}
|
182
|
+
@game.transaction { |db|
|
183
|
+
[h[:players]].flatten.each { |e|
|
184
|
+
x = db[e].to_i;
|
185
|
+
db[e] = x + 1;
|
186
|
+
u = USER[e]
|
187
|
+
u.game.transaction { |ddb| x = ddb[@id].to_i; ddb[@id] = x + 1; }
|
188
|
+
}
|
189
|
+
}
|
190
|
+
if h.has_key? :award
|
191
|
+
@lvls.transaction { |db|
|
192
|
+
db[h[:award]] = h[:winner]
|
193
|
+
u = User.new(h[:winner])
|
194
|
+
u.lvls.transaction { |ddb|
|
195
|
+
LVL[h[:award]].incr h[:winner]
|
196
|
+
}
|
197
|
+
}
|
198
|
+
end
|
199
199
|
end
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
class Lvls
|
203
203
|
attr_accessor :id
|
204
|
-
|
204
|
+
|
205
205
|
attr_reader :user
|
206
206
|
|
207
207
|
def initialize i
|