zold 0.16.24 → 0.16.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rultor.yml +1 -0
  3. data/.travis.yml +1 -0
  4. data/README.md +1 -1
  5. data/bin/zold +121 -117
  6. data/lib/zold/cached_wallets.rb +2 -2
  7. data/lib/zold/commands/create.rb +1 -1
  8. data/lib/zold/commands/diff.rb +1 -1
  9. data/lib/zold/commands/fetch.rb +3 -2
  10. data/lib/zold/commands/invoice.rb +2 -2
  11. data/lib/zold/commands/list.rb +9 -1
  12. data/lib/zold/commands/merge.rb +1 -1
  13. data/lib/zold/commands/pay.rb +2 -2
  14. data/lib/zold/commands/propagate.rb +3 -3
  15. data/lib/zold/commands/push.rb +3 -3
  16. data/lib/zold/commands/remote.rb +3 -3
  17. data/lib/zold/commands/remove.rb +1 -1
  18. data/lib/zold/commands/show.rb +1 -1
  19. data/lib/zold/commands/taxes.rb +3 -3
  20. data/lib/zold/http.rb +22 -19
  21. data/lib/zold/hungry_wallets.rb +2 -2
  22. data/lib/zold/node/entrance.rb +1 -1
  23. data/lib/zold/node/front.rb +3 -6
  24. data/lib/zold/node/nodup_entrance.rb +1 -1
  25. data/lib/zold/node/sync_entrance.rb +1 -1
  26. data/lib/zold/patch.rb +3 -5
  27. data/lib/zold/remotes.rb +7 -6
  28. data/lib/zold/sync_wallets.rb +3 -2
  29. data/lib/zold/tree_wallets.rb +2 -1
  30. data/lib/zold/version.rb +1 -1
  31. data/lib/zold/wallets.rb +2 -1
  32. data/test/commands/test_create.rb +1 -1
  33. data/test/commands/test_invoice.rb +1 -1
  34. data/test/commands/test_list.rb +1 -1
  35. data/test/commands/test_pull.rb +1 -1
  36. data/test/commands/test_show.rb +1 -1
  37. data/test/fake_home.rb +1 -1
  38. data/test/node/fake_node.rb +2 -2
  39. data/test/node/test_front.rb +30 -30
  40. data/test/test__helper.rb +1 -0
  41. data/test/test_cached_wallets.rb +2 -2
  42. data/test/test_http.rb +9 -9
  43. data/test/test_sync_wallets.rb +2 -2
  44. data/test/test_tree_wallets.rb +2 -2
  45. data/test/test_wallets.rb +2 -2
  46. data/test/upgrades/test_protocol_up.rb +1 -1
  47. data/zold.gemspec +7 -0
  48. metadata +36 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be5fb06b537fc4c9e80b30fadf5f6cd1e1a344e7604dfecdc1ac78ed46176063
4
- data.tar.gz: 9fbb3d142ca8047324eac09dc35beac86ba0cca2c72649034de550c220553cc5
3
+ metadata.gz: eb543c3e1e0acee9fb72b9ad04a51453dfa417e0c030f4fe18291518d36ce0c2
4
+ data.tar.gz: 440c25b8260e36048f63b9ce59e19101375dace2514667efbc4e5df550b2a71a
5
5
  SHA512:
6
- metadata.gz: 2c90d865cabb1b36ae83ed263f2779d725ff98a15fd93606a94ca088522853aea674f2b8a1142e865849b4f2fee2522275adcb8bc918a0a021ca992a6be78409
7
- data.tar.gz: 9fa78df566ec34dd99ebfb8ae24160295232245a2e75ee55be033d5c53a77f897cb52ce1e28609d15b5187de2861b0766699734c471b4c73c93e12216cf035ae
6
+ metadata.gz: b459087e04fe5ebe18cd68024ee247c041e0c876b098f6dc25b4262ee501a61431aac6f76123d56fb5cf85c86afcedd7b1949480bbb5160fd87763766afe4032
7
+ data.tar.gz: 135ae329734d90f68df3716a29e61a1c0a5dce7ec7506d7f40630242ec68f948d241c7b362134962687d6d4331f679eebb031d20bdc7c73eafbd710b45c44fe1
data/.rultor.yml CHANGED
@@ -6,6 +6,7 @@ install: |
6
6
  export GEM_HOME=~/.ruby
7
7
  export GEM_PATH=$GEM_HOME:$GEM_PATH
8
8
  sudo apt-get -y update
9
+ sudo apt-get -y install libcurl4-openssl-dev
9
10
  sudo gem install pdd
10
11
  release:
11
12
  script: |-
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 2.3.1
4
4
  - 2.3.3
5
+ - 2.5.1
5
6
  cache: bundler
6
7
  branches:
7
8
  only:
data/README.md CHANGED
@@ -339,7 +339,7 @@ Then:
339
339
 
340
340
  ```bash
341
341
  $ bundle update
342
- $ rake
342
+ $ bundle exec rake
343
343
  ```
344
344
 
345
345
  The build has to be clean. If it's not, [submit an issue](https://github.com/zold-io/zold/issues).
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
- begin
67
- opts = Slop.parse(args, strict: false, suppress_errors: true) do |o|
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
- #{Rainbow('remote').green} command [options]
71
- Manage remote nodes
72
- #{Rainbow('create').green} [options]
73
- Creates a new wallet with a random ID
74
- #{Rainbow('fetch').green} [ID...] [options]
75
- Fetch wallet copies from remote nodes
76
- #{Rainbow('clean').green} [ID...] [options]
77
- Remove expired local copies
78
- #{Rainbow('merge').green} [ID...] [options]
79
- Merge remote copies with the HEAD
80
- #{Rainbow('propagate').green} [ID...] [options]
81
- Propagate transactions to receiving wallets
82
- #{Rainbow('pull').green} [ID...] [options]
83
- Fetch and then merge
84
- #{Rainbow('remove').green} [ID...] [options]
85
- Remove the wallet(s) from the local storage
86
- #{Rainbow('show').green} [ID...] [options]
87
- Show all available information about the wallet
88
- #{Rainbow('pay').green} from to amount details [options]
89
- Pay ZOLD from one wallet to another
90
- #{Rainbow('invoice').green} ID [options]
91
- Generate invoice unique ID for a payment
92
- #{Rainbow('push').green} [ID...] [options]
93
- Push all/some local wallets or the ones required
94
- #{Rainbow('taxes').green} command [ID...] [options]
95
- Pay taxes, check their status
96
- #{Rainbow('node').green} [options]
97
- Run node at the given TCP port
98
- #{Rainbow('alias').green} [alias] [wallet ID]
99
- Set an alias for a wallet
100
- #{Rainbow('next').green} score
101
- Generate next score from the provided one
102
- #{Rainbow('score').green} [options]
103
- Generate score for the given host and port
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
- o.string '--home',
106
- "Home directory (default: #{Dir.pwd})",
107
- default: Dir.pwd
108
- o.string '--network',
109
- "The name of the network we work in (default: #{Zold::Wallet::MAIN_NETWORK})",
110
- required: true,
111
- default: Zold::Wallet::MAIN_NETWORK
112
- o.bool '-h', '--help', 'Show these instructions'
113
- o.bool '--trace', 'Show full stack trace in case of a problem'
114
- o.bool '--memory-dump', 'Dump memory snapshot afterwards, to the console', default: false
115
- o.bool '--skip-upgrades', 'Don\'t upgrade the storage', default: false
116
- o.bool '--ignore-global-config', 'Don\'t read options from the ~/.zold file'
117
- o.on '--no-colors', 'Disable colors in the ouput' do
118
- Rainbow.enabled = false
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
- log = Zold::Log::Sync.new(log)
128
+ log = Zold::Log::Sync.new(log)
130
129
 
131
- log.debug("Gem location: #{File.dirname(File.dirname(__FILE__))}")
130
+ log.debug("Gem location: #{File.dirname(File.dirname(__FILE__))}")
132
131
 
133
- commands = opts.arguments.reject { |a| a.start_with?('-') }
134
- command = commands[0]
132
+ commands = opts.arguments.reject { |a| a.start_with?('-') }
133
+ command = commands[0]
135
134
 
136
- if command.nil?
137
- raise 'A command required, try --help' unless opts.help?
138
- log.info(opts.to_s)
139
- exit
140
- end
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
- args = opts.arguments
143
- args << '--help' if opts.help?
144
- args << "--network=#{opts['network']}"
141
+ args = opts.arguments
142
+ args << '--help' if opts.help?
143
+ args << "--network=#{opts['network']}"
145
144
 
146
- home = File.expand_path(opts[:home])
147
- FileUtils.mkdir_p(home)
148
- Dir.chdir(home)
149
- log.debug("Home directory: #{home}")
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
- zoldata = File.join(home, '.zoldata')
150
+ zoldata = File.join(home, '.zoldata')
152
151
 
153
- unless opts['skip-upgrades']
154
- Zold::Upgrades.new(Zold::VersionFile.new(File.join(zoldata, 'version')), 'upgrades').run
155
- # @todo #384:30min This is a workaround, move this code into Upgrades, somehow.
156
- # We should find a way to run these arbitrary scripts and pass arguments
157
- # to them. Each of them may need its own set of arguments.
158
- require_relative '../upgrades/2'
159
- Zold::UpgradeTo2.new(Dir.pwd, log).exec
160
- require_relative '../upgrades/protocol_up'
161
- Zold::ProtocolUp.new(Dir.pwd, log).exec
162
- require_relative '../upgrades/rename_foreign_wallets'
163
- Zold::RenameForeignWallets.new(Dir.pwd, opts['network'], log).exec
164
- if command == 'node'
165
- require_relative '../upgrades/move_wallets_into_tree'
166
- Zold::MoveWalletsIntoTree.new(Dir.pwd, log).exec
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
- wallets = Zold::SyncWallets.new(
171
- Zold::CachedWallets.new(
172
- command == 'node' ? Zold::TreeWallets.new(home) : Zold::Wallets.new(home)
173
- ),
174
- log: log
175
- )
176
- fremotes = File.join(zoldata, 'remotes')
177
- remotes = Zold::Remotes.new(file: fremotes, network: opts['network'])
178
- if File.exist?(fremotes)
179
- log.debug("Remote nodes: #{remotes.all.count} total")
180
- else
181
- remotes.defaults
182
- log.debug("Default remotes have been set: #{remotes.all.count} total")
183
- end
184
- copies = File.join(zoldata, 'copies')
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
- log.debug("Network: #{opts['network']} (#{opts['network'] == Zold::Wallet::MAIN_NETWORK ? 'main' : 'test'} net)")
185
+ log.debug("Network: #{opts['network']} (#{opts['network'] == Zold::Wallet::MAIN_NETWORK ? 'main' : 'test'} net)")
187
186
 
188
- cmd = lambda do
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
- if opts['memory-dump']
253
- MemoryProfiler.report(top: 20) { cmd.call }.pretty_print
254
- else
255
- cmd.call
256
- end
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)}")
@@ -53,8 +53,8 @@ module Zold
53
53
  @wallets.all
54
54
  end
55
55
 
56
- def find(id)
57
- @wallets.find(id) do |wallet|
56
+ def acq(id, exclusive: false)
57
+ @wallets.acq(id, exclusive: exclusive) do |wallet|
58
58
  yield @zache.get(id.to_s, lifetime: 5 * 60) { wallet }
59
59
  end
60
60
  end
@@ -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.find(id) do |wallet|
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
@@ -66,7 +66,7 @@ Available options:"
66
66
  cps.each do |c|
67
67
  patch.join(Wallet.new(c[:path]))
68
68
  end
69
- before = @wallets.find(id) do |wallet|
69
+ before = @wallets.acq(id) do |wallet|
70
70
  IO.read(wallet.path)
71
71
  end
72
72
  after = ''
@@ -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.code == '404'
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)}: #{Rainbow(score.value).green} (#{json['version']})")
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.find(id, &:exists?)
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.find(id) do |wallet|
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)
@@ -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
- @wallets.find(id) do |wallet|
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
@@ -76,7 +76,7 @@ Available options:"
76
76
  merge_one(opts, patch, wallet, name)
77
77
  score += c[:score]
78
78
  end
79
- @wallets.find(id) do |wallet|
79
+ @wallets.acq(id, exclusive: true) do |wallet|
80
80
  start = Time.now
81
81
  if wallet.exists?
82
82
  merge_one(opts, patch, wallet, 'localhost')
@@ -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.find(id) do |from|
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.find(id) do |wallet|
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.find(id, &:network)
67
- @wallets.find(id, &:txns).select { |t| t.amount.negative? }.each do |t|
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.find(t.bnf) do |target|
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