zold 0.14.45 → 0.14.46
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zold/commands/taxes.rb +14 -3
- data/lib/zold/tax.rb +2 -2
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +1 -1
- data/test/commands/test_taxes.rb +15 -0
- data/test/test_tax.rb +2 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c359aed6c4deb0d0a24de1ca8708f6cdb8fac8da481392df5e8a375c5c9edb1a
|
4
|
+
data.tar.gz: b967d7822af606bcd9f19d6601498d8b00693599512f3a008ece9336334e8f40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f4c779de8bbcda39f648e7b3e8d062cf9d2462092b109ac23870eb397f23ad15950a1ef32cc461dca17c116a2893595ebd7dd801e798939b4b76b812d0ce433
|
7
|
+
data.tar.gz: 12c2f331075d390b253928200024b82cea9c78367f0a4155a0407ad0c0c077ddef8037004959cb7c1c41bb92d5e6ff5fb39244c8d23fe5e36fbe3338e841d6da
|
data/lib/zold/commands/taxes.rb
CHANGED
@@ -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.
|
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
|
-
|
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?(
|
62
|
-
!@wallet.txns.find { |t| t.details.start_with?("#{Tax::PREFIX} ") && t.details ==
|
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
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
|
data/test/commands/test_taxes.rb
CHANGED
@@ -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
|
-
|
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
|