zold 0.16.27 → 0.16.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/bin/zold +19 -8
  4. data/fixtures/scripts/distribute-wallet.sh +1 -1
  5. data/fixtures/scripts/pull-on-start.sh +1 -1
  6. data/fixtures/scripts/push-and-pull.sh +1 -1
  7. data/fixtures/scripts/spread-wallets.sh +1 -1
  8. data/lib/zold/commands/alias.rb +4 -1
  9. data/lib/zold/commands/calculate.rb +4 -1
  10. data/lib/zold/commands/clean.rb +1 -1
  11. data/lib/zold/commands/create.rb +6 -3
  12. data/lib/zold/commands/diff.rb +4 -1
  13. data/lib/zold/commands/fetch.rb +4 -1
  14. data/lib/zold/commands/invoice.rb +4 -1
  15. data/lib/zold/commands/list.rb +12 -4
  16. data/lib/zold/commands/merge.rb +8 -1
  17. data/lib/zold/commands/next.rb +4 -1
  18. data/lib/zold/commands/node.rb +6 -3
  19. data/lib/zold/commands/pay.rb +4 -1
  20. data/lib/zold/commands/propagate.rb +4 -1
  21. data/lib/zold/commands/pull.rb +4 -1
  22. data/lib/zold/commands/push.rb +4 -1
  23. data/lib/zold/commands/remote.rb +6 -3
  24. data/lib/zold/commands/remove.rb +4 -1
  25. data/lib/zold/commands/routines/reconnect.rb +1 -1
  26. data/lib/zold/commands/routines/spread.rb +1 -1
  27. data/lib/zold/commands/show.rb +7 -3
  28. data/lib/zold/commands/taxes.rb +4 -1
  29. data/lib/zold/commands/thread_badge.rb +47 -0
  30. data/lib/zold/copies.rb +1 -1
  31. data/lib/zold/endless.rb +1 -1
  32. data/lib/zold/http.rb +3 -3
  33. data/lib/zold/key.rb +3 -0
  34. data/lib/zold/log.rb +52 -111
  35. data/lib/zold/metronome.rb +12 -10
  36. data/lib/zold/node/async_entrance.rb +2 -2
  37. data/lib/zold/node/entrance.rb +1 -1
  38. data/lib/zold/node/farm.rb +1 -1
  39. data/lib/zold/node/farmers.rb +1 -1
  40. data/lib/zold/node/front.rb +5 -5
  41. data/lib/zold/node/nodup_entrance.rb +1 -1
  42. data/lib/zold/node/spread_entrance.rb +1 -1
  43. data/lib/zold/node/sync_entrance.rb +1 -1
  44. data/lib/zold/patch.rb +2 -2
  45. data/lib/zold/remotes.rb +1 -1
  46. data/lib/zold/signature.rb +5 -1
  47. data/lib/zold/sync_wallets.rb +1 -1
  48. data/lib/zold/upgrades.rb +1 -1
  49. data/lib/zold/verbose_thread.rb +1 -1
  50. data/lib/zold/version.rb +1 -1
  51. data/lib/zold/version_file.rb +1 -1
  52. data/lib/zold/wallet.rb +2 -2
  53. data/resources/root.pub +14 -0
  54. data/test/commands/test_list.rb +2 -1
  55. data/test/commands/test_remote.rb +35 -4
  56. data/test/commands/test_show.rb +1 -1
  57. data/test/fake_home.rb +1 -1
  58. data/test/node/fake_node.rb +3 -2
  59. data/test/node/test_farm.rb +1 -1
  60. data/test/test__helper.rb +4 -3
  61. data/test/test_dir_items.rb +1 -1
  62. data/test/test_http.rb +44 -6
  63. data/test/test_key.rb +7 -0
  64. data/test/test_log.rb +12 -1
  65. data/test/test_remotes.rb +1 -1
  66. data/test/test_signature.rb +1 -0
  67. data/test/test_verbose_thread.rb +3 -3
  68. data/test/test_zold.rb +4 -3
  69. data/zold.gemspec +3 -2
  70. metadata +8 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6099001404773f73201ba9d4120098b1e096a14132874aaee47ffea89d0bb4d4
4
- data.tar.gz: 004e0c2475ba063f08f8a685e6f9b592769a593fb4b17d765e9316f487481506
3
+ metadata.gz: 0a58595f5d647efa9b0ff2f58a2d975d299f9dda59ddd938f8f5c2ff4f917f37
4
+ data.tar.gz: 86d0ddf04dcbe3301ce6906900f0d02687c3b893702e374dcab7008e99f7fa45
5
5
  SHA512:
6
- metadata.gz: cc98c08e0f2c2c6c3e5f0a94b434d05a5a0301c213fb2ad45401e1f4b733fe3e7f0806ac060e2f414a937a935effaaad5f39c8a7d07c26b2fc2251c42d16d536
7
- data.tar.gz: 486ba67e95ad7c4d2f92a9e1dd8d8fe854f701a39737b3664de943482370bba1859052fcd09372e2905e484b3f5a857e55abde9e8d89b8bea0114fda28bf6e57
6
+ metadata.gz: '09ca8a13aca6b85dd4d1efb6dcfdeeea39b5c9bdf685e0c0d87a2b29c6de081c59e24d59d838ec2d57a20fcb1259fc1fde104aba107c3c33927a0de25638e098'
7
+ data.tar.gz: 18bfc9cf728d6d22d9e50287d1031e7340cb8b623ef3249523161e84fa711dba364bed0cbec34950108b4c4c5753719b59f1997813e0548a37c0d576c6d1cf70
data/README.md CHANGED
@@ -311,7 +311,7 @@ For example, `Zold::Log::Verbose` will print a lot of information to the console
311
311
 
312
312
  ```ruby
313
313
  require 'zold/commands/push'
314
- Zold::Push.new(wallets: wallets, remotes: remotes, log: Zold::Log::Verbose.new).run(['push'])
314
+ Zold::Push.new(wallets: wallets, remotes: remotes, log: Zold::Log::VERBOSE).run(['push'])
315
315
  ```
316
316
 
317
317
  Also, all commands by default assume that you are working in a `test` network.
data/bin/zold CHANGED
@@ -50,7 +50,7 @@ Thread.current.name = 'main'
50
50
  Encoding.default_external = Encoding::UTF_8
51
51
  Encoding.default_internal = Encoding::UTF_8
52
52
 
53
- log = Zold::Log::Regular.new
53
+ log = Zold::Log::REGULAR.dup
54
54
 
55
55
  args = []
56
56
  unless ENV['RACK_ENV'] == 'test' || ARGV.find { |a| a == '--ignore-global-config' }
@@ -105,9 +105,13 @@ Available options:"
105
105
  "Home directory (default: #{Dir.pwd})",
106
106
  default: Dir.pwd
107
107
  o.string '--network',
108
- "The name of the network we work in (default: #{Zold::Wallet::MAIN_NETWORK})",
108
+ "The name of the network we work in (default: #{Zold::Wallet::MAINET})",
109
109
  required: true,
110
- default: Zold::Wallet::MAIN_NETWORK
110
+ default: Zold::Wallet::MAINET
111
+ o.string '--pretty',
112
+ 'Logging format, e.g. short, full, compact (default: short)',
113
+ required: true,
114
+ default: 'short'
111
115
  o.bool '-h', '--help', 'Show these instructions'
112
116
  o.bool '--trace', 'Show full stack trace in case of a problem'
113
117
  o.bool '--memory-dump', 'Dump memory snapshot afterwards, to the console', default: false
@@ -117,7 +121,7 @@ Available options:"
117
121
  Rainbow.enabled = false
118
122
  end
119
123
  o.on '--verbose', 'Enable extra logging information' do
120
- log = Zold::Log::Verbose.new
124
+ log = Zold::Log::VERBOSE.dup
121
125
  end
122
126
  o.on '-v', '--version', 'Show current version' do
123
127
  log.info(Zold::VERSION)
@@ -125,7 +129,14 @@ Available options:"
125
129
  end
126
130
  end
127
131
 
128
- log = Zold::Log::Sync.new(log)
132
+ case opts['pretty'].downcase.strip
133
+ when 'short'
134
+ log.formatter = Zold::Log::SHORT
135
+ when 'compact'
136
+ log.formatter = Zold::Log::COMPACT
137
+ when 'full'
138
+ log.formatter = Zold::Log::FULL
139
+ end
129
140
 
130
141
  log.debug("Gem location: #{File.dirname(File.dirname(__FILE__))}")
131
142
 
@@ -182,7 +193,7 @@ else
182
193
  end
183
194
  copies = File.join(zoldata, 'copies')
184
195
 
185
- log.debug("Network: #{opts['network']} (#{opts['network'] == Zold::Wallet::MAIN_NETWORK ? 'main' : 'test'} net)")
196
+ log.debug("Network: #{opts['network']} (#{opts['network'] == Zold::Wallet::MAINET ? 'main' : 'test'} net)")
186
197
 
187
198
  cmd = lambda do
188
199
  begin
@@ -204,10 +215,10 @@ cmd = lambda do
204
215
  Zold::Pay.new(wallets: wallets, remotes: remotes, log: log).run(args)
205
216
  when 'show'
206
217
  require_relative '../lib/zold/commands/show'
207
- Zold::Show.new(wallets: wallets, log: log).run(args)
218
+ Zold::Show.new(wallets: wallets, copies: copies, log: log).run(args)
208
219
  when 'list'
209
220
  require_relative '../lib/zold/commands/list'
210
- Zold::List.new(wallets: wallets, log: log).run(args)
221
+ Zold::List.new(wallets: wallets, copies: copies, log: log).run(args)
211
222
  when 'fetch'
212
223
  require_relative '../lib/zold/commands/fetch'
213
224
  Zold::Fetch.new(wallets: wallets, remotes: remotes, copies: copies, log: log).run(args)
@@ -6,7 +6,7 @@ function start_node {
6
6
  cd ${port}
7
7
  zold node --trace --invoice=DISTRWALLET@ffffffffffffffff \
8
8
  --host=127.0.0.1 --port=${port} --bind-port=${port} \
9
- --threads=0 --routine-immediately --never-reboot > log.txt &
9
+ --threads=0 --routine-immediately --never-reboot > log.txt 2>&1 &
10
10
  pid=$!
11
11
  echo ${pid} > pid
12
12
  cd ..
@@ -5,7 +5,7 @@ mkdir server
5
5
  cd server
6
6
  zold node --trace --invoice=PULLONSTART@ffffffffffffffff --no-metronome \
7
7
  --host=127.0.0.1 --port=${port} --bind-port=${port} \
8
- --threads=0 --standalone &
8
+ --threads=0 --standalone --pretty=full 2>&1 &
9
9
  cd ..
10
10
 
11
11
  wait_for_port ${port}
@@ -6,7 +6,7 @@ mkdir server
6
6
  cd server
7
7
  zold node --trace --invoice=PUSHNPULL@ffffffffffffffff \
8
8
  --host=127.0.0.1 --port=${port} --bind-port=${port} \
9
- --threads=0 --standalone &
9
+ --threads=0 --standalone 2>&1 &
10
10
  pid=$!
11
11
  trap "halt_nodes ${port}" EXIT
12
12
  cd ..
@@ -6,7 +6,7 @@ function start_node {
6
6
  cd ${port}
7
7
  zold node --trace --invoice=SPREADWALLETS@ffffffffffffffff \
8
8
  --host=127.0.0.1 --port=${port} --bind-port=${port} \
9
- --threads=0 > log.txt &
9
+ --threads=0 > log.txt 2>&1 &
10
10
  pid=$!
11
11
  echo ${pid} > pid
12
12
  cd ..
@@ -2,13 +2,16 @@
2
2
 
3
3
  require 'slop'
4
4
  require 'rainbow'
5
+ require_relative 'thread_badge'
5
6
  require_relative 'args'
6
7
  require_relative '../log'
7
8
 
8
9
  module Zold
9
10
  # Command to set an alias for wallet ID
10
11
  class Alias
11
- def initialize(wallets:, log: Log::Quiet.new)
12
+ prepend ThreadBadge
13
+
14
+ def initialize(wallets:, log: Log::NULL)
12
15
  @wallets = wallets
13
16
  @log = log
14
17
  end
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'slop'
24
24
  require 'zold/score'
25
+ require_relative 'thread_badge'
25
26
  require_relative '../log'
26
27
 
27
28
  # SCORE command.
@@ -31,7 +32,9 @@ require_relative '../log'
31
32
  module Zold
32
33
  # Calculate score
33
34
  class Calculate
34
- def initialize(log: Log::Quiet.new)
35
+ prepend ThreadBadge
36
+
37
+ def initialize(log: Log::NULL)
35
38
  @log = log
36
39
  end
37
40
 
@@ -41,7 +41,7 @@ require_relative '../copies'
41
41
  module Zold
42
42
  # CLEAN command
43
43
  class Clean
44
- def initialize(wallets:, copies:, log: Log::Quiet.new)
44
+ def initialize(wallets:, copies:, log: Log::NULL)
45
45
  @wallets = wallets
46
46
  @copies = copies
47
47
  @log = log
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'slop'
24
24
  require 'rainbow'
25
+ require_relative 'thread_badge'
25
26
  require_relative 'args'
26
27
  require_relative '../wallet'
27
28
  require_relative '../log'
@@ -34,7 +35,9 @@ require_relative '../id'
34
35
  module Zold
35
36
  # Create command
36
37
  class Create
37
- def initialize(wallets:, log: Log::Quiet.new)
38
+ prepend ThreadBadge
39
+
40
+ def initialize(wallets:, log: Log::NULL)
38
41
  @wallets = wallets
39
42
  @log = log
40
43
  end
@@ -48,9 +51,9 @@ Available options:"
48
51
  require: true,
49
52
  default: File.expand_path('~/.ssh/id_rsa.pub')
50
53
  o.string '--network',
51
- "The name of the network (default: #{Wallet::MAIN_NETWORK}",
54
+ "The name of the network (default: #{Wallet::MAINET}",
52
55
  require: true,
53
- default: Wallet::MAIN_NETWORK
56
+ default: Wallet::MAINET
54
57
  o.bool '--help', 'Print instructions'
55
58
  end
56
59
  mine = Args.new(opts, @log).take || return
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require_relative 'thread_badge'
23
24
  require 'tempfile'
24
25
  require 'slop'
25
26
  require 'diffy'
@@ -36,7 +37,9 @@ require_relative '../wallet'
36
37
  module Zold
37
38
  # DIFF pulling command
38
39
  class Diff
39
- def initialize(wallets:, copies:, log: Log::Quiet.new)
40
+ prepend ThreadBadge
41
+
42
+ def initialize(wallets:, copies:, log: Log::NULL)
40
43
  @wallets = wallets
41
44
  @copies = copies
42
45
  @log = log
@@ -28,6 +28,7 @@ require 'slop'
28
28
  require 'rainbow'
29
29
  require 'concurrent/atomics'
30
30
  require 'zold/score'
31
+ require_relative 'thread_badge'
31
32
  require_relative 'args'
32
33
  require_relative '../log'
33
34
  require_relative '../age'
@@ -43,7 +44,9 @@ require_relative '../copies'
43
44
  module Zold
44
45
  # FETCH pulling command
45
46
  class Fetch
46
- def initialize(wallets:, remotes:, copies:, log: Log::Quiet.new)
47
+ prepend ThreadBadge
48
+
49
+ def initialize(wallets:, remotes:, copies:, log: Log::NULL)
47
50
  @wallets = wallets
48
51
  @remotes = remotes
49
52
  @copies = copies
@@ -21,6 +21,7 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'slop'
24
+ require_relative 'thread_badge'
24
25
  require_relative 'args'
25
26
  require_relative '../log'
26
27
  require_relative '../prefixes'
@@ -32,7 +33,9 @@ require_relative '../prefixes'
32
33
  module Zold
33
34
  # Generate invoice
34
35
  class Invoice
35
- def initialize(wallets:, remotes:, copies:, log: Log::Quiet.new)
36
+ prepend ThreadBadge
37
+
38
+ def initialize(wallets:, remotes:, copies:, log: Log::NULL)
36
39
  @wallets = wallets
37
40
  @remotes = remotes
38
41
  @copies = copies
@@ -20,9 +20,11 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require_relative 'thread_badge'
23
24
  require_relative '../log'
24
25
  require_relative '../amount'
25
26
  require_relative '../wallet'
27
+ require_relative '../size'
26
28
 
27
29
  # LIST command.
28
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -31,26 +33,32 @@ require_relative '../wallet'
31
33
  module Zold
32
34
  # LIST command
33
35
  class List
34
- def initialize(wallets:, log: Log::Quiet.new)
36
+ prepend ThreadBadge
37
+
38
+ def initialize(wallets:, copies:, log: Log::NULL)
35
39
  @wallets = wallets
40
+ @copies = copies
36
41
  @log = log
37
42
  end
38
43
 
39
44
  def run(_ = [])
40
45
  total = 0
41
46
  txns = 0
47
+ size = 0
42
48
  balance = Amount::ZERO
43
49
  @wallets.all.sort.each do |id|
44
50
  total += 1
51
+ cps = Copies.new(File.join(@copies, id))
45
52
  @wallets.acq(id) do |wallet|
46
- msg = wallet.mnemo
47
- msg += " (net:#{wallet.network})" if wallet.network != Wallet::MAIN_NETWORK
53
+ msg = "#{wallet.mnemo} #{cps.all.count}c"
54
+ msg += " (net:#{wallet.network})" if wallet.network != Wallet::MAINET
48
55
  txns += wallet.txns.count
49
56
  balance += wallet.balance
57
+ size += wallet.size
50
58
  @log.info(msg)
51
59
  end
52
60
  end
53
- @log.info("#{total} wallets, #{txns} transactions, #{balance} in total")
61
+ @log.info("#{total} wallets, #{txns} transactions, #{Size.new(size)}, #{balance} in total")
54
62
  end
55
63
  end
56
64
  end
@@ -23,6 +23,7 @@
23
23
  require 'slop'
24
24
  require 'rainbow'
25
25
  require 'backtrace'
26
+ require_relative 'thread_badge'
26
27
  require_relative 'args'
27
28
  require_relative '../age'
28
29
  require_relative '../log'
@@ -37,7 +38,9 @@ require_relative '../patch'
37
38
  module Zold
38
39
  # MERGE pulling command
39
40
  class Merge
40
- def initialize(wallets:, copies:, log: Log::Quiet.new)
41
+ prepend ThreadBadge
42
+
43
+ def initialize(wallets:, copies:, log: Log::NULL)
41
44
  @wallets = wallets
42
45
  @copies = copies
43
46
  @log = log
@@ -51,6 +54,9 @@ Available options:"
51
54
  o.bool '--no-baseline',
52
55
  'Don\'t trust any remote copies and re-validate all incoming payments against their wallets',
53
56
  default: false
57
+ o.bool '--skip-propagate',
58
+ 'Don\'t propagate after merge',
59
+ default: false
54
60
  o.bool '--help', 'Print instructions'
55
61
  end
56
62
  mine = Args.new(opts, @log).take || return
@@ -58,6 +64,7 @@ Available options:"
58
64
  (mine.empty? ? @wallets.all : mine.map { |i| Id.new(i) }).each do |id|
59
65
  next unless merge(id, Copies.new(File.join(@copies, id)), opts)
60
66
  modified << id
67
+ next if opts['skip-propagate']
61
68
  require_relative 'propagate'
62
69
  modified += Propagate.new(wallets: @wallets, log: @log).run(args)
63
70
  end
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'slop'
24
24
  require 'zold/score'
25
+ require_relative 'thread_badge'
25
26
  require_relative '../log'
26
27
 
27
28
  # NEXT command.
@@ -31,7 +32,9 @@ require_relative '../log'
31
32
  module Zold
32
33
  # Calculate next score
33
34
  class Next
34
- def initialize(log: Log::Quiet.new)
35
+ prepend ThreadBadge
36
+
37
+ def initialize(log: Log::NULL)
35
38
  @log = log
36
39
  end
37
40
 
@@ -25,6 +25,7 @@ require 'slop'
25
25
  require 'backtrace'
26
26
  require 'concurrent'
27
27
  require 'zold/score'
28
+ require_relative 'thread_badge'
28
29
  require_relative '../version'
29
30
  require_relative '../age'
30
31
  require_relative '../metronome'
@@ -54,7 +55,9 @@ require_relative 'remote'
54
55
  module Zold
55
56
  # NODE command
56
57
  class Node
57
- def initialize(wallets:, remotes:, copies:, log: Log::Quiet.new)
58
+ prepend ThreadBadge
59
+
60
+ def initialize(wallets:, remotes:, copies:, log: Log::NULL)
58
61
  @remotes = remotes
59
62
  @copies = copies
60
63
  @log = log
@@ -123,8 +126,8 @@ module Zold
123
126
  'The location of RSA private key (default: ~/.ssh/id_rsa)',
124
127
  default: '~/.ssh/id_rsa'
125
128
  o.string '--network',
126
- "The name of the network (default: #{Wallet::MAIN_NETWORK})",
127
- default: Wallet::MAIN_NETWORK
129
+ "The name of the network (default: #{Wallet::MAINET})",
130
+ default: Wallet::MAINET
128
131
  o.integer '--nohup-max-cycles',
129
132
  'Maximum amount of nohup re-starts (-1 by default, which means forever)',
130
133
  default: -1
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'slop'
24
24
  require 'rainbow'
25
+ require_relative 'thread_badge'
25
26
  require_relative 'args'
26
27
  require_relative '../id'
27
28
  require_relative '../amount'
@@ -34,7 +35,9 @@ require_relative '../log'
34
35
  module Zold
35
36
  # Money sending command
36
37
  class Pay
37
- def initialize(wallets:, remotes:, log: Log::Quiet.new)
38
+ prepend ThreadBadge
39
+
40
+ def initialize(wallets:, remotes:, log: Log::NULL)
38
41
  @wallets = wallets
39
42
  @remotes = remotes
40
43
  @log = log
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'slop'
24
24
  require 'rainbow'
25
+ require_relative 'thread_badge'
25
26
  require_relative 'args'
26
27
  require_relative '../log'
27
28
  require_relative '../age'
@@ -36,7 +37,9 @@ require_relative '../prefixes'
36
37
  module Zold
37
38
  # PROPAGATE pulling command
38
39
  class Propagate
39
- def initialize(wallets:, log: Log::Quiet.new)
40
+ prepend ThreadBadge
41
+
42
+ def initialize(wallets:, log: Log::NULL)
40
43
  @wallets = wallets
41
44
  @log = log
42
45
  end
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require_relative 'thread_badge'
23
24
  require_relative '../log'
24
25
  require_relative 'fetch'
25
26
  require_relative 'merge'
@@ -32,7 +33,9 @@ require_relative 'clean'
32
33
  module Zold
33
34
  # PULL command
34
35
  class Pull
35
- def initialize(wallets:, remotes:, copies:, log: Log::Quiet.new)
36
+ prepend ThreadBadge
37
+
38
+ def initialize(wallets:, remotes:, copies:, log: Log::NULL)
36
39
  @wallets = wallets
37
40
  @remotes = remotes
38
41
  @copies = copies