zold 0.31.5 → 0.31.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codecov.yml +20 -0
  3. data/.github/workflows/pdd.yml +11 -0
  4. data/.github/workflows/rake.yml +23 -0
  5. data/.github/workflows/xcop.yml +11 -0
  6. data/.rubocop.yml +9 -5
  7. data/.ruby-version +1 -1
  8. data/.rultor.yml +4 -5
  9. data/.simplecov +15 -19
  10. data/Dockerfile +1 -1
  11. data/Gemfile +13 -13
  12. data/Guardfile +1 -1
  13. data/README.md +0 -5
  14. data/Rakefile +1 -1
  15. data/bin/zold +1 -1
  16. data/features/step_definitions/steps.rb +5 -5
  17. data/features/support/env.rb +1 -1
  18. data/fixtures/merge/asserts.rb +1 -1
  19. data/fixtures/merge/into_no_wallet/assert.rb +1 -1
  20. data/fixtures/merge/legacy_negatives_stay/assert.rb +2 -2
  21. data/fixtures/merge/missed_wallets/assert.rb +2 -2
  22. data/fixtures/merge/negative_overwriting/assert.rb +1 -1
  23. data/fixtures/merge/negatives_in_between/assert.rb +2 -2
  24. data/fixtures/merge/random_expenses/assert.rb +2 -2
  25. data/fixtures/merge/simple_case/assert.rb +1 -1
  26. data/fixtures/merge/unconfirmed_income/assert.rb +1 -1
  27. data/lib/zold/age.rb +1 -1
  28. data/lib/zold/amount.rb +3 -3
  29. data/lib/zold/cached_wallets.rb +1 -1
  30. data/lib/zold/commands/args.rb +1 -1
  31. data/lib/zold/commands/calculate.rb +2 -2
  32. data/lib/zold/commands/clean.rb +1 -1
  33. data/lib/zold/commands/create.rb +6 -2
  34. data/lib/zold/commands/diff.rb +3 -3
  35. data/lib/zold/commands/fetch.rb +3 -3
  36. data/lib/zold/commands/invoice.rb +1 -1
  37. data/lib/zold/commands/list.rb +1 -1
  38. data/lib/zold/commands/merge.rb +4 -4
  39. data/lib/zold/commands/next.rb +1 -1
  40. data/lib/zold/commands/node.rb +3 -3
  41. data/lib/zold/commands/pay.rb +2 -2
  42. data/lib/zold/commands/propagate.rb +2 -2
  43. data/lib/zold/commands/pull.rb +1 -1
  44. data/lib/zold/commands/push.rb +1 -1
  45. data/lib/zold/commands/remote.rb +1 -1
  46. data/lib/zold/commands/remove.rb +1 -1
  47. data/lib/zold/commands/routines/audit.rb +7 -8
  48. data/lib/zold/commands/routines/gc.rb +1 -1
  49. data/lib/zold/commands/routines/reconcile.rb +1 -1
  50. data/lib/zold/commands/routines/reconnect.rb +1 -1
  51. data/lib/zold/commands/routines/retire.rb +1 -1
  52. data/lib/zold/commands/routines.rb +1 -1
  53. data/lib/zold/commands/show.rb +5 -6
  54. data/lib/zold/commands/taxes.rb +2 -2
  55. data/lib/zold/commands/thread_badge.rb +1 -1
  56. data/lib/zold/copies.rb +4 -4
  57. data/lib/zold/dir_items.rb +2 -2
  58. data/lib/zold/endless.rb +3 -5
  59. data/lib/zold/gem.rb +1 -1
  60. data/lib/zold/hands.rb +4 -4
  61. data/lib/zold/head.rb +1 -1
  62. data/lib/zold/hexnum.rb +1 -1
  63. data/lib/zold/http.rb +5 -4
  64. data/lib/zold/hungry_wallets.rb +2 -2
  65. data/lib/zold/id.rb +3 -5
  66. data/lib/zold/json_page.rb +2 -2
  67. data/lib/zold/key.rb +5 -5
  68. data/lib/zold/log.rb +7 -7
  69. data/lib/zold/metronome.rb +2 -2
  70. data/lib/zold/node/async_entrance.rb +9 -9
  71. data/lib/zold/node/entrance.rb +5 -5
  72. data/lib/zold/node/farm.rb +4 -4
  73. data/lib/zold/node/farmers.rb +2 -4
  74. data/lib/zold/node/front.rb +23 -19
  75. data/lib/zold/node/journaled_pipeline.rb +6 -6
  76. data/lib/zold/node/nodup_entrance.rb +1 -1
  77. data/lib/zold/node/nospam_entrance.rb +2 -2
  78. data/lib/zold/node/pipeline.rb +6 -6
  79. data/lib/zold/node/safe_entrance.rb +2 -2
  80. data/lib/zold/node/soft_error.rb +1 -1
  81. data/lib/zold/node/spread_entrance.rb +3 -3
  82. data/lib/zold/node/sync_entrance.rb +1 -1
  83. data/lib/zold/node/trace.rb +1 -1
  84. data/lib/zold/patch.rb +14 -15
  85. data/lib/zold/prefixes.rb +1 -1
  86. data/lib/zold/remotes.rb +4 -6
  87. data/lib/zold/signature.rb +1 -1
  88. data/lib/zold/size.rb +1 -1
  89. data/lib/zold/sync_wallets.rb +1 -1
  90. data/lib/zold/tax.rb +6 -4
  91. data/lib/zold/thread_pool.rb +3 -3
  92. data/lib/zold/tree_wallets.rb +1 -1
  93. data/lib/zold/txn.rb +26 -19
  94. data/lib/zold/txns.rb +1 -1
  95. data/lib/zold/upgrades.rb +2 -2
  96. data/lib/zold/verbose_thread.rb +2 -2
  97. data/lib/zold/version.rb +2 -2
  98. data/lib/zold/version_file.rb +1 -1
  99. data/lib/zold/wallet.rb +3 -3
  100. data/lib/zold/wallets.rb +6 -1
  101. data/lib/zold.rb +1 -1
  102. data/renovate.json +6 -0
  103. data/test/commands/routines/test_audit.rb +2 -2
  104. data/test/commands/routines/test_gc.rb +2 -2
  105. data/test/commands/routines/test_reconcile.rb +2 -2
  106. data/test/commands/routines/test_reconnect.rb +2 -2
  107. data/test/commands/routines/test_retire.rb +2 -2
  108. data/test/commands/test_alias.rb +1 -1
  109. data/test/commands/test_calculate.rb +1 -1
  110. data/test/commands/test_clean.rb +4 -4
  111. data/test/commands/test_create.rb +1 -1
  112. data/test/commands/test_diff.rb +5 -5
  113. data/test/commands/test_fetch.rb +21 -21
  114. data/test/commands/test_invoice.rb +1 -1
  115. data/test/commands/test_list.rb +1 -1
  116. data/test/commands/test_merge.rb +11 -11
  117. data/test/commands/test_node.rb +1 -1
  118. data/test/commands/test_pay.rb +4 -4
  119. data/test/commands/test_propagate.rb +1 -1
  120. data/test/commands/test_pull.rb +1 -1
  121. data/test/commands/test_push.rb +1 -1
  122. data/test/commands/test_remote.rb +2 -2
  123. data/test/commands/test_remove.rb +1 -1
  124. data/test/commands/test_show.rb +1 -1
  125. data/test/commands/test_taxes.rb +2 -2
  126. data/test/fake_home.rb +4 -3
  127. data/test/node/fake_entrance.rb +1 -1
  128. data/test/node/fake_node.rb +2 -2
  129. data/test/node/test_async_entrance.rb +6 -4
  130. data/test/node/test_entrance.rb +4 -4
  131. data/test/node/test_farm.rb +2 -2
  132. data/test/node/test_farmers.rb +1 -1
  133. data/test/node/test_front.rb +4 -4
  134. data/test/node/test_nodup_entrance.rb +2 -2
  135. data/test/node/test_nospam_entrance.rb +1 -1
  136. data/test/node/test_safe_entrance.rb +3 -3
  137. data/test/node/test_spread_entrance.rb +2 -2
  138. data/test/node/test_sync_entrance.rb +1 -1
  139. data/test/node/test_trace.rb +1 -1
  140. data/test/test__helper.rb +5 -4
  141. data/test/test_age.rb +2 -2
  142. data/test/test_amount.rb +1 -1
  143. data/test/test_cached_wallets.rb +3 -3
  144. data/test/test_copies.rb +6 -6
  145. data/test/test_dir_items.rb +2 -4
  146. data/test/test_gem.rb +1 -1
  147. data/test/test_hands.rb +1 -1
  148. data/test/test_hexnum.rb +1 -1
  149. data/test/test_http.rb +5 -5
  150. data/test/test_hungry_wallets.rb +1 -1
  151. data/test/test_id.rb +1 -1
  152. data/test/test_json_page.rb +1 -1
  153. data/test/test_key.rb +5 -5
  154. data/test/test_log.rb +1 -1
  155. data/test/test_metronome.rb +2 -1
  156. data/test/test_patch.rb +9 -9
  157. data/test/test_prefixes.rb +1 -1
  158. data/test/test_remotes.rb +2 -2
  159. data/test/test_signature.rb +1 -1
  160. data/test/test_size.rb +1 -1
  161. data/test/test_sync_wallets.rb +1 -1
  162. data/test/test_tax.rb +4 -4
  163. data/test/test_thread_pool.rb +1 -1
  164. data/test/test_tree_wallets.rb +1 -1
  165. data/test/test_txn.rb +2 -2
  166. data/test/test_upgrades.rb +4 -4
  167. data/test/test_verbose_thread.rb +1 -1
  168. data/test/test_wallet.rb +14 -14
  169. data/test/test_wallets.rb +1 -1
  170. data/test/test_zold.rb +2 -2
  171. data/test/upgrades/test_delete_banned_wallets.rb +1 -1
  172. data/test/upgrades/test_protocol_up.rb +1 -1
  173. data/upgrades/2.rb +1 -1
  174. data/upgrades/delete_banned_wallets.rb +2 -2
  175. data/upgrades/move_wallets_into_tree.rb +1 -1
  176. data/upgrades/protocol_up.rb +3 -3
  177. data/upgrades/rename_foreign_wallets.rb +2 -2
  178. data/zold.gemspec +21 -24
  179. metadata +40 -117
  180. data/.github/CODE_OF_CONDUCT.md +0 -76
  181. data/.github/CONTRIBUTING.md +0 -11
  182. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  183. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -145,7 +145,7 @@ Available options:"
145
145
  end
146
146
  if modified
147
147
  @log.info("#{cps.count} copies with the total score of #{score} successfully merged \
148
- into #{@wallets.acq(id, &:mnemo)} in #{Age.new(start, limit: 0.1 + cps.count * 0.01)}")
148
+ into #{@wallets.acq(id, &:mnemo)} in #{Age.new(start, limit: 0.1 + (cps.count * 0.01))}")
149
149
  else
150
150
  @log.info("Nothing changed in #{id} after merge of #{cps.count} copies")
151
151
  end
@@ -157,14 +157,14 @@ into #{@wallets.acq(id, &:mnemo)} in #{Age.new(start, limit: 0.1 + cps.count * 0
157
157
  @log.debug("Adding copy ##{name}#{master ? ' (master)' : ''} to the patch #{wallet.mnemo}...")
158
158
  if opts['depth'].positive?
159
159
  patch.join(wallet, ledger: opts['ledger'], baseline: baseline, master: master) do |txn|
160
- trusted = IO.read(opts['trusted']).split(',')
160
+ trusted = File.read(opts['trusted']).split(',')
161
161
  if trusted.include?(txn.bnf.to_s)
162
162
  @log.debug("Won't PULL #{txn.bnf} since it is already trusted, among #{trusted.count} others")
163
163
  elsif trusted.count > opts['trusted-max']
164
164
  @log.debug("Won't PULL #{txn.bnf} since there are too many trusted wallets already: \
165
165
  #{trusted.count} > #{opts['trusted-max']}")
166
166
  else
167
- IO.write(opts['trusted'], (trusted + [txn.bnf.to_s]).sort.uniq.join(','))
167
+ File.write(opts['trusted'], (trusted + [txn.bnf.to_s]).sort.uniq.join(','))
168
168
  Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
169
169
  ['pull', txn.bnf.to_s, "--network=#{Shellwords.escape(opts['network'])}", '--quiet-if-absent'] +
170
170
  ["--depth=#{opts['depth'] - 1}"] +
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -208,7 +208,7 @@ module Zold
208
208
  the node won\'t connect to the network like that; try to do "zold remote reset" first'
209
209
  end
210
210
  pid = nohup(opts)
211
- IO.write(opts['save-pid'], pid) if opts['save-pid']
211
+ File.write(opts['save-pid'], pid) if opts['save-pid']
212
212
  @log.debug("Process ID #{pid} saved into \"#{opts['save-pid']}\"")
213
213
  @log.info(pid)
214
214
  return
@@ -499,7 +499,7 @@ the node won\'t connect to the network like that; try to do "zold remote reset"
499
499
  temp = Tempfile.new
500
500
  total = copy(@file, temp)
501
501
  unit = File.size(@file) / total
502
- tail = total - @max / (2 * unit)
502
+ tail = total - (@max / (2 * unit))
503
503
  copy(temp, @file, tail)
504
504
  File.delete(temp)
505
505
  File.open(@file, 'a') do |f|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -163,7 +163,7 @@ Available options:"
163
163
  the difference is #{(amount - from.balance).to_i} zents"
164
164
  end
165
165
  end
166
- pem = IO.read(opts['private-key'])
166
+ pem = File.read(opts['private-key'])
167
167
  unless opts['keygap'].empty?
168
168
  pem = pem.sub('*' * opts['keygap'].length, opts['keygap'])
169
169
  @log.debug("Keygap \"#{'*' * opts['keygap'].length}\" injected into the RSA private key")
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -94,7 +94,7 @@ Available options:"
94
94
  end
95
95
  modified.uniq!
96
96
  @log.debug("Wallet #{id} propagated successfully, #{total} txns \
97
- in #{Age.new(start, limit: 20 + total * 0.005)}, #{modified.count} wallets affected")
97
+ in #{Age.new(start, limit: 20 + (total * 0.005))}, #{modified.count} wallets affected")
98
98
  modified.each do |w|
99
99
  @wallets.acq(w, &:refurbish)
100
100
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -37,12 +37,11 @@ class Zold::Routines::Audit
37
37
 
38
38
  def exec(_ = 0)
39
39
  sleep(60) unless @opts['routine-immediately']
40
- @log.info(
41
- 'Audit: ' + [
42
- "memory used: #{Zold::Size.new(GetProcessMem.new.bytes.to_i)}",
43
- "threads total: #{Thread.list.count}",
44
- "wallets: #{@wallets.count}"
45
- ].join('; ')
46
- )
40
+ msg = [
41
+ "memory used: #{Zold::Size.new(GetProcessMem.new.bytes.to_i)}",
42
+ "threads total: #{Thread.list.count}",
43
+ "wallets: #{@wallets.count}"
44
+ ].join('; ')
45
+ @log.info("Audit: #{msg}")
47
46
  end
48
47
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -49,7 +49,7 @@ class Zold::Routines::Reconcile
49
49
  res = r.http('/wallets').get
50
50
  r.assert_code(200, res)
51
51
  missing = res.body.strip.split("\n").compact
52
- .select { |i| /^[a-f0-9]{16}$/.match?(i) }
52
+ .grep(/^[a-f0-9]{16}$/)
53
53
  .reject { |i| @wallets.acq(Zold::Id.new(i), &:exists?) }
54
54
  missing.each { |i| pull(i) }
55
55
  if missing.empty?
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -87,11 +87,10 @@ Available options:"
87
87
  "Digest: #{wallet.digest}"
88
88
  ].join("\n")
89
89
  )
90
- @log.info(
91
- "\n" + Copies.new(File.join(@copies, wallet.id)).all.map do |c|
92
- "##{c[:name]}: #{c[:score]} #{Wallet.new(c[:path]).mnemo}"
93
- end.join("\n")
94
- )
90
+ msg = Copies.new(File.join(@copies, wallet.id)).all.map do |c|
91
+ "##{c[:name]}: #{c[:score]} #{Wallet.new(c[:path]).mnemo}"
92
+ end.join("\n")
93
+ @log.info("\n#{msg}")
95
94
  balance
96
95
  end
97
96
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -154,7 +154,7 @@ the balance is #{wallet.balance}: #{tax.to_text}")
154
154
  @log.debug("The score has already been taxed: #{best}")
155
155
  next
156
156
  end
157
- pem = IO.read(opts['private-key'])
157
+ pem = File.read(opts['private-key'])
158
158
  unless opts['keygap'].empty?
159
159
  pem = pem.sub('*' * opts['keygap'].length, opts['keygap'])
160
160
  @log.debug("Keygap \"#{'*' * opts['keygap'].length}\" injected into the RSA private key")
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/zold/copies.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -124,7 +124,7 @@ module Zold
124
124
  .max
125
125
  max = 0 if max.nil?
126
126
  name = (max + 1).to_s
127
- IO.write(File.join(@dir, "#{name}#{Copies::EXT}"), content)
127
+ File.write(File.join(@dir, "#{name}#{Copies::EXT}"), content)
128
128
  else
129
129
  name = target[:name]
130
130
  end
@@ -150,7 +150,7 @@ module Zold
150
150
  path: File.join(@dir, "#{name}#{Copies::EXT}"),
151
151
  total: scores.count,
152
152
  master: scores.any? { |s| s[:master] },
153
- score: scores.select { |s| s[:time] > Time.now - 24 * 60 * 60 }
153
+ score: scores.select { |s| s[:time] > Time.now - (24 * 60 * 60) }
154
154
  .map { |s| s[:score] }
155
155
  .inject(&:+) || 0
156
156
  }
@@ -182,7 +182,7 @@ module Zold
182
182
  private
183
183
 
184
184
  def save(list)
185
- IO.write(
185
+ File.write(
186
186
  file,
187
187
  list.map do |r|
188
188
  [
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -41,7 +41,7 @@ module Zold
41
41
  def fetch(recursive: true)
42
42
  `find #{([@dir] + (recursive ? [] : ['-maxdepth', '1']) + ['-type', 'f', '-print']).join(' ')} 2>/dev/null`
43
43
  .strip
44
- .split(' ')
44
+ .split
45
45
  .select { |f| f.start_with?(@dir) && f.length > @dir.length }
46
46
  .map { |f| f[(@dir.length + 1)..-1] }
47
47
  end
data/lib/zold/endless.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -36,14 +36,12 @@ module Zold
36
36
  @log = log
37
37
  end
38
38
 
39
- def run
39
+ def run(&block)
40
40
  start = Time.now
41
41
  Thread.current.name = @title
42
42
  begin
43
43
  loop do
44
- VerboseThread.new(@log).run(true) do
45
- yield
46
- end
44
+ VerboseThread.new(@log).run(safe: true, &block)
47
45
  end
48
46
  ensure
49
47
  @log.debug("Endless loop \"#{@title}\" quit after #{Age.new(start)} of work")
data/lib/zold/gem.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/zold/hands.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -43,7 +43,7 @@ module Zold
43
43
 
44
44
  def self.threshold
45
45
  advised = Total::Mem.new.bytes / (128 * 1024 * 1024)
46
- [Concurrent.processor_count * 4, [advised, 4].max].min
46
+ advised.clamp(4, Concurrent.processor_count * 4)
47
47
  rescue Total::CantDetect
48
48
  4
49
49
  end
@@ -66,13 +66,13 @@ module Zold
66
66
  end
67
67
 
68
68
  # Run this code in many threads
69
- def self.exec(threads, set = (0..threads - 1).to_a)
69
+ def self.exec(threads, set = (0..threads - 1).to_a, &block)
70
70
  raise 'The thread pool is empty' if POOL.empty?
71
71
  raise "Number of threads #{threads} has to be positive" unless threads.positive?
72
72
  list = set.dup
73
73
  total = [threads, set.count].min
74
74
  if total == 1
75
- list.each_with_index { |r, i| yield(r, i) }
75
+ list.each_with_index(&block)
76
76
  elsif total.positive?
77
77
  idx = Concurrent::AtomicFixnum.new
78
78
  mutex = Mutex.new
data/lib/zold/head.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/zold/hexnum.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/zold/http.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -50,6 +50,7 @@ module Zold
50
50
  # The error, if connection fails
51
51
  class HttpError < HttpResponse
52
52
  def initialize(ex)
53
+ super(ex)
53
54
  @ex = ex
54
55
  end
55
56
 
@@ -144,12 +145,12 @@ module Zold
144
145
  Typhoeus::Request.put(
145
146
  @uri,
146
147
  accept_encoding: 'gzip',
147
- body: IO.read(file),
148
+ body: File.read(file),
148
149
  headers: headers.merge(
149
150
  'Content-Type': 'text/plain'
150
151
  ),
151
152
  connecttimeout: CONNECT_TIMEOUT,
152
- timeout: 2 + File.size(file) * 0.01 / 1024
153
+ timeout: 2 + (File.size(file) * 0.01 / 1024)
153
154
  )
154
155
  )
155
156
  rescue StandardError => e
@@ -161,7 +162,7 @@ module Zold
161
162
  def headers
162
163
  headers = {
163
164
  'User-Agent': "Zold #{VERSION}",
164
- 'Connection': 'close',
165
+ Connection: 'close',
165
166
  'Accept-Encoding': 'gzip'
166
167
  }
167
168
  headers[Http::VERSION_HEADER] = Zold::VERSION
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -64,7 +64,7 @@ module Zold
64
64
  else
65
65
  @mutex.synchronize do
66
66
  unless @queue.include?(id)
67
- @missed.put(id.to_s, lifetime: 5 * 60)
67
+ @missed.put(id.to_s, true, lifetime: 5 * 60)
68
68
  @queue << id
69
69
  @log.debug("Hungry queue got #{id}, at the pos no.#{@queue.size - 1}")
70
70
  end
data/lib/zold/id.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -34,13 +34,11 @@ module Zold
34
34
  private_constant :PTN
35
35
 
36
36
  # Returns a list of banned IDs, as strings
37
- BANNED = begin
38
- CSV.read(File.join(__dir__, '../../resources/banned-wallets.csv')).map { |r| r[0] }
39
- end
37
+ BANNED = CSV.read(File.join(__dir__, '../../resources/banned-wallets.csv')).map { |r| r[0] }
40
38
 
41
39
  def self.generate_id
42
40
  loop do
43
- id = format('%016x', rand(2**32..2**64 - 1))
41
+ id = format('%016x', rand((2**32)..(2**64) - 1))
44
42
  next if Id::BANNED.include?(id)
45
43
  return id
46
44
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -40,7 +40,7 @@ module Zold
40
40
  end
41
41
 
42
42
  def to_hash
43
- raise CantParse, 'JSON is empty, can\'t parse' + (@uri.empty? ? '' : " at #{@uri}") if @text.empty?
43
+ raise CantParse, "JSON is empty, can't parse#{@uri.empty? ? '' : " at #{@uri}"}" if @text.empty?
44
44
  JSON.parse(@text)
45
45
  rescue JSON::ParserError => e
46
46
  raise CantParse, "Failed to parse JSON #{@uri.empty? ? '' : "at #{@uri}"} (#{short(e.message)}): #{short(@text)}"
data/lib/zold/key.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -37,7 +37,7 @@ module Zold
37
37
  unless file.nil?
38
38
  path = File.expand_path(file)
39
39
  raise "Can't find RSA key at #{file} (#{path})" unless File.exist?(path)
40
- return IO.read(path)
40
+ return File.read(path)
41
41
  end
42
42
  unless text.nil?
43
43
  return text if text.start_with?('-----')
@@ -71,11 +71,11 @@ module Zold
71
71
  end
72
72
 
73
73
  def sign(text)
74
- Base64.encode64(rsa.sign(OpenSSL::Digest::SHA256.new, text)).delete("\n")
74
+ Base64.encode64(rsa.sign(OpenSSL::Digest.new('SHA256'), text)).delete("\n")
75
75
  end
76
76
 
77
77
  def verify(signature, text)
78
- rsa.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(signature), text)
78
+ rsa.verify(OpenSSL::Digest.new('SHA256'), Base64.decode64(signature), text)
79
79
  end
80
80
 
81
81
  private
@@ -84,7 +84,7 @@ module Zold
84
84
  text = @body.call.strip
85
85
  unless text.start_with?('-----BEGIN')
86
86
  Tempfile.open do |f|
87
- IO.write(f.path, text)
87
+ File.write(f.path, text)
88
88
  text = `ssh-keygen -f #{f.path} -e -m pem`
89
89
  end
90
90
  end
data/lib/zold/log.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -64,12 +64,12 @@ module Zold
64
64
  when 'DEBUG'
65
65
  prefix = 'D: '
66
66
  end
67
- colored(prefix, severity) + msg.to_s.rstrip.gsub(/\n/, "\n" + (' ' * prefix.length)) + "\n"
67
+ "#{colored(prefix, severity)}#{msg.to_s.rstrip.gsub("\n", "\n#{' ' * prefix.length}")}\n"
68
68
  end
69
69
 
70
70
  # Short formatter
71
71
  SHORT = proc do |_severity, _time, _target, msg|
72
- msg.to_s.rstrip + "\n"
72
+ "#{msg.to_s.rstrip}\n"
73
73
  end
74
74
 
75
75
  # Full formatter
@@ -83,24 +83,24 @@ module Zold
83
83
  end
84
84
 
85
85
  # No logging at all
86
- NULL = Logger.new(STDOUT)
86
+ NULL = Logger.new($stdout)
87
87
  NULL.level = Logger::UNKNOWN
88
88
  NULL.freeze
89
89
 
90
90
  # Everything, including debug
91
- VERBOSE = Logger.new(STDOUT)
91
+ VERBOSE = Logger.new($stdout)
92
92
  VERBOSE.level = Logger::DEBUG
93
93
  VERBOSE.formatter = COMPACT
94
94
  VERBOSE.freeze
95
95
 
96
96
  # Info and errors, no debug info
97
- REGULAR = Logger.new(STDOUT)
97
+ REGULAR = Logger.new($stdout)
98
98
  REGULAR.level = Logger::INFO
99
99
  REGULAR.formatter = COMPACT
100
100
  REGULAR.freeze
101
101
 
102
102
  # Errors only
103
- ERRORS = Logger.new(STDOUT)
103
+ ERRORS = Logger.new($stdout)
104
104
  ERRORS.level = Logger::ERROR
105
105
  ERRORS.formatter = COMPACT
106
106
  ERRORS.freeze
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2018-2023 Zerocracy, Inc.
3
+ # Copyright (c) 2018-2023 Zerocracy
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
@@ -68,7 +68,7 @@ module Zold
68
68
  @log.debug("Routine #{r.class.name} ##{step} done \
69
69
  in #{Age.new(Thread.current.thread_variable_get(:start))}")
70
70
  rescue StandardError => e
71
- @failures[r.class.name] = Time.now.utc.iso8601 + "\n" + Backtrace.new(e).to_s
71
+ @failures[r.class.name] = "#{Time.now.utc.iso8601}\n#{Backtrace.new(e)}"
72
72
  @log.error("Routine #{r.class.name} ##{step} failed \
73
73
  in #{Age.new(Thread.current.thread_variable_get(:start))}")
74
74
  raise e