zold 0.14.45 → 0.14.46

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dc091e61d283ef577ce87d8820b39688a07c57f628992f566ed3fd73845c536
4
- data.tar.gz: b521a547e508f4b3d562ab0c166baf686cfca29879c25366bf46325e91e156c0
3
+ metadata.gz: c359aed6c4deb0d0a24de1ca8708f6cdb8fac8da481392df5e8a375c5c9edb1a
4
+ data.tar.gz: b967d7822af606bcd9f19d6601498d8b00693599512f3a008ece9336334e8f40
5
5
  SHA512:
6
- metadata.gz: c54c68946531a91b6087f7cfaf311dc0b11f7e20fcf0b6e053792c7d525bb608759f18cbbac16811ae35aa6d0ba79add1ba66848c3b070937d24356370d47437
7
- data.tar.gz: ce085d811af804213af2efbd8ced6bec1afa62127fdd3d83c5d0d4463b515bcaad0687037109a6a1770ff7c8c8f4e9c4745a01cf57a6ff628d45963e803d7aaf
6
+ metadata.gz: 6f4c779de8bbcda39f648e7b3e8d062cf9d2462092b109ac23870eb397f23ad15950a1ef32cc461dca17c116a2893595ebd7dd801e798939b4b76b812d0ce433
7
+ data.tar.gz: 12c2f331075d390b253928200024b82cea9c78367f0a4155a0407ad0c0c077ddef8037004959cb7c1c41bb92d5e6ff5fb39244c8d23fe5e36fbe3338e841d6da
@@ -75,6 +75,9 @@ Available options:"
75
75
  o.bool '--ignore-score-weakness',
76
76
  'Don\'t complain when their score is too weak',
77
77
  default: false
78
+ o.bool '--ignore-nodes-absence',
79
+ 'Don\'t complain if there are not enough nodes in the network to pay taxes',
80
+ default: false
78
81
  o.bool '--help', 'Print instructions'
79
82
  end
80
83
  mine = Args.new(opts, @log).take || return
@@ -112,20 +115,28 @@ Available options:"
112
115
  raise 'The wallet is absent' unless wallet.exists?
113
116
  tax = Tax.new(wallet)
114
117
  debt = tax.debt
115
- @log.debug("The current debt is #{debt} (#{debt.to_i} zents)")
118
+ @log.info("The current debt is #{debt} (#{debt.to_i} zents)")
116
119
  unless tax.in_debt?
117
120
  @log.debug("No need to pay taxes yet, until the debt is less than #{Tax::TRIAL} (#{Tax::TRIAL.to_i} zents)")
118
121
  return
119
122
  end
120
123
  top = top_scores(opts)
121
124
  while debt > Tax::TRIAL
122
- raise 'No acceptable remote nodes, try later' if top.empty?
125
+ if top.empty?
126
+ raise 'No acceptable remote nodes, try later' unless opts['ignore-nodes-absence']
127
+ @log.info('Not enough strong nodes in the network, try later')
128
+ break
129
+ end
123
130
  best = top.shift
131
+ if tax.exists?(tax.details(best))
132
+ @log.debug("The score has already been taxed: #{best}")
133
+ next
134
+ end
124
135
  txn = tax.pay(Zold::Key.new(file: opts['private-key']), best)
125
136
  debt += txn.amount
126
137
  @log.info("#{txn.amount} of taxes paid to #{txn.bnf}, #{debt} left to pay")
127
138
  end
128
- @log.info('The wallet is in good standing, all taxes paid')
139
+ @log.info('The wallet is in good standing, all taxes paid') unless tax.in_debt?
129
140
  end
130
141
 
131
142
  def debt(wallet, _)
data/lib/zold/tax.rb CHANGED
@@ -58,8 +58,8 @@ module Zold
58
58
  end
59
59
 
60
60
  # Check whether this tax payment already exists in the wallet.
61
- def exists?(txn)
62
- !@wallet.txns.find { |t| t.details.start_with?("#{Tax::PREFIX} ") && t.details == txn.details }.nil?
61
+ def exists?(details)
62
+ !@wallet.txns.find { |t| t.details.start_with?("#{Tax::PREFIX} ") && t.details == details }.nil?
63
63
  end
64
64
 
65
65
  def details(best)
data/lib/zold/version.rb CHANGED
@@ -25,6 +25,6 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.14.45'
28
+ VERSION = '0.14.46'
29
29
  PROTOCOL = 2
30
30
  end
data/lib/zold/wallet.rb CHANGED
@@ -133,7 +133,7 @@ module Zold
133
133
  dup = txns.find { |t| t.bnf == txn.bnf && t.id == txn.id }
134
134
  raise "Wallet #{id} can't pay itself: #{txn}" if txn.bnf == id
135
135
  raise "The transaction with the same ID and BNF already exists in #{id}: #{dup}" unless dup.nil?
136
- raise "The tax payment already exists in #{id}: #{txn}" if Tax.new(self).exists?(txn)
136
+ raise "The tax payment already exists in #{id}: #{txn}" if Tax.new(self).exists?(txn.details)
137
137
  File.open(@file, 'a') { |f| f.print "#{txn}\n" }
138
138
  @txns.flush
139
139
  end
@@ -63,6 +63,21 @@ class TestTaxes < Minitest::Test
63
63
  ['taxes', '--private-key=fixtures/id_rsa', '--ignore-score-weakness', 'pay', wallet.id.to_s]
64
64
  )
65
65
  assert_equal(Zold::Amount.new(coins: 81_561_428_951), wallet.balance)
66
+ wallet.add(
67
+ Zold::Txn.new(
68
+ 2,
69
+ Time.now - 24 * 60 * 60 * 365 * 300,
70
+ Zold::Amount.new(zld: 19.99),
71
+ 'NOPREFIX', Zold::Id.new, '-'
72
+ )
73
+ )
74
+ Zold::Taxes.new(wallets: wallets, remotes: remotes, log: test_log).run(
75
+ [
76
+ 'taxes', '--private-key=fixtures/id_rsa', '--ignore-score-weakness',
77
+ '--ignore-nodes-absence', 'pay', wallet.id.to_s
78
+ ]
79
+ )
80
+ assert_equal(Zold::Amount.new(coins: 167_417_825_198), wallet.balance)
66
81
  end
67
82
  end
68
83
  end
data/test/test_tax.rb CHANGED
@@ -119,26 +119,8 @@ class TestTax < Minitest::Test
119
119
  suffixes: %w[A B C D E F G H I J K L M N O P Q R S T U V]
120
120
  )
121
121
  tax.pay(Zold::Key.new(file: 'fixtures/id_rsa'), score)
122
- assert(
123
- tax.exists?(
124
- Zold::Txn.new(
125
- 2,
126
- Time.now,
127
- Zold::Amount.new(zld: 10.99),
128
- 'AAPREFIX', target.id, tax.details(score)
129
- )
130
- )
131
- )
132
- assert(
133
- !tax.exists?(
134
- Zold::Txn.new(
135
- 2,
136
- Time.now,
137
- Zold::Amount.new(zld: 10.99),
138
- 'NOPREFIX', target.id, '-'
139
- )
140
- )
141
- )
122
+ assert(tax.exists?(tax.details(score)))
123
+ assert(!tax.exists?('-'))
142
124
  end
143
125
  end
144
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.45
4
+ version: 0.14.46
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko