zold 0.14.50 → 0.14.51
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 +4 -4
- data/lib/zold/commands/propagate.rb +9 -3
- data/lib/zold/patch.rb +1 -1
- data/lib/zold/version.rb +1 -1
- data/lib/zold/wallet.rb +14 -4
- data/test/test_wallet.rb +19 -0
- 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: 53fed8a92732a47d8473dd93dcfccf0cc5aac6cd2dad450068779d3faabc8849
|
|
4
|
+
data.tar.gz: 6eb21513a8b304eb81ad3ef3d46f8c8d802aa0be3b409e06bdadaf5c6021ee88
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86cee566355856078b67b2f90f150458158f24a3e5d1681c580c86227dbdffac875c01377e3b69987dca088ed026351a623d02a1f51e653fbfb1ee1b8bd7372f
|
|
7
|
+
data.tar.gz: 55d61bc63a682151a23a35098449c5798f4ba783101ec8d609a0511cb0462c4f1344e9c191e4b53ae2093c1c576463438c247afea8ef84c72afd6785556f263d
|
|
@@ -63,9 +63,14 @@ Available options:"
|
|
|
63
63
|
def propagate(id, _)
|
|
64
64
|
start = Time.now
|
|
65
65
|
modified = []
|
|
66
|
+
total = 0
|
|
66
67
|
@wallets.find(id) do |wallet|
|
|
67
68
|
wallet.txns.select { |t| t.amount.negative? }.each do |t|
|
|
68
|
-
|
|
69
|
+
total += 1
|
|
70
|
+
if t.bnf == id
|
|
71
|
+
@log.error("Paying itself in #{id}? #{t}")
|
|
72
|
+
next
|
|
73
|
+
end
|
|
69
74
|
@wallets.find(t.bnf) do |target|
|
|
70
75
|
unless target.exists?
|
|
71
76
|
@log.debug("#{t.amount * -1} to #{t.bnf}: wallet is absent")
|
|
@@ -75,7 +80,7 @@ Available options:"
|
|
|
75
80
|
@log.error("#{t.amount * -1} to #{t.bnf}: network mismatch, '#{target.network}'!='#{wallet.network}'")
|
|
76
81
|
next
|
|
77
82
|
end
|
|
78
|
-
next if target.
|
|
83
|
+
next if target.includes_positive?(t.id, id)
|
|
79
84
|
unless target.prefix?(t.prefix)
|
|
80
85
|
@log.error("#{t.amount * -1} to #{t.bnf}: wrong prefix")
|
|
81
86
|
next
|
|
@@ -87,7 +92,8 @@ Available options:"
|
|
|
87
92
|
end
|
|
88
93
|
end
|
|
89
94
|
modified.uniq!
|
|
90
|
-
@log.debug("Wallet #{id} propagated successfully in #{Age.new(start)},
|
|
95
|
+
@log.debug("Wallet #{id} propagated successfully, #{total} txns in #{Age.new(start)}, \
|
|
96
|
+
#{modified.count} wallets affected")
|
|
91
97
|
modified
|
|
92
98
|
end
|
|
93
99
|
end
|
data/lib/zold/patch.rb
CHANGED
|
@@ -105,7 +105,7 @@ module Zold
|
|
|
105
105
|
@log.error("Paying wallet file is absent: #{txn.to_text}")
|
|
106
106
|
next
|
|
107
107
|
end
|
|
108
|
-
unless @wallets.find(txn.bnf) { |p| p.
|
|
108
|
+
unless @wallets.find(txn.bnf) { |p| p.includes_negative?(txn.id, wallet.id) }
|
|
109
109
|
@log.error("Paying wallet #{txn.bnf} doesn't have transaction ##{txn.id} \
|
|
110
110
|
among #{payer.txns.count} transactions: #{txn.to_text}")
|
|
111
111
|
next
|
data/lib/zold/version.rb
CHANGED
data/lib/zold/wallet.rb
CHANGED
|
@@ -130,18 +130,28 @@ module Zold
|
|
|
130
130
|
|
|
131
131
|
def add(txn)
|
|
132
132
|
raise 'The txn has to be of type Txn' unless txn.is_a?(Txn)
|
|
133
|
-
dup = txns.find { |t| t.bnf == txn.bnf && t.id == txn.id && t.amount.negative? && txn.amount.negative? }
|
|
134
133
|
raise "Wallet #{id} can't pay itself: #{txn}" if txn.bnf == id
|
|
135
|
-
raise "The
|
|
134
|
+
raise "The amount can't be zero in #{id}: #{txn}" if txn.amount.zero?
|
|
135
|
+
if txn.amount.negative? && includes_negative?(txn.id)
|
|
136
|
+
raise "Negative transaction with the same ID #{txn.id} already exists in #{id}"
|
|
137
|
+
end
|
|
138
|
+
if txn.amount.positive? && includes_positive?(txn.id, txn.bnf)
|
|
139
|
+
raise "Positive transaction with the same ID #{txn.id} and BNF #{txn.bnf} already exists in #{id}"
|
|
140
|
+
end
|
|
136
141
|
raise "The tax payment already exists in #{id}: #{txn}" if Tax.new(self).exists?(txn.details)
|
|
137
142
|
File.open(@file, 'a') { |f| f.print "#{txn}\n" }
|
|
138
143
|
@txns.flush
|
|
139
144
|
end
|
|
140
145
|
|
|
141
|
-
def
|
|
146
|
+
def includes_negative?(id, bnf = nil)
|
|
147
|
+
raise 'The txn ID has to be of type Integer' unless id.is_a?(Integer)
|
|
148
|
+
!txns.find { |t| t.id == id && (bnf.nil? || t.bnf == bnf) && t.amount.negative? }.nil?
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def includes_positive?(id, bnf)
|
|
142
152
|
raise 'The txn ID has to be of type Integer' unless id.is_a?(Integer)
|
|
143
153
|
raise 'The bnf has to be of type Id' unless bnf.is_a?(Id)
|
|
144
|
-
!txns.find { |t| t.id == id && t.bnf == bnf }.nil?
|
|
154
|
+
!txns.find { |t| t.id == id && t.bnf == bnf && !t.amount.negative? }.nil?
|
|
145
155
|
end
|
|
146
156
|
|
|
147
157
|
def prefix?(prefix)
|
data/test/test_wallet.rb
CHANGED
|
@@ -79,10 +79,29 @@ class TestWallet < Minitest::Test
|
|
|
79
79
|
id = Zold::Id.new
|
|
80
80
|
wallet.sub(amount, "NOPREFIX@#{id}", key)
|
|
81
81
|
wallet.add(Zold::Txn.new(1, Time.now, amount, 'NOPREFIX', id, '-'))
|
|
82
|
+
assert_raises do
|
|
83
|
+
wallet.add(Zold::Txn.new(1, Time.now, amount, 'NOPREFIX', id, '-'))
|
|
84
|
+
end
|
|
85
|
+
assert_raises do
|
|
86
|
+
wallet.add(Zold::Txn.new(1, Time.now, amount * -1, 'NOPREFIX', id, '-'))
|
|
87
|
+
end
|
|
82
88
|
assert(wallet.balance.zero?)
|
|
83
89
|
end
|
|
84
90
|
end
|
|
85
91
|
|
|
92
|
+
def test_checks_similar_transaction
|
|
93
|
+
FakeHome.new.run do |home|
|
|
94
|
+
wallet = home.create_wallet
|
|
95
|
+
amount = Zold::Amount.new(zld: 39.99)
|
|
96
|
+
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
|
97
|
+
id = Zold::Id.new
|
|
98
|
+
wallet.sub(amount, "NOPREFIX@#{id}", key)
|
|
99
|
+
wallet.add(Zold::Txn.new(1, Time.now, amount, 'NOPREFIX', id, '-'))
|
|
100
|
+
assert(wallet.includes_negative?(1))
|
|
101
|
+
assert(wallet.includes_positive?(1, id))
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
86
105
|
def test_refurbishes_wallet
|
|
87
106
|
FakeHome.new.run do |home|
|
|
88
107
|
wallet = home.create_wallet
|