zold 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/bin/zold +21 -81
- data/fixtures/keys/1.pub +1 -0
- data/fixtures/keys/2 +51 -0
- data/fixtures/keys/2.pub +1 -0
- data/fixtures/scripts/print-helps.sh +15 -0
- data/fixtures/scripts/push-and-pull.sh +7 -3
- data/lib/zold/commands/clean.rb +24 -7
- data/lib/zold/commands/create.rb +16 -4
- data/lib/zold/commands/diff.rb +32 -9
- data/lib/zold/commands/fetch.rb +36 -9
- data/lib/zold/commands/invoice.rb +64 -0
- data/lib/zold/commands/list.rb +1 -1
- data/lib/zold/commands/merge.rb +31 -10
- data/lib/zold/commands/node.rb +6 -2
- data/lib/zold/commands/pay.rb +40 -17
- data/lib/zold/commands/propagate.rb +34 -14
- data/lib/zold/commands/push.rb +27 -9
- data/lib/zold/commands/remote.rb +63 -34
- data/lib/zold/commands/show.rb +34 -9
- data/lib/zold/copies.rb +4 -0
- data/lib/zold/http.rb +1 -1
- data/lib/zold/key.rb +17 -11
- data/lib/zold/node/farm.rb +8 -0
- data/lib/zold/node/front.rb +13 -3
- data/lib/zold/patch.rb +8 -8
- data/lib/zold/prefixes.rb +53 -0
- data/lib/zold/remotes.rb +6 -0
- data/lib/zold/score.rb +4 -4
- data/lib/zold/signature.rb +9 -9
- data/lib/zold/txn.rb +111 -0
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +32 -59
- data/lib/zold/wallets.rb +2 -2
- data/test/commands/test_clean.rb +5 -4
- data/test/commands/test_create.rb +3 -3
- data/test/commands/test_diff.rb +16 -15
- data/test/commands/test_fetch.rb +13 -11
- data/test/commands/test_invoice.rb +46 -0
- data/test/commands/test_list.rb +4 -4
- data/test/commands/test_merge.rb +21 -22
- data/test/commands/test_node.rb +9 -9
- data/test/commands/test_pay.rb +12 -12
- data/test/commands/test_remote.rb +11 -11
- data/test/commands/test_show.rb +9 -7
- data/test/node/fake_node.rb +3 -3
- data/test/node/test_farm.rb +1 -1
- data/test/node/test_front.rb +6 -6
- data/test/test_amount.rb +1 -1
- data/test/test_copies.rb +1 -1
- data/test/test_http.rb +1 -1
- data/test/test_id.rb +1 -1
- data/test/test_key.rb +19 -1
- data/test/test_patch.rb +11 -11
- data/test/test_prefixes.rb +46 -0
- data/test/test_remotes.rb +1 -1
- data/test/test_score.rb +1 -1
- data/test/test_signature.rb +9 -11
- data/test/test_wallet.rb +22 -21
- data/test/test_wallets.rb +4 -4
- metadata +12 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1bcd34bba59aafa0887d0d1901844373598806a
|
4
|
+
data.tar.gz: cdc027656c02317a0087311135a89ea9d211a02a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abc7efeaf98c35608460d912a23c7d65b8b67b1bf9f6e5e5bdaea319f1c948873ac5280a66e6cee0417d3eb1e6bb99b46a24be98c42f8c295b4f0d6fb3464f2f
|
7
|
+
data.tar.gz: 24b68ba90828a813e8c287b277bc9d1f599b8c4e15f3916aa85da6497d0deabc32ec67e24b7feab8f38dbd21fd994dbd6e1ac43f0678c631a8ea423cba0cb9fd
|
data/README.md
CHANGED
data/bin/zold
CHANGED
@@ -54,12 +54,16 @@ Available commands:
|
|
54
54
|
Remove expired local copies
|
55
55
|
#{Rainbow('merge').green} [ID...]
|
56
56
|
Merge remote copies with the HEAD
|
57
|
+
#{Rainbow('propagate').green} [ID...]
|
58
|
+
Propagate transactions to receiving wallets
|
57
59
|
#{Rainbow('pull').green} [ID...]
|
58
60
|
Fetch and then merge
|
59
61
|
#{Rainbow('show').green} [ID...]
|
60
62
|
Show all available information about the wallet
|
61
|
-
#{Rainbow('pay').green}
|
63
|
+
#{Rainbow('pay').green} from to amount details
|
62
64
|
Pay ZOLD from one wallet to another
|
65
|
+
#{Rainbow('invoice').green} ID
|
66
|
+
Generate invoice unique ID for a payment
|
63
67
|
#{Rainbow('status').green}
|
64
68
|
Show status of local copies
|
65
69
|
#{Rainbow('push').green} [ID...]
|
@@ -120,107 +124,43 @@ Available options:"
|
|
120
124
|
).run(args)
|
121
125
|
when 'remote'
|
122
126
|
require_relative '../lib/zold/commands/remote'
|
123
|
-
Zold::Remote.new(
|
124
|
-
|
125
|
-
|
126
|
-
).run(args)
|
127
|
+
Zold::Remote.new(remotes: remotes, log: log).run(args)
|
128
|
+
when 'invoice'
|
129
|
+
require_relative '../lib/zold/commands/invoice'
|
130
|
+
Zold::Invoice.new(wallets: wallets, log: log).run(args)
|
127
131
|
when 'pay'
|
128
|
-
raise "Payer wallet ID is required" if args[0].nil?
|
129
|
-
raise "Recepient wallet ID is required" if args[1].nil?
|
130
|
-
raise "Amount is required (in Zolds)" if args[2].nil?
|
131
132
|
require_relative '../lib/zold/commands/pay'
|
132
133
|
Zold::Pay.new(
|
133
|
-
|
134
|
-
receiver: Zold::Id.new(args[1]),
|
135
|
-
amount: Zold::Amount.new(zld: args[2].to_f),
|
136
|
-
details: opts.arguments[4] ? args[3] : '-',
|
134
|
+
wallets: wallets,
|
137
135
|
pvtkey: Zold::Key.new(file: opts['private-key']),
|
138
136
|
log: log
|
139
137
|
).run(args)
|
140
138
|
when 'show'
|
141
|
-
|
142
|
-
|
143
|
-
Zold::List.new(
|
144
|
-
wallets: wallets,
|
145
|
-
log: log
|
146
|
-
).run(args)
|
147
|
-
else
|
148
|
-
require_relative '../lib/zold/commands/show'
|
149
|
-
args.each do |id|
|
150
|
-
Zold::Show.new(
|
151
|
-
wallet: wallets.find(Zold::Id.new(id)),
|
152
|
-
log: log
|
153
|
-
).run(args)
|
154
|
-
end
|
155
|
-
end
|
139
|
+
require_relative '../lib/zold/commands/show'
|
140
|
+
Zold::Show.new(wallets: wallets, log: log).run(args)
|
156
141
|
when 'fetch'
|
157
142
|
require_relative '../lib/zold/commands/fetch'
|
158
|
-
|
159
|
-
Zold::Fetch.new(
|
160
|
-
id: Zold::Id.new(id),
|
161
|
-
remotes: remotes,
|
162
|
-
copies: Zold::Copies.new(File.join(copies, id)),
|
163
|
-
log: log
|
164
|
-
).run(args)
|
165
|
-
end
|
143
|
+
Zold::Fetch.new(remotes: remotes, copies: copies, log: log).run(args)
|
166
144
|
when 'clean'
|
167
145
|
require_relative '../lib/zold/commands/clean'
|
168
|
-
|
169
|
-
args = Dir.new(copies).select { |f| f =~ /[0-9a-fA-F]{16}/ }
|
170
|
-
end
|
171
|
-
args.each do |id|
|
172
|
-
Zold::Clean.new(
|
173
|
-
copies: Zold::Copies.new(File.join(copies, id)),
|
174
|
-
log: log
|
175
|
-
).run(args)
|
176
|
-
end
|
146
|
+
Zold::Clean.new(copies: copies, log: log).run(args)
|
177
147
|
when 'diff'
|
178
148
|
require_relative '../lib/zold/commands/diff'
|
179
|
-
|
180
|
-
Zold::Diff.new(
|
181
|
-
wallet: wallets.find(Zold::Id.new(id)),
|
182
|
-
copies: Zold::Copies.new(File.join(copies, id)),
|
183
|
-
log: log
|
184
|
-
).run(args)
|
185
|
-
end
|
149
|
+
Zold::Diff.new(wallets: wallets, copies: copies, log: log).run(args)
|
186
150
|
when 'merge'
|
187
151
|
require_relative '../lib/zold/commands/merge'
|
152
|
+
Zold::Merge.new(wallets: wallets, copies: copies, log: log).run(args)
|
153
|
+
when 'propagate'
|
188
154
|
require_relative '../lib/zold/commands/propagate'
|
189
|
-
|
190
|
-
Zold::Merge.new(
|
191
|
-
wallet: wallets.find(Zold::Id.new(id)),
|
192
|
-
copies: Zold::Copies.new(File.join(copies, id)),
|
193
|
-
log: log
|
194
|
-
).run(args)
|
195
|
-
Zold::Propagate.new(
|
196
|
-
wallet: wallets.find(Zold::Id.new(id)),
|
197
|
-
wallets: wallets,
|
198
|
-
log: log
|
199
|
-
).run(args)
|
200
|
-
end
|
155
|
+
Zold::Propagate.new(wallets: wallets, log: log).run(args)
|
201
156
|
when 'pull'
|
202
157
|
require_relative '../lib/zold/commands/fetch'
|
158
|
+
Zold::Fetch.new(remotes: remotes, copies: copies, log: log).run(args)
|
203
159
|
require_relative '../lib/zold/commands/merge'
|
204
|
-
|
205
|
-
Zold::Fetch.new(
|
206
|
-
id: Zold::Id.new(id),
|
207
|
-
remotes: remotes,
|
208
|
-
copies: Zold::Copies.new(File.join(copies, id)),
|
209
|
-
log: log
|
210
|
-
).run(args)
|
211
|
-
Zold::Merge.new(
|
212
|
-
wallet: wallets.find(Zold::Id.new(id)),
|
213
|
-
copies: Zold::Copies.new(File.join(copies, id)),
|
214
|
-
log: log
|
215
|
-
).run(args)
|
216
|
-
end
|
160
|
+
Zold::Merge.new(wallets: wallets, copies: copies, log: log).run(args)
|
217
161
|
when 'push'
|
218
162
|
require_relative '../lib/zold/commands/push'
|
219
|
-
Zold::Push.new(
|
220
|
-
wallet: wallets.find(Zold::Id.new(args[0])),
|
221
|
-
remotes: remotes,
|
222
|
-
log: log
|
223
|
-
).run(args)
|
163
|
+
Zold::Push.new(wallets: wallets, remotes: remotes, log: log).run(args)
|
224
164
|
when 'score'
|
225
165
|
require_relative '../lib/zold/score'
|
226
166
|
if args.length != 3
|
data/fixtures/keys/1.pub
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDFCn75hNu6+tmqn6NWtqrbN87WvlfRmGlyrUY0OLdofydrNUqEfhBzU+jPlYVM4TaMGs3mPxrhXbXhfEngZihzkQ08MJ/Sez0ecDMTsubsEVN6kDEQ3pPoCWo3YGHSsPQ8XYrufQMeqh/oCFlqXaLX5CLgjNk3q384mmdN/94JDpmsX+6nLdwhXRmgDQYSBZBJBq4nAgrjY0GC/g/k0GMshahI204xbNOlmqOvj8k2C7XYmTWAMEDtQMFedqIGHOw9dB2n6VOvLiVnfJty/u/HRuyHtZFYLt1/qhBhwousoD2gJKh7DJoOvzSnOMlIJ6TiIucx0PPR4co7Ioc2UOdj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uV5uNSUdG0jP3ct0MxnTOyXeUhZ3vrJ2hRp/N5HEXzqg8e8zy//xB4ncLclG7WCui39Y9dHmatR47qG2yQMOei4Pcwbh3Lzqw9Kntw6HYYMcf1HrhLX7VTLMFBQtxnjxXXfCuVboEMDp9Dt7YHPNuVCTvmnj/xB3xIOFZkTNPQfdx0kH2JsQknjDZPOl/goV3rcBrbS1pqiCFOCro2WhBhWUxW0QeILDDMcFn1S11iuJTmrGZNXV2Hh8ATF//BUkShPcC3MS3KUHKjo7rXzg8C5uhscM6UiWWkRZLLiC3k7q562l4LUzMnR5+bR5yE5d/rF6wWI6DPoiXPnFoP+UbcZ96IBRA3tk1bz68LPGK4PpiPcXjA6T8Bud3MdOEzhfIPWUxqno9RXpwNfryrqsCfkVTzTDHoNLgDHoTY5FDk5PWOlx3dw8Rc1JAPEqAcdagm7Cgeak/cjV0JVbTxQb3RXOqdPBTnacIm6HNEWcbjnQvx29/8U9RCkd0vPfJWpRQ== yegor256@gmail.com
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -x
|
3
|
+
set -e
|
4
|
+
shopt -s expand_aliases
|
5
|
+
|
6
|
+
alias zold="$1"
|
7
|
+
|
8
|
+
zold --help
|
9
|
+
declare -a commands=(node create invoice remote pay show fetch clean diff merge propagate pull push)
|
10
|
+
for c in "${commands[@]}"
|
11
|
+
do
|
12
|
+
zold --trace $c --help
|
13
|
+
done
|
14
|
+
|
15
|
+
echo 'DONE'
|
@@ -23,13 +23,17 @@ zold remote add localhost ${port}
|
|
23
23
|
zold remote show
|
24
24
|
|
25
25
|
zold --public-key id_rsa.pub create 0000000000000000
|
26
|
-
zold --
|
26
|
+
target=`zold --public-key id_rsa.pub create`
|
27
|
+
invoice=`zold invoice ${target}`
|
28
|
+
zold --private-key id_rsa pay 0000000000000000 ${invoice} 14.99 'To save the world!'
|
29
|
+
zold propagate 0000000000000000
|
27
30
|
zold show
|
28
31
|
zold show 0000000000000000
|
29
32
|
|
30
33
|
zold push 0000000000000000
|
31
|
-
zold fetch 0000000000000000
|
34
|
+
zold fetch 0000000000000000 --ignore-score-weakness
|
32
35
|
zold diff 0000000000000000
|
33
|
-
zold
|
36
|
+
zold merge 0000000000000000
|
37
|
+
zold clean 0000000000000000
|
34
38
|
|
35
39
|
echo 'DONE'
|
data/lib/zold/commands/clean.rb
CHANGED
@@ -21,9 +21,10 @@
|
|
21
21
|
require 'uri'
|
22
22
|
require 'json'
|
23
23
|
require 'time'
|
24
|
-
require_relative '../log
|
25
|
-
require_relative '../http
|
26
|
-
require_relative '../score
|
24
|
+
require_relative '../log'
|
25
|
+
require_relative '../http'
|
26
|
+
require_relative '../score'
|
27
|
+
require_relative '../copies'
|
27
28
|
|
28
29
|
# CLEAN command.
|
29
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -37,10 +38,26 @@ module Zold
|
|
37
38
|
@log = log
|
38
39
|
end
|
39
40
|
|
40
|
-
def run(
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def run(args = [])
|
42
|
+
opts = Slop.parse(args, help: true) do |o|
|
43
|
+
o.banner = "Usage: zold clean [ID...] [options]
|
44
|
+
Available options:"
|
45
|
+
o.bool '--help', 'Print instructions'
|
46
|
+
end
|
47
|
+
if opts.help?
|
48
|
+
@log.info(opts.to_s)
|
49
|
+
return
|
50
|
+
end
|
51
|
+
raise 'At least one wallet ID is required' if opts.arguments.empty?
|
52
|
+
opts.arguments.each do |id|
|
53
|
+
clean(Copies.new(File.join(@copies, id)), opts)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def clean(cps, _)
|
58
|
+
cps.clean
|
59
|
+
@log.debug("Expired local copies removed for #{cps}, \
|
60
|
+
#{cps.all.count} left")
|
44
61
|
end
|
45
62
|
end
|
46
63
|
end
|
data/lib/zold/commands/create.rb
CHANGED
@@ -18,9 +18,9 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
|
-
require_relative '../wallet
|
22
|
-
require_relative '../log
|
23
|
-
require_relative '../id
|
21
|
+
require_relative '../wallet'
|
22
|
+
require_relative '../log'
|
23
|
+
require_relative '../id'
|
24
24
|
|
25
25
|
# CREATE command.
|
26
26
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -36,7 +36,19 @@ module Zold
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def run(args = [])
|
39
|
-
|
39
|
+
opts = Slop.parse(args, help: true) do |o|
|
40
|
+
o.banner = "Usage: zold create [options]
|
41
|
+
Available options:"
|
42
|
+
o.bool '--help', 'Print instructions'
|
43
|
+
end
|
44
|
+
if opts.help?
|
45
|
+
@log.info(opts.to_s)
|
46
|
+
return
|
47
|
+
end
|
48
|
+
create(opts.arguments.empty? ? Id.new : Id.new(opts.arguments[0]), opts)
|
49
|
+
end
|
50
|
+
|
51
|
+
def create(id, _)
|
40
52
|
wallet = @wallets.find(id)
|
41
53
|
wallet.init(id, @pubkey)
|
42
54
|
@log.info(wallet.id)
|
data/lib/zold/commands/diff.rb
CHANGED
@@ -19,10 +19,11 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'tempfile'
|
22
|
+
require 'slop'
|
22
23
|
require 'diffy'
|
23
|
-
require_relative '../log
|
24
|
-
require_relative '../patch
|
25
|
-
require_relative '../wallet
|
24
|
+
require_relative '../log'
|
25
|
+
require_relative '../patch'
|
26
|
+
require_relative '../wallet'
|
26
27
|
|
27
28
|
# DIFF command.
|
28
29
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -31,21 +32,43 @@ require_relative '../wallet.rb'
|
|
31
32
|
module Zold
|
32
33
|
# DIFF pulling command
|
33
34
|
class Diff
|
34
|
-
def initialize(
|
35
|
-
@
|
35
|
+
def initialize(wallets:, copies:, log: Log::Quiet.new)
|
36
|
+
@wallets = wallets
|
36
37
|
@copies = copies
|
37
38
|
@log = log
|
38
39
|
end
|
39
40
|
|
40
|
-
def run(
|
41
|
-
|
42
|
-
|
41
|
+
def run(args = [])
|
42
|
+
opts = Slop.parse(args, help: true) do |o|
|
43
|
+
o.banner = "Usage: zold diff [ID...] [options]
|
44
|
+
Available options:"
|
45
|
+
o.bool '--help', 'Print instructions'
|
46
|
+
end
|
47
|
+
if opts.help?
|
48
|
+
@log.info(opts.to_s)
|
49
|
+
return
|
50
|
+
end
|
51
|
+
raise 'At least one wallet ID is required' if opts.arguments.empty?
|
52
|
+
stdout = ''
|
53
|
+
opts.arguments.each do |id|
|
54
|
+
stdout += diff(
|
55
|
+
@wallets.find(Id.new(id)),
|
56
|
+
Copies.new(File.join(@copies, id)),
|
57
|
+
opts
|
58
|
+
)
|
59
|
+
end
|
60
|
+
stdout
|
61
|
+
end
|
62
|
+
|
63
|
+
def diff(wallet, cps, _)
|
64
|
+
raise 'There are no remote copies, try FETCH first' if cps.all.empty?
|
65
|
+
cps = cps.all.sort_by { |c| c[:score] }.reverse
|
43
66
|
patch = Patch.new
|
44
67
|
patch.start(Wallet.new(cps[0][:path]))
|
45
68
|
cps[1..-1].each do |c|
|
46
69
|
patch.join(Wallet.new(c[:path]))
|
47
70
|
end
|
48
|
-
before = File.read(
|
71
|
+
before = File.read(wallet.path)
|
49
72
|
after = ''
|
50
73
|
Tempfile.open do |f|
|
51
74
|
patch.save(f, overwrite: true)
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -21,9 +21,11 @@
|
|
21
21
|
require 'uri'
|
22
22
|
require 'json'
|
23
23
|
require 'time'
|
24
|
-
|
25
|
-
require_relative '../
|
26
|
-
require_relative '../
|
24
|
+
require 'slop'
|
25
|
+
require_relative '../log'
|
26
|
+
require_relative '../http'
|
27
|
+
require_relative '../score'
|
28
|
+
require_relative '../copies'
|
27
29
|
|
28
30
|
# FETCH command.
|
29
31
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -32,17 +34,35 @@ require_relative '../score.rb'
|
|
32
34
|
module Zold
|
33
35
|
# FETCH pulling command
|
34
36
|
class Fetch
|
35
|
-
def initialize(
|
36
|
-
@id = id
|
37
|
+
def initialize(remotes:, copies:, log: Log::Quiet.new)
|
37
38
|
@remotes = remotes
|
38
39
|
@copies = copies
|
39
40
|
@log = log
|
40
41
|
end
|
41
42
|
|
42
|
-
def run(
|
43
|
+
def run(args = [])
|
44
|
+
opts = Slop.parse(args, help: true) do |o|
|
45
|
+
o.banner = "Usage: zold fetch [ID...] [options]
|
46
|
+
Available options:"
|
47
|
+
o.bool '--ignore-score-weakness',
|
48
|
+
'Don\'t complain when their score is too weak',
|
49
|
+
default: false
|
50
|
+
o.bool '--help', 'Print instructions'
|
51
|
+
end
|
52
|
+
if opts.help?
|
53
|
+
@log.info(opts.to_s)
|
54
|
+
return
|
55
|
+
end
|
56
|
+
raise 'At least one wallet ID is required' if opts.arguments.empty?
|
57
|
+
opts.arguments.each do |id|
|
58
|
+
fetch(id, Copies.new(File.join(@copies, id)), opts)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def fetch(id, cps, opts)
|
43
63
|
total = 0
|
44
64
|
@remotes.all.each do |r|
|
45
|
-
uri = URI("#{r[:home]}wallet/#{
|
65
|
+
uri = URI("#{r[:home]}wallet/#{id}")
|
46
66
|
res = Http.new(uri).get
|
47
67
|
unless res.code == '200'
|
48
68
|
@log.error("#{r[:host]}:#{r[:port]} \
|
@@ -60,15 +80,22 @@ module Zold
|
|
60
80
|
@log.error("#{r[:host]}:#{r[:port]} invalid score")
|
61
81
|
next
|
62
82
|
end
|
83
|
+
if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
|
84
|
+
@log.error(
|
85
|
+
"#{r[:host]}:#{r[:port]} score is too weak: #{score.strength} \
|
86
|
+
(<#{Score::STRENGTH})"
|
87
|
+
)
|
88
|
+
next
|
89
|
+
end
|
63
90
|
total += 1
|
64
|
-
|
91
|
+
cps.add(json['body'], r[:host], r[:port], score.value)
|
65
92
|
@log.info(
|
66
93
|
"#{r[:host]}:#{r[:port]} #{json['body'].length}b/\
|
67
94
|
#{Rainbow(score.value).green} (v.#{json['version']})"
|
68
95
|
)
|
69
96
|
end
|
70
97
|
@log.debug("#{total} copies fetched, \
|
71
|
-
there are #{
|
98
|
+
there are #{cps.all.count} available locally")
|
72
99
|
end
|
73
100
|
end
|
74
101
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Copyright (c) 2018 Yegor Bugayenko
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
# SOFTWARE.
|
20
|
+
|
21
|
+
require 'slop'
|
22
|
+
require_relative '../log'
|
23
|
+
require_relative '../prefixes'
|
24
|
+
|
25
|
+
# INVOICE command.
|
26
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
27
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
28
|
+
# License:: MIT
|
29
|
+
module Zold
|
30
|
+
# Generate invoice
|
31
|
+
class Invoice
|
32
|
+
def initialize(wallets:, log: Log::Quiet.new)
|
33
|
+
@wallets = wallets
|
34
|
+
@log = log
|
35
|
+
end
|
36
|
+
|
37
|
+
def run(args = [])
|
38
|
+
opts = Slop.parse(args, help: true) do |o|
|
39
|
+
o.banner = "Usage: zold invoice ID [options]
|
40
|
+
Where:
|
41
|
+
'ID' is the wallet ID of the money receiver
|
42
|
+
Available options:"
|
43
|
+
o.integer '--length',
|
44
|
+
'The length of the invoice prefix (default: 8)',
|
45
|
+
default: 8
|
46
|
+
o.bool '--help', 'Print instructions'
|
47
|
+
end
|
48
|
+
if opts.help?
|
49
|
+
@log.info(opts.to_s)
|
50
|
+
return
|
51
|
+
end
|
52
|
+
raise 'Receiver wallet ID is required' if opts.arguments[0].nil?
|
53
|
+
wallet = @wallets.find(Zold::Id.new(opts.arguments[0]))
|
54
|
+
raise 'Wallet doesn\'t exist, do \'fetch\' first' unless wallet.exists?
|
55
|
+
invoice(wallet, opts)
|
56
|
+
end
|
57
|
+
|
58
|
+
def invoice(wallet, opts)
|
59
|
+
invoice = "#{Prefixes.new(wallet).create(opts[:length])}@#{wallet.id}"
|
60
|
+
@log.info(invoice)
|
61
|
+
invoice
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/zold/commands/list.rb
CHANGED
data/lib/zold/commands/merge.rb
CHANGED
@@ -18,9 +18,11 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
|
-
|
22
|
-
require_relative '../
|
23
|
-
require_relative '../
|
21
|
+
require 'slop'
|
22
|
+
require_relative '../log'
|
23
|
+
require_relative '../id'
|
24
|
+
require_relative '../wallet'
|
25
|
+
require_relative '../patch'
|
24
26
|
|
25
27
|
# MERGE command.
|
26
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -29,22 +31,41 @@ require_relative '../patch.rb'
|
|
29
31
|
module Zold
|
30
32
|
# MERGE pulling command
|
31
33
|
class Merge
|
32
|
-
def initialize(
|
33
|
-
@
|
34
|
+
def initialize(wallets:, copies:, log: Log::Quiet.new)
|
35
|
+
@wallets = wallets
|
34
36
|
@copies = copies
|
35
37
|
@log = log
|
36
38
|
end
|
37
39
|
|
38
|
-
def run(
|
39
|
-
|
40
|
-
|
40
|
+
def run(args = [])
|
41
|
+
opts = Slop.parse(args, help: true) do |o|
|
42
|
+
o.banner = "Usage: zold merge [ID...] [options]
|
43
|
+
Available options:"
|
44
|
+
o.bool '--help', 'Print instructions'
|
45
|
+
end
|
46
|
+
if opts.help?
|
47
|
+
@log.info(opts.to_s)
|
48
|
+
return
|
49
|
+
end
|
50
|
+
raise 'At least one wallet ID is required' if opts.arguments.empty?
|
51
|
+
opts.arguments.each do |id|
|
52
|
+
wallet = @wallets.find(Id.new(id))
|
53
|
+
merge(wallet, Copies.new(File.join(@copies, id)), opts)
|
54
|
+
require_relative 'propagate'
|
55
|
+
Propagate.new(wallets: @wallets, log: @log).run(args)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def merge(wallet, cps, _)
|
60
|
+
raise 'There are no remote copies, try FETCH first' if cps.all.empty?
|
61
|
+
cps = cps.all.sort_by { |c| c[:score] }.reverse
|
41
62
|
patch = Patch.new
|
42
63
|
patch.start(Wallet.new(cps[0][:path]))
|
43
64
|
cps[1..-1].each do |c|
|
44
65
|
patch.join(Wallet.new(c[:path]))
|
45
66
|
end
|
46
|
-
patch.save(
|
47
|
-
@log.debug("Merged successfully into #{
|
67
|
+
patch.save(wallet.path, overwrite: true)
|
68
|
+
@log.debug("Merged successfully into #{wallet.path}")
|
48
69
|
end
|
49
70
|
end
|
50
71
|
end
|
data/lib/zold/commands/node.rb
CHANGED
@@ -47,8 +47,8 @@ module Zold
|
|
47
47
|
o.string '--home', 'Home directory (default: current directory)',
|
48
48
|
default: Dir.pwd
|
49
49
|
o.integer '--strength',
|
50
|
-
"The strength of the score (default: #{Score::
|
51
|
-
default: Score::
|
50
|
+
"The strength of the score (default: #{Score::STRENGTH})",
|
51
|
+
default: Score::STRENGTH
|
52
52
|
o.integer '--threads',
|
53
53
|
'How many threads to use for scores finding (default: 8)',
|
54
54
|
default: 8
|
@@ -96,6 +96,10 @@ module Zold
|
|
96
96
|
def debug(msg)
|
97
97
|
@log.debug(msg)
|
98
98
|
end
|
99
|
+
|
100
|
+
def debug?
|
101
|
+
@log.debug?
|
102
|
+
end
|
99
103
|
end
|
100
104
|
end
|
101
105
|
end
|