zold 0.16.24 → 0.16.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rultor.yml +1 -0
- data/.travis.yml +1 -0
- data/README.md +1 -1
- data/bin/zold +121 -117
- data/lib/zold/cached_wallets.rb +2 -2
- data/lib/zold/commands/create.rb +1 -1
- data/lib/zold/commands/diff.rb +1 -1
- data/lib/zold/commands/fetch.rb +3 -2
- data/lib/zold/commands/invoice.rb +2 -2
- data/lib/zold/commands/list.rb +9 -1
- data/lib/zold/commands/merge.rb +1 -1
- data/lib/zold/commands/pay.rb +2 -2
- data/lib/zold/commands/propagate.rb +3 -3
- data/lib/zold/commands/push.rb +3 -3
- data/lib/zold/commands/remote.rb +3 -3
- data/lib/zold/commands/remove.rb +1 -1
- data/lib/zold/commands/show.rb +1 -1
- data/lib/zold/commands/taxes.rb +3 -3
- data/lib/zold/http.rb +22 -19
- data/lib/zold/hungry_wallets.rb +2 -2
- data/lib/zold/node/entrance.rb +1 -1
- data/lib/zold/node/front.rb +3 -6
- data/lib/zold/node/nodup_entrance.rb +1 -1
- data/lib/zold/node/sync_entrance.rb +1 -1
- data/lib/zold/patch.rb +3 -5
- data/lib/zold/remotes.rb +7 -6
- data/lib/zold/sync_wallets.rb +3 -2
- data/lib/zold/tree_wallets.rb +2 -1
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallets.rb +2 -1
- data/test/commands/test_create.rb +1 -1
- data/test/commands/test_invoice.rb +1 -1
- data/test/commands/test_list.rb +1 -1
- data/test/commands/test_pull.rb +1 -1
- data/test/commands/test_show.rb +1 -1
- data/test/fake_home.rb +1 -1
- data/test/node/fake_node.rb +2 -2
- data/test/node/test_front.rb +30 -30
- data/test/test__helper.rb +1 -0
- data/test/test_cached_wallets.rb +2 -2
- data/test/test_http.rb +9 -9
- data/test/test_sync_wallets.rb +2 -2
- data/test/test_tree_wallets.rb +2 -2
- data/test/test_wallets.rb +2 -2
- data/test/upgrades/test_protocol_up.rb +1 -1
- data/zold.gemspec +7 -0
- metadata +36 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb543c3e1e0acee9fb72b9ad04a51453dfa417e0c030f4fe18291518d36ce0c2
|
4
|
+
data.tar.gz: 440c25b8260e36048f63b9ce59e19101375dace2514667efbc4e5df550b2a71a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b459087e04fe5ebe18cd68024ee247c041e0c876b098f6dc25b4262ee501a61431aac6f76123d56fb5cf85c86afcedd7b1949480bbb5160fd87763766afe4032
|
7
|
+
data.tar.gz: 135ae329734d90f68df3716a29e61a1c0a5dce7ec7506d7f40630242ec68f948d241c7b362134962687d6d4331f679eebb031d20bdc7c73eafbd710b45c44fe1
|
data/.rultor.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/bin/zold
CHANGED
@@ -63,129 +63,129 @@ unless ENV['RACK_ENV'] == 'test' || ARGV.find { |a| a == '--ignore-global-config
|
|
63
63
|
end
|
64
64
|
args += ARGV
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
o.banner = "Usage: zold [options] command [arguments]
|
66
|
+
opts = Slop.parse(args, strict: false, suppress_errors: true) do |o|
|
67
|
+
o.banner = "Usage: zold [options] command [arguments]
|
69
68
|
Available commands:
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
69
|
+
#{Rainbow('remote').green} command [options]
|
70
|
+
Manage remote nodes
|
71
|
+
#{Rainbow('create').green} [options]
|
72
|
+
Creates a new wallet with a random ID
|
73
|
+
#{Rainbow('fetch').green} [ID...] [options]
|
74
|
+
Fetch wallet copies from remote nodes
|
75
|
+
#{Rainbow('clean').green} [ID...] [options]
|
76
|
+
Remove expired local copies
|
77
|
+
#{Rainbow('merge').green} [ID...] [options]
|
78
|
+
Merge remote copies with the HEAD
|
79
|
+
#{Rainbow('propagate').green} [ID...] [options]
|
80
|
+
Propagate transactions to receiving wallets
|
81
|
+
#{Rainbow('pull').green} [ID...] [options]
|
82
|
+
Fetch and then merge
|
83
|
+
#{Rainbow('remove').green} [ID...] [options]
|
84
|
+
Remove the wallet(s) from the local storage
|
85
|
+
#{Rainbow('show').green} [ID...] [options]
|
86
|
+
Show all available information about the wallet
|
87
|
+
#{Rainbow('pay').green} from to amount details [options]
|
88
|
+
Pay ZOLD from one wallet to another
|
89
|
+
#{Rainbow('invoice').green} ID [options]
|
90
|
+
Generate invoice unique ID for a payment
|
91
|
+
#{Rainbow('push').green} [ID...] [options]
|
92
|
+
Push all/some local wallets or the ones required
|
93
|
+
#{Rainbow('taxes').green} command [ID...] [options]
|
94
|
+
Pay taxes, check their status
|
95
|
+
#{Rainbow('node').green} [options]
|
96
|
+
Run node at the given TCP port
|
97
|
+
#{Rainbow('alias').green} [alias] [wallet ID]
|
98
|
+
Set an alias for a wallet
|
99
|
+
#{Rainbow('next').green} score
|
100
|
+
Generate next score from the provided one
|
101
|
+
#{Rainbow('score').green} [options]
|
102
|
+
Generate score for the given host and port
|
104
103
|
Available options:"
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
|
-
o.on '--verbose', 'Enable extra logging information' do
|
121
|
-
log = Zold::Log::Verbose.new
|
122
|
-
end
|
123
|
-
o.on '-v', '--version', 'Show current version' do
|
124
|
-
log.info(Zold::VERSION)
|
125
|
-
exit
|
126
|
-
end
|
104
|
+
o.string '--home',
|
105
|
+
"Home directory (default: #{Dir.pwd})",
|
106
|
+
default: Dir.pwd
|
107
|
+
o.string '--network',
|
108
|
+
"The name of the network we work in (default: #{Zold::Wallet::MAIN_NETWORK})",
|
109
|
+
required: true,
|
110
|
+
default: Zold::Wallet::MAIN_NETWORK
|
111
|
+
o.bool '-h', '--help', 'Show these instructions'
|
112
|
+
o.bool '--trace', 'Show full stack trace in case of a problem'
|
113
|
+
o.bool '--memory-dump', 'Dump memory snapshot afterwards, to the console', default: false
|
114
|
+
o.bool '--skip-upgrades', 'Don\'t upgrade the storage', default: false
|
115
|
+
o.bool '--ignore-global-config', 'Don\'t read options from the ~/.zold file'
|
116
|
+
o.on '--no-colors', 'Disable colors in the ouput' do
|
117
|
+
Rainbow.enabled = false
|
127
118
|
end
|
119
|
+
o.on '--verbose', 'Enable extra logging information' do
|
120
|
+
log = Zold::Log::Verbose.new
|
121
|
+
end
|
122
|
+
o.on '-v', '--version', 'Show current version' do
|
123
|
+
log.info(Zold::VERSION)
|
124
|
+
exit
|
125
|
+
end
|
126
|
+
end
|
128
127
|
|
129
|
-
|
128
|
+
log = Zold::Log::Sync.new(log)
|
130
129
|
|
131
|
-
|
130
|
+
log.debug("Gem location: #{File.dirname(File.dirname(__FILE__))}")
|
132
131
|
|
133
|
-
|
134
|
-
|
132
|
+
commands = opts.arguments.reject { |a| a.start_with?('-') }
|
133
|
+
command = commands[0]
|
135
134
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
135
|
+
if command.nil?
|
136
|
+
raise 'A command required, try --help' unless opts.help?
|
137
|
+
log.info(opts.to_s)
|
138
|
+
exit
|
139
|
+
end
|
141
140
|
|
142
|
-
|
143
|
-
|
144
|
-
|
141
|
+
args = opts.arguments
|
142
|
+
args << '--help' if opts.help?
|
143
|
+
args << "--network=#{opts['network']}"
|
145
144
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
145
|
+
home = File.expand_path(opts[:home])
|
146
|
+
FileUtils.mkdir_p(home)
|
147
|
+
Dir.chdir(home)
|
148
|
+
log.debug("Home directory: #{home}")
|
150
149
|
|
151
|
-
|
150
|
+
zoldata = File.join(home, '.zoldata')
|
152
151
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
end
|
152
|
+
unless opts['skip-upgrades']
|
153
|
+
Zold::Upgrades.new(Zold::VersionFile.new(File.join(zoldata, 'version')), 'upgrades').run
|
154
|
+
# @todo #384:30min This is a workaround, move this code into Upgrades, somehow.
|
155
|
+
# We should find a way to run these arbitrary scripts and pass arguments
|
156
|
+
# to them. Each of them may need its own set of arguments.
|
157
|
+
require_relative '../upgrades/2'
|
158
|
+
Zold::UpgradeTo2.new(Dir.pwd, log).exec
|
159
|
+
require_relative '../upgrades/protocol_up'
|
160
|
+
Zold::ProtocolUp.new(Dir.pwd, log).exec
|
161
|
+
require_relative '../upgrades/rename_foreign_wallets'
|
162
|
+
Zold::RenameForeignWallets.new(Dir.pwd, opts['network'], log).exec
|
163
|
+
if command == 'node'
|
164
|
+
require_relative '../upgrades/move_wallets_into_tree'
|
165
|
+
Zold::MoveWalletsIntoTree.new(Dir.pwd, log).exec
|
168
166
|
end
|
167
|
+
end
|
169
168
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
169
|
+
wallets = Zold::SyncWallets.new(
|
170
|
+
Zold::CachedWallets.new(
|
171
|
+
command == 'node' ? Zold::TreeWallets.new(home) : Zold::Wallets.new(home)
|
172
|
+
),
|
173
|
+
log: log
|
174
|
+
)
|
175
|
+
fremotes = File.join(zoldata, 'remotes')
|
176
|
+
remotes = Zold::Remotes.new(file: fremotes, network: opts['network'])
|
177
|
+
if File.exist?(fremotes)
|
178
|
+
log.debug("Remote nodes: #{remotes.all.count} total")
|
179
|
+
else
|
180
|
+
remotes.defaults
|
181
|
+
log.debug("Default remotes have been set: #{remotes.all.count} total")
|
182
|
+
end
|
183
|
+
copies = File.join(zoldata, 'copies')
|
185
184
|
|
186
|
-
|
185
|
+
log.debug("Network: #{opts['network']} (#{opts['network'] == Zold::Wallet::MAIN_NETWORK ? 'main' : 'test'} net)")
|
187
186
|
|
188
|
-
|
187
|
+
cmd = lambda do
|
188
|
+
begin
|
189
189
|
case command
|
190
190
|
when 'node'
|
191
191
|
require_relative '../lib/zold/commands/node'
|
@@ -247,17 +247,21 @@ Available options:"
|
|
247
247
|
else
|
248
248
|
raise "Command '#{command}' is not supported"
|
249
249
|
end
|
250
|
+
return 0
|
251
|
+
rescue StandardError => ex
|
252
|
+
log.error("#{ex.message} (#{ex.class.name})")
|
253
|
+
log.error(Backtrace.new(ex)) if opts['trace']
|
254
|
+
return -1
|
250
255
|
end
|
256
|
+
end
|
251
257
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
rescue StandardError => ex
|
258
|
-
log.error("#{ex.message} (#{ex.class.name})")
|
259
|
-
puts(Backtrace.new(ex)) if opts['trace']
|
260
|
-
exit -1
|
258
|
+
code = 0
|
259
|
+
if opts['memory-dump']
|
260
|
+
MemoryProfiler.report(top: 20) { code = cmd.call }.pretty_print
|
261
|
+
else
|
262
|
+
code = cmd.call
|
261
263
|
end
|
262
264
|
|
265
|
+
exit(code) unless code.zero?
|
266
|
+
|
263
267
|
log.debug("Successfully finished in #{Zold::Age.new(start)}")
|
data/lib/zold/cached_wallets.rb
CHANGED
data/lib/zold/commands/create.rb
CHANGED
@@ -61,7 +61,7 @@ Available options:"
|
|
61
61
|
|
62
62
|
def create(id, opts)
|
63
63
|
key = Zold::Key.new(file: opts['public-key'])
|
64
|
-
@wallets.
|
64
|
+
@wallets.acq(id, exclusive: true) do |wallet|
|
65
65
|
wallet.init(id, key, network: opts['network'])
|
66
66
|
@log.debug("Wallet #{Rainbow(wallet).green} created at #{@wallets.path}")
|
67
67
|
end
|
data/lib/zold/commands/diff.rb
CHANGED
data/lib/zold/commands/fetch.rb
CHANGED
@@ -107,7 +107,7 @@ Available options:"
|
|
107
107
|
size = r.http(uri + '/size').get
|
108
108
|
r.assert_code(200, size)
|
109
109
|
res = r.http(uri).get(timeout: 2 + size.body.to_i * 0.01 / 1024)
|
110
|
-
raise "Wallet #{id} not found" if res.
|
110
|
+
raise "Wallet #{id} not found" if res.status == '404'
|
111
111
|
r.assert_code(200, res)
|
112
112
|
json = JsonPage.new(res.body, uri).to_hash
|
113
113
|
score = Score.parse_json(json['score'])
|
@@ -130,7 +130,8 @@ Available options:"
|
|
130
130
|
end
|
131
131
|
copy = cps.add(IO.read(f), score.host, score.port, score.value)
|
132
132
|
@log.info("#{r} returned #{wallet.mnemo} #{Age.new(json['mtime'])}/#{json['copies']}c \
|
133
|
-
as copy ##{copy} in #{Age.new(start, limit: 4)}:
|
133
|
+
as copy ##{copy}/#{cps.all.count} in #{Age.new(start, limit: 4)}: \
|
134
|
+
#{Rainbow(score.value).green} (#{json['version']})")
|
134
135
|
end
|
135
136
|
score.value
|
136
137
|
end
|
@@ -61,13 +61,13 @@ Available options:"
|
|
61
61
|
private
|
62
62
|
|
63
63
|
def invoice(id, opts)
|
64
|
-
unless @wallets.
|
64
|
+
unless @wallets.acq(id, &:exists?)
|
65
65
|
require_relative 'pull'
|
66
66
|
Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
|
67
67
|
['pull', id.to_s, "--network=#{opts['network']}"]
|
68
68
|
)
|
69
69
|
end
|
70
|
-
inv = @wallets.
|
70
|
+
inv = @wallets.acq(id) do |wallet|
|
71
71
|
"#{Prefixes.new(wallet).create(opts[:length])}@#{wallet.id}"
|
72
72
|
end
|
73
73
|
@log.info(inv)
|
data/lib/zold/commands/list.rb
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require_relative '../log'
|
24
|
+
require_relative '../amount'
|
24
25
|
require_relative '../wallet'
|
25
26
|
|
26
27
|
# LIST command.
|
@@ -36,13 +37,20 @@ module Zold
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def run(_ = [])
|
40
|
+
total = 0
|
41
|
+
txns = 0
|
42
|
+
balance = Amount::ZERO
|
39
43
|
@wallets.all.sort.each do |id|
|
40
|
-
|
44
|
+
total += 1
|
45
|
+
@wallets.acq(id) do |wallet|
|
41
46
|
msg = wallet.mnemo
|
42
47
|
msg += " (net:#{wallet.network})" if wallet.network != Wallet::MAIN_NETWORK
|
48
|
+
txns += wallet.txns.count
|
49
|
+
balance += wallet.balance
|
43
50
|
@log.info(msg)
|
44
51
|
end
|
45
52
|
end
|
53
|
+
@log.info("#{total} wallets, #{txns} transactions, #{balance} in total")
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
data/lib/zold/commands/merge.rb
CHANGED
data/lib/zold/commands/pay.rb
CHANGED
@@ -79,7 +79,7 @@ Available options:"
|
|
79
79
|
amount = Amount.new(zld: mine[2].to_f)
|
80
80
|
details = mine[3] || '-'
|
81
81
|
taxes(id, opts)
|
82
|
-
@wallets.
|
82
|
+
@wallets.acq(id, exclusive: true) do |from|
|
83
83
|
pay(from, invoice, amount, details, opts)
|
84
84
|
end
|
85
85
|
return if opts['skip-propagate']
|
@@ -90,7 +90,7 @@ Available options:"
|
|
90
90
|
private
|
91
91
|
|
92
92
|
def taxes(id, opts)
|
93
|
-
debt = @wallets.
|
93
|
+
debt = @wallets.acq(id) do |wallet|
|
94
94
|
raise "Wallet #{id} doesn't exist, do 'zold pull' first" unless wallet.exists?
|
95
95
|
Tax.new(wallet).in_debt? && !opts['dont-pay-taxes']
|
96
96
|
end
|
@@ -63,14 +63,14 @@ Available options:"
|
|
63
63
|
start = Time.now
|
64
64
|
modified = []
|
65
65
|
total = 0
|
66
|
-
network = @wallets.
|
67
|
-
@wallets.
|
66
|
+
network = @wallets.acq(id, &:network)
|
67
|
+
@wallets.acq(id, &:txns).select { |t| t.amount.negative? }.each do |t|
|
68
68
|
total += 1
|
69
69
|
if t.bnf == id
|
70
70
|
@log.error("Paying itself in #{id}? #{t}")
|
71
71
|
next
|
72
72
|
end
|
73
|
-
@wallets.
|
73
|
+
@wallets.acq(t.bnf, exclusive: true) do |target|
|
74
74
|
unless target.exists?
|
75
75
|
@log.debug("#{t.amount * -1} to #{t.bnf}: wallet is absent")
|
76
76
|
next
|