zold 0.16.7 → 0.16.8
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/bin/zold +14 -10
- data/fixtures/scripts/_head.sh +4 -4
- data/fixtures/scripts/distribute-wallet.sh +2 -2
- data/lib/zold/amount.rb +24 -24
- data/lib/zold/commands/taxes.rb +16 -5
- data/lib/zold/http.rb +1 -1
- data/lib/zold/node/emission.rb +1 -1
- data/lib/zold/node/front.rb +6 -6
- data/lib/zold/patch.rb +1 -1
- data/lib/zold/tax.rb +9 -5
- data/lib/zold/txn.rb +1 -1
- data/lib/zold/version.rb +1 -1
- data/test/node/test_front.rb +1 -1
- data/test/test_amount.rb +3 -3
- data/test/test_tax.rb +5 -5
- data/test/test_wallet.rb +5 -5
- data/test/test_zold.rb +3 -0
- data/zold.gemspec +1 -1
- metadata +16 -20
- data/fixtures/scripts/sigdump.sh +0 -15
- data/lib/zold/cache.rb +0 -50
- data/test/test_cache.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1399da979b61a827097b2b29a04b31920f6da3a65e2af8920fc493bbb52064ba
|
4
|
+
data.tar.gz: 255d50d0c687709e5b15f1ce1fc17eec7ab656b24a7c8356aec320d8620d911c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acf61ff6782dcb26a24f17f2f208cf64d7110c1204ccb048240433541c99978f298f21de0c96974aa7c67321acf800131e80a518d5eef37709c714e7642c1c41
|
7
|
+
data.tar.gz: d0816cade1db2f054b08a321aa7bde96a6af4eb3beb8ea42d54ba3d66b88c254464d48809e3a7e1fca80a155653420f21c779f93a2db1b7c255b38e652448187
|
data/bin/zold
CHANGED
@@ -23,11 +23,7 @@
|
|
23
23
|
|
24
24
|
STDOUT.sync = true
|
25
25
|
|
26
|
-
|
27
|
-
# For debug in production, see https://github.com/frsyuki/sigdump
|
28
|
-
ENV['SIGDUMP_PATH'] = File.join(Dir.pwd, "sigdump-#{Process.pid}.log")
|
29
|
-
require 'sigdump/setup'
|
30
|
-
end
|
26
|
+
start = Time.now
|
31
27
|
|
32
28
|
require 'slop'
|
33
29
|
require 'rainbow'
|
@@ -40,6 +36,7 @@ require_relative '../lib/zold/sync_wallets'
|
|
40
36
|
require_relative '../lib/zold/cached_wallets'
|
41
37
|
require_relative '../lib/zold/log'
|
42
38
|
require_relative '../lib/zold/key'
|
39
|
+
require_relative '../lib/zold/age'
|
43
40
|
require_relative '../lib/zold/amount'
|
44
41
|
require_relative '../lib/zold/copies'
|
45
42
|
require_relative '../lib/zold/remotes'
|
@@ -60,9 +57,6 @@ unless ENV['RACK_ENV'] == 'test' || ARGV.find { |a| a == '--ignore-global-config
|
|
60
57
|
body = IO.read(config)
|
61
58
|
extra = body.split(/[\r\n]+/).map(&:strip)
|
62
59
|
args += extra
|
63
|
-
log.debug("Found #{body.split(/\n/).length} lines in #{config}")
|
64
|
-
else
|
65
|
-
log.debug("Default config file #{config} not found")
|
66
60
|
end
|
67
61
|
end
|
68
62
|
args += ARGV
|
@@ -131,6 +125,8 @@ Available options:"
|
|
131
125
|
|
132
126
|
log = Zold::Log::Sync.new(log)
|
133
127
|
|
128
|
+
log.debug("Gem location: #{File.dirname(File.dirname(__FILE__))}")
|
129
|
+
|
134
130
|
commands = opts.arguments.reject { |a| a.start_with?('-') }
|
135
131
|
command = commands[0]
|
136
132
|
|
@@ -147,6 +143,7 @@ Available options:"
|
|
147
143
|
home = File.expand_path(opts[:home])
|
148
144
|
FileUtils.mkdir_p(home)
|
149
145
|
Dir.chdir(home)
|
146
|
+
log.debug("Home directory: #{home}")
|
150
147
|
|
151
148
|
zoldata = File.join(home, '.zoldata')
|
152
149
|
|
@@ -175,10 +172,15 @@ Available options:"
|
|
175
172
|
)
|
176
173
|
fremotes = File.join(zoldata, 'remotes')
|
177
174
|
remotes = Zold::Remotes.new(file: fremotes, network: opts['network'])
|
178
|
-
|
175
|
+
if File.exist?(fremotes)
|
176
|
+
log.debug("Remote nodes: #{remotes.all.count} total")
|
177
|
+
else
|
178
|
+
remotes.defaults
|
179
|
+
log.debug("Default remotes have been set: #{remotes.all.count} total")
|
180
|
+
end
|
179
181
|
copies = File.join(zoldata, 'copies')
|
180
182
|
|
181
|
-
log.debug("Network: #{opts['network']}")
|
183
|
+
log.debug("Network: #{opts['network']} (#{opts['network'] == Zold::Wallet::MAIN_NETWORK ? 'main' : 'test'} net)")
|
182
184
|
|
183
185
|
case command
|
184
186
|
when 'node'
|
@@ -246,3 +248,5 @@ rescue StandardError => ex
|
|
246
248
|
puts(ex.backtrace) if opts['trace']
|
247
249
|
exit -1
|
248
250
|
end
|
251
|
+
|
252
|
+
log.debug("Successfully finished in #{Zold::Age.new(start)}")
|
data/fixtures/scripts/_head.sh
CHANGED
@@ -19,7 +19,7 @@ function wait_for_url {
|
|
19
19
|
echo "URL $1 is not available after ${i} attempts"
|
20
20
|
exit 12
|
21
21
|
fi
|
22
|
-
sleep
|
22
|
+
sleep 2
|
23
23
|
done
|
24
24
|
}
|
25
25
|
|
@@ -31,7 +31,7 @@ function wait_for_port {
|
|
31
31
|
echo "Port $1 is not available after ${i} attempts"
|
32
32
|
exit 13
|
33
33
|
fi
|
34
|
-
sleep
|
34
|
+
sleep 2
|
35
35
|
done
|
36
36
|
}
|
37
37
|
|
@@ -43,7 +43,7 @@ function wait_for_file {
|
|
43
43
|
echo "File $1 not found, giving up after ${i} attempts"
|
44
44
|
exit 14
|
45
45
|
fi
|
46
|
-
sleep
|
46
|
+
sleep 2
|
47
47
|
done
|
48
48
|
}
|
49
49
|
|
@@ -59,7 +59,7 @@ function halt_nodes {
|
|
59
59
|
exit 15
|
60
60
|
fi
|
61
61
|
echo "Still waiting for process ${pid} to die, attempt no.${i}"
|
62
|
-
sleep
|
62
|
+
sleep 2
|
63
63
|
done
|
64
64
|
echo "Process ${pid} is dead!"
|
65
65
|
fi
|
@@ -53,7 +53,7 @@ until zold fetch 0000000000000000 --ignore-score-weakness; do
|
|
53
53
|
echo "The wallet has not been distributed, after ${i} attempts"
|
54
54
|
exit 9
|
55
55
|
fi
|
56
|
-
sleep
|
56
|
+
sleep 2
|
57
57
|
done
|
58
58
|
|
59
59
|
# Here we check the JSON of the first node to make sure all status
|
@@ -81,6 +81,6 @@ until zold fetch 0000000000000000 --ignore-score-weakness; do
|
|
81
81
|
cat ${first}/log.txt
|
82
82
|
exit 8
|
83
83
|
fi
|
84
|
-
sleep
|
84
|
+
sleep 2
|
85
85
|
done
|
86
86
|
|
data/lib/zold/amount.rb
CHANGED
@@ -35,28 +35,28 @@ module Zold
|
|
35
35
|
# Maximum amount of zents
|
36
36
|
MAX = 2**63
|
37
37
|
|
38
|
-
def initialize(
|
39
|
-
if !
|
40
|
-
raise "Integer is required, while #{
|
41
|
-
@
|
38
|
+
def initialize(zents: nil, zld: nil)
|
39
|
+
if !zents.nil?
|
40
|
+
raise "Integer is required, while #{zents.class} provided: #{zents}" unless zents.is_a?(Integer)
|
41
|
+
@zents = zents
|
42
42
|
elsif !zld.nil?
|
43
43
|
raise "Float is required, while #{zld.class} provided: #{zld}" unless zld.is_a?(Float)
|
44
|
-
@
|
44
|
+
@zents = (zld * 2**Amount::FRACTION).to_i
|
45
45
|
else
|
46
46
|
raise 'You can\'t specify both coints and zld'
|
47
47
|
end
|
48
|
-
raise "The amount is too big: #{@
|
49
|
-
raise "The amount is too small: #{@
|
48
|
+
raise "The amount is too big: #{@zents}" if @zents > Amount::MAX
|
49
|
+
raise "The amount is too small: #{@zents}" if @zents < -Amount::MAX
|
50
50
|
end
|
51
51
|
|
52
|
-
ZERO = Amount.new(
|
52
|
+
ZERO = Amount.new(zents: 0)
|
53
53
|
|
54
54
|
def to_i
|
55
|
-
@
|
55
|
+
@zents
|
56
56
|
end
|
57
57
|
|
58
58
|
def to_zld(digits = 2)
|
59
|
-
format("%0.#{digits}f", @
|
59
|
+
format("%0.#{digits}f", @zents.to_f / 2**Amount::FRACTION)
|
60
60
|
end
|
61
61
|
|
62
62
|
def to_s
|
@@ -72,61 +72,61 @@ module Zold
|
|
72
72
|
|
73
73
|
def ==(other)
|
74
74
|
raise "== may only work with Amount: #{other}" unless other.is_a?(Amount)
|
75
|
-
@
|
75
|
+
@zents == other.to_i
|
76
76
|
end
|
77
77
|
|
78
78
|
def >(other)
|
79
79
|
raise '> may only work with Amount' unless other.is_a?(Amount)
|
80
|
-
@
|
80
|
+
@zents > other.to_i
|
81
81
|
end
|
82
82
|
|
83
83
|
def <(other)
|
84
84
|
raise '< may only work with Amount' unless other.is_a?(Amount)
|
85
|
-
@
|
85
|
+
@zents < other.to_i
|
86
86
|
end
|
87
87
|
|
88
88
|
def <=(other)
|
89
89
|
raise '<= may only work with Amount' unless other.is_a?(Amount)
|
90
|
-
@
|
90
|
+
@zents <= other.to_i
|
91
91
|
end
|
92
92
|
|
93
93
|
def <=>(other)
|
94
94
|
raise '<= may only work with Amount' unless other.is_a?(Amount)
|
95
|
-
@
|
95
|
+
@zents <=> other.to_i
|
96
96
|
end
|
97
97
|
|
98
98
|
def +(other)
|
99
99
|
raise '+ may only work with Amount' unless other.is_a?(Amount)
|
100
|
-
Amount.new(
|
100
|
+
Amount.new(zents: @zents + other.to_i)
|
101
101
|
end
|
102
102
|
|
103
103
|
def -(other)
|
104
104
|
raise '- may only work with Amount' unless other.is_a?(Amount)
|
105
|
-
Amount.new(
|
105
|
+
Amount.new(zents: @zents - other.to_i)
|
106
106
|
end
|
107
107
|
|
108
108
|
def zero?
|
109
|
-
@
|
109
|
+
@zents.zero?
|
110
110
|
end
|
111
111
|
|
112
112
|
def negative?
|
113
|
-
@
|
113
|
+
@zents.negative?
|
114
114
|
end
|
115
115
|
|
116
116
|
def positive?
|
117
|
-
@
|
117
|
+
@zents.positive?
|
118
118
|
end
|
119
119
|
|
120
120
|
def *(other)
|
121
121
|
raise '* may only work with a number' unless other.is_a?(Integer) || other.is_a?(Float)
|
122
|
-
c = (@
|
123
|
-
raise "Overflow, can't multiply #{@
|
124
|
-
Amount.new(
|
122
|
+
c = (@zents * other).to_i
|
123
|
+
raise "Overflow, can't multiply #{@zents} by #{m}" if c > Amount::MAX
|
124
|
+
Amount.new(zents: c)
|
125
125
|
end
|
126
126
|
|
127
127
|
def /(other)
|
128
128
|
raise '/ may only work with a number' unless other.is_a?(Integer) || other.is_a?(Float)
|
129
|
-
Amount.new(
|
129
|
+
Amount.new(zents: (@zents / other).to_i)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
data/lib/zold/commands/taxes.rb
CHANGED
@@ -114,18 +114,26 @@ Available options:"
|
|
114
114
|
def pay(wallet, opts)
|
115
115
|
raise 'The wallet is absent' unless wallet.exists?
|
116
116
|
tax = Tax.new(wallet)
|
117
|
-
debt = tax.debt
|
117
|
+
debt = total = tax.debt
|
118
118
|
@log.info("The current debt of #{wallet.id}/#{wallet.txns.count}t is #{debt} (#{debt.to_i} zents), \
|
119
119
|
the balance is #{wallet.balance}: #{tax.to_text}")
|
120
120
|
unless tax.in_debt?
|
121
121
|
@log.debug("No need to pay taxes yet, while the debt is less than #{Tax::TRIAL} (#{Tax::TRIAL.to_i} zents)")
|
122
122
|
return
|
123
123
|
end
|
124
|
-
top = top_scores(opts)
|
124
|
+
top = everybody = top_scores(opts)
|
125
|
+
paid = 0
|
125
126
|
while debt > Tax::TRIAL
|
126
127
|
if top.empty?
|
127
|
-
|
128
|
-
|
128
|
+
msg = [
|
129
|
+
"There were #{everybody.count} remote nodes as tax collecting candidates;",
|
130
|
+
"#{paid} payments have been made",
|
131
|
+
"there was not enough score power to pay the total debt of #{total} for #{wallet.id};",
|
132
|
+
"the residual amount to pay is #{debt} (trial amount is #{Tax::TRIAL});",
|
133
|
+
"the formula ingredients are #{tax.to_text}"
|
134
|
+
].join(' ')
|
135
|
+
raise msg unless opts['ignore-nodes-absence']
|
136
|
+
@log.info(msg)
|
129
137
|
break
|
130
138
|
end
|
131
139
|
best = top.shift
|
@@ -135,7 +143,8 @@ the balance is #{wallet.balance}: #{tax.to_text}")
|
|
135
143
|
end
|
136
144
|
txn = tax.pay(Zold::Key.new(file: opts['private-key']), best)
|
137
145
|
debt += txn.amount
|
138
|
-
|
146
|
+
paid += 1
|
147
|
+
@log.info("#{txn.amount} of taxes paid to #{txn.bnf} (payment no.#{paid}), #{debt} left to pay")
|
139
148
|
end
|
140
149
|
@log.info('The wallet is in good standing, all taxes paid') unless tax.in_debt?
|
141
150
|
end
|
@@ -144,6 +153,8 @@ the balance is #{wallet.balance}: #{tax.to_text}")
|
|
144
153
|
raise 'The wallet is absent' unless wallet.exists?
|
145
154
|
tax = Tax.new(wallet)
|
146
155
|
@log.info(tax.debt)
|
156
|
+
@log.debug(tax.to_text)
|
157
|
+
@log.debug('Read the White Paper for more details: https://papers.zold.io/wp.pdf')
|
147
158
|
end
|
148
159
|
|
149
160
|
def show(_, _)
|
data/lib/zold/http.rb
CHANGED
data/lib/zold/node/emission.rb
CHANGED
data/lib/zold/node/front.rb
CHANGED
@@ -31,6 +31,7 @@ require 'diffy'
|
|
31
31
|
require 'usagewatch_ext'
|
32
32
|
require 'concurrent'
|
33
33
|
require 'backtrace'
|
34
|
+
require 'zache'
|
34
35
|
require_relative '../version'
|
35
36
|
require_relative '../size'
|
36
37
|
require_relative '../wallet'
|
@@ -39,7 +40,6 @@ require_relative '../copies'
|
|
39
40
|
require_relative '../log'
|
40
41
|
require_relative '../id'
|
41
42
|
require_relative '../http'
|
42
|
-
require_relative '../cache'
|
43
43
|
|
44
44
|
# The web front of the node.
|
45
45
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -77,7 +77,7 @@ module Zold
|
|
77
77
|
set :remotes, nil? # to be injected at node.rb
|
78
78
|
set :copies, nil? # to be injected at node.rb
|
79
79
|
set :node_alias, nil? # to be injected at node.rb
|
80
|
-
set :
|
80
|
+
set :zache, Zache.new
|
81
81
|
end
|
82
82
|
use Rack::Deflater
|
83
83
|
|
@@ -187,10 +187,10 @@ in #{Age.new(@start, limit: 1)}")
|
|
187
187
|
protocol: settings.protocol,
|
188
188
|
score: score.to_h,
|
189
189
|
pid: Process.pid,
|
190
|
-
cpus: settings.
|
190
|
+
cpus: settings.zache.get(:cpus) { Concurrent.processor_count },
|
191
191
|
memory: GetProcessMem.new.bytes.to_i,
|
192
192
|
platform: RUBY_PLATFORM,
|
193
|
-
load: settings.
|
193
|
+
load: settings.zache.get(:load, lifetime: 5 * 60) { Usagewatch.uw_load.to_f },
|
194
194
|
threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
|
195
195
|
wallets: total_wallets,
|
196
196
|
remotes: all_remotes.count,
|
@@ -435,13 +435,13 @@ in #{Age.new(@start, limit: 1)}")
|
|
435
435
|
end
|
436
436
|
|
437
437
|
def all_remotes
|
438
|
-
settings.
|
438
|
+
settings.zache.get(:remotes, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do
|
439
439
|
settings.remotes.all
|
440
440
|
end
|
441
441
|
end
|
442
442
|
|
443
443
|
def score
|
444
|
-
settings.
|
444
|
+
settings.zache.get(:score, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do
|
445
445
|
b = settings.farm.best
|
446
446
|
raise 'Score is empty, there is something wrong with the Farm!' if b.empty?
|
447
447
|
b[0]
|
data/lib/zold/patch.rb
CHANGED
@@ -84,7 +84,7 @@ module Zold
|
|
84
84
|
balance = @txns.map(&:amount).map(&:to_i).inject(&:+).to_i
|
85
85
|
if balance < txn.amount.to_i * -1 && !wallet.root?
|
86
86
|
@log.error("Transaction ##{txn.id} attempts to make the balance of \
|
87
|
-
#{wallet.id}/#{Amount.new(
|
87
|
+
#{wallet.id}/#{Amount.new(zents: balance).to_zld}/#{@txns.size} negative: #{txn.to_text}")
|
88
88
|
next
|
89
89
|
end
|
90
90
|
unless Signature.new.valid?(@key, wallet.id, txn)
|
data/lib/zold/tax.rb
CHANGED
@@ -45,7 +45,9 @@ module Zold
|
|
45
45
|
# This is how much we charge per one transaction per hour
|
46
46
|
# of storage. A wallet of 4096 transactions will pay
|
47
47
|
# approximately 16ZLD per year.
|
48
|
-
|
48
|
+
# Here is the formula: 16.0 / (365 * 24) / 4096 = 1915
|
49
|
+
# But I like the 1917 number better.
|
50
|
+
FEE = Amount.new(zents: 1917)
|
49
51
|
|
50
52
|
# The maximum debt we can tolerate at the wallet. If the debt
|
51
53
|
# is bigger than this threshold, nodes must stop accepting PUSH.
|
@@ -77,10 +79,14 @@ module Zold
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def to_text
|
80
|
-
"A=#{@wallet.age}, F=#{Tax::
|
82
|
+
"A=#{@wallet.age.round} hours, F=#{Tax::FEE.to_i}z/th, T=#{@wallet.txns.count}t, Paid=#{paid}"
|
81
83
|
end
|
82
84
|
|
83
85
|
def debt
|
86
|
+
Tax::FEE * @wallet.txns.count * @wallet.age - paid
|
87
|
+
end
|
88
|
+
|
89
|
+
def paid
|
84
90
|
txns = @wallet.txns
|
85
91
|
scored = txns.map do |t|
|
86
92
|
pfx, body = t.details.split(' ', 2)
|
@@ -91,9 +97,7 @@ module Zold
|
|
91
97
|
next if t.amount > Tax::MAX_PAYMENT
|
92
98
|
t
|
93
99
|
end.compact.uniq(&:details)
|
94
|
-
|
95
|
-
owned = Tax::FEE_TXN_HOUR * txns.count * @wallet.age
|
96
|
-
owned - paid
|
100
|
+
scored.empty? ? Amount::ZERO : scored.map(&:amount).inject(&:+)
|
97
101
|
end
|
98
102
|
end
|
99
103
|
end
|
data/lib/zold/txn.rb
CHANGED
@@ -133,7 +133,7 @@ module Zold
|
|
133
133
|
txn = Txn.new(
|
134
134
|
Hexnum.parse(parts[:id]).to_i,
|
135
135
|
Time.parse(parts[:date]),
|
136
|
-
Amount.new(
|
136
|
+
Amount.new(zents: Hexnum.parse(parts[:amount]).to_i),
|
137
137
|
parts[:prefix],
|
138
138
|
Id.new(parts[:bnf]),
|
139
139
|
parts[:details]
|
data/lib/zold/version.rb
CHANGED
data/test/node/test_front.rb
CHANGED
@@ -326,7 +326,7 @@ class FrontTest < Minitest::Test
|
|
326
326
|
assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.code }
|
327
327
|
cycles = 50
|
328
328
|
cycles.times do
|
329
|
-
wallet.sub(Zold::Amount.new(
|
329
|
+
wallet.sub(Zold::Amount.new(zents: 10), "NOPREFIX@#{Zold::Id.new}", key)
|
330
330
|
Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
|
331
331
|
assert_equal('200', Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.code)
|
332
332
|
end
|
data/test/test_amount.rb
CHANGED
@@ -52,8 +52,8 @@ class TestAmount < Minitest::Test
|
|
52
52
|
assert(amount != Zold::Amount::ZERO)
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
56
|
-
amount = Zold::Amount.new(
|
55
|
+
def test_parses_zents
|
56
|
+
amount = Zold::Amount.new(zents: 900_000_000)
|
57
57
|
assert(
|
58
58
|
amount.to_s.include?('0.21ZLD'),
|
59
59
|
"#{amount} is not equal to '0.21ZLD'"
|
@@ -61,7 +61,7 @@ class TestAmount < Minitest::Test
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_compares_amounts
|
64
|
-
amount = Zold::Amount.new(
|
64
|
+
amount = Zold::Amount.new(zents: 700_000_000)
|
65
65
|
assert(
|
66
66
|
amount > Zold::Amount::ZERO,
|
67
67
|
"#{amount} is not greater than zero"
|
data/test/test_tax.rb
CHANGED
@@ -39,23 +39,23 @@ require_relative '../lib/zold/score'
|
|
39
39
|
# License:: MIT
|
40
40
|
class TestTax < Minitest::Test
|
41
41
|
def test_print_fee
|
42
|
-
test_log.info("Fee in zents: #{Zold::Tax::
|
42
|
+
test_log.info("Fee in zents: #{Zold::Tax::FEE.to_i}")
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_calculates_tax_for_one_year
|
46
46
|
FakeHome.new(log: test_log).run do |home|
|
47
47
|
wallet = home.create_wallet
|
48
|
+
a = 10_000
|
48
49
|
wallet.add(
|
49
50
|
Zold::Txn.new(
|
50
51
|
1,
|
51
|
-
Time.now -
|
52
|
+
Time.now - a * 60 * 60,
|
52
53
|
Zold::Amount.new(zld: 19.99),
|
53
54
|
'NOPREFIX', Zold::Id.new, '-'
|
54
55
|
)
|
55
56
|
)
|
56
57
|
tax = Zold::Tax.new(wallet)
|
57
|
-
|
58
|
-
assert(tax.debt < Zold::Amount.new(coins: 16_790_000))
|
58
|
+
assert_equal(Zold::Tax::FEE * a, tax.debt, tax.to_text)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -97,7 +97,7 @@ class TestTax < Minitest::Test
|
|
97
97
|
Zold::Txn.new(
|
98
98
|
1,
|
99
99
|
Time.now,
|
100
|
-
Zold::Amount.new(
|
100
|
+
Zold::Amount.new(zents: 95_596_800),
|
101
101
|
'NOPREFIX', Zold::Id.new('912ecc24b32dbe74'),
|
102
102
|
"TAXES 6 5b5a21a9 b2.zold.io 1000 DCexx0hG 912ecc24b32dbe74 \
|
103
103
|
386d4a ec9eae 306e3d 119d073 1c00dba 1376703 203589 5b55f7"
|
data/test/test_wallet.rb
CHANGED
@@ -132,10 +132,10 @@ class TestWallet < Minitest::Test
|
|
132
132
|
wallet = home.create_wallet
|
133
133
|
time = Time.now
|
134
134
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
135
|
-
wallet.add(Zold::Txn.new(1, time, Zold::Amount.new(
|
136
|
-
wallet.sub(Zold::Amount.new(
|
137
|
-
wallet.add(Zold::Txn.new(2, time, Zold::Amount.new(
|
138
|
-
wallet.sub(Zold::Amount.new(
|
135
|
+
wallet.add(Zold::Txn.new(1, time, Zold::Amount.new(zents: 1), 'NOPREFIX', Zold::Id.new, '-'))
|
136
|
+
wallet.sub(Zold::Amount.new(zents: 2), "NOPREFIX@#{Zold::Id.new}", key, time: time)
|
137
|
+
wallet.add(Zold::Txn.new(2, time, Zold::Amount.new(zents: 3), 'NOPREFIX', Zold::Id.new, '-'))
|
138
|
+
wallet.sub(Zold::Amount.new(zents: 4), "NOPREFIX@#{Zold::Id.new}", key, time: time)
|
139
139
|
assert_equal('3, 1, -2, -4', wallet.txns.map(&:amount).map(&:to_i).join(', '))
|
140
140
|
end
|
141
141
|
end
|
@@ -219,7 +219,7 @@ class TestWallet < Minitest::Test
|
|
219
219
|
sum += t.amount
|
220
220
|
end
|
221
221
|
assert(
|
222
|
-
sum == Zold::Amount.new(
|
222
|
+
sum == Zold::Amount.new(zents: 235_965_503_242),
|
223
223
|
"#{sum} (#{sum.to_i}) is not equal to #{Zold::Amount.new(zld: 54.94)}"
|
224
224
|
)
|
225
225
|
end
|
data/test/test_zold.rb
CHANGED
@@ -35,6 +35,8 @@ class TestZold < Minitest::Test
|
|
35
35
|
def test_all_scripts
|
36
36
|
Dir.new('fixtures/scripts').select { |f| f =~ /\.sh$/ && !f.start_with?('_') }.each do |f|
|
37
37
|
# next unless f == 'push-and-pull.sh'
|
38
|
+
start = Time.now
|
39
|
+
test_log.debug("\n\n#{f} running...")
|
38
40
|
Dir.mktmpdir do |dir|
|
39
41
|
FileUtils.cp('fixtures/id_rsa.pub', dir)
|
40
42
|
FileUtils.cp('fixtures/id_rsa', dir)
|
@@ -55,6 +57,7 @@ class TestZold < Minitest::Test
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
60
|
+
test_log.debug("\n\n#{f} done in #{Zold::Age.new(start)}")
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
data/zold.gemspec
CHANGED
@@ -68,7 +68,6 @@ and suggests a different architecture for digital wallet maintenance.'
|
|
68
68
|
s.add_runtime_dependency 'rubocop', '0.58.1' # has to stay here for Heroku
|
69
69
|
s.add_runtime_dependency 'rubocop-rspec', '~>1' # has to stay here for Heroku
|
70
70
|
s.add_runtime_dependency 'semantic', '~>1'
|
71
|
-
s.add_runtime_dependency 'sigdump', '~>0'
|
72
71
|
s.add_runtime_dependency 'sinatra', '~>2'
|
73
72
|
s.add_runtime_dependency 'slop', '~>4'
|
74
73
|
s.add_runtime_dependency 'sys-proctable', '~>1'
|
@@ -76,6 +75,7 @@ and suggests a different architecture for digital wallet maintenance.'
|
|
76
75
|
s.add_runtime_dependency 'threads', '~>0'
|
77
76
|
s.add_runtime_dependency 'usagewatch_ext', '~>0'
|
78
77
|
s.add_runtime_dependency 'xcop', '~>0'
|
78
|
+
s.add_runtime_dependency 'zache', '~>0'
|
79
79
|
s.add_development_dependency 'codecov', '~>0'
|
80
80
|
s.add_development_dependency 'minitest', '~>5'
|
81
81
|
s.add_development_dependency 'random-port', '~>0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|
@@ -206,20 +206,6 @@ dependencies:
|
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '1'
|
209
|
-
- !ruby/object:Gem::Dependency
|
210
|
-
name: sigdump
|
211
|
-
requirement: !ruby/object:Gem::Requirement
|
212
|
-
requirements:
|
213
|
-
- - "~>"
|
214
|
-
- !ruby/object:Gem::Version
|
215
|
-
version: '0'
|
216
|
-
type: :runtime
|
217
|
-
prerelease: false
|
218
|
-
version_requirements: !ruby/object:Gem::Requirement
|
219
|
-
requirements:
|
220
|
-
- - "~>"
|
221
|
-
- !ruby/object:Gem::Version
|
222
|
-
version: '0'
|
223
209
|
- !ruby/object:Gem::Dependency
|
224
210
|
name: sinatra
|
225
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -318,6 +304,20 @@ dependencies:
|
|
318
304
|
- - "~>"
|
319
305
|
- !ruby/object:Gem::Version
|
320
306
|
version: '0'
|
307
|
+
- !ruby/object:Gem::Dependency
|
308
|
+
name: zache
|
309
|
+
requirement: !ruby/object:Gem::Requirement
|
310
|
+
requirements:
|
311
|
+
- - "~>"
|
312
|
+
- !ruby/object:Gem::Version
|
313
|
+
version: '0'
|
314
|
+
type: :runtime
|
315
|
+
prerelease: false
|
316
|
+
version_requirements: !ruby/object:Gem::Requirement
|
317
|
+
requirements:
|
318
|
+
- - "~>"
|
319
|
+
- !ruby/object:Gem::Version
|
320
|
+
version: '0'
|
321
321
|
- !ruby/object:Gem::Dependency
|
322
322
|
name: codecov
|
323
323
|
requirement: !ruby/object:Gem::Requirement
|
@@ -482,13 +482,11 @@ files:
|
|
482
482
|
- fixtures/scripts/pull-on-start.sh
|
483
483
|
- fixtures/scripts/push-and-pull.sh
|
484
484
|
- fixtures/scripts/redeploy-on-upgrade.sh
|
485
|
-
- fixtures/scripts/sigdump.sh
|
486
485
|
- fixtures/scripts/spread-wallets.sh
|
487
486
|
- heroku-run.sh
|
488
487
|
- lib/zold.rb
|
489
488
|
- lib/zold/age.rb
|
490
489
|
- lib/zold/amount.rb
|
491
|
-
- lib/zold/cache.rb
|
492
490
|
- lib/zold/cached_wallets.rb
|
493
491
|
- lib/zold/commands/alias.rb
|
494
492
|
- lib/zold/commands/args.rb
|
@@ -590,7 +588,6 @@ files:
|
|
590
588
|
- test/test__helper.rb
|
591
589
|
- test/test_age.rb
|
592
590
|
- test/test_amount.rb
|
593
|
-
- test/test_cache.rb
|
594
591
|
- test/test_cached_wallets.rb
|
595
592
|
- test/test_copies.rb
|
596
593
|
- test/test_dir_items.rb
|
@@ -691,7 +688,6 @@ test_files:
|
|
691
688
|
- test/test__helper.rb
|
692
689
|
- test/test_age.rb
|
693
690
|
- test/test_amount.rb
|
694
|
-
- test/test_cache.rb
|
695
691
|
- test/test_cached_wallets.rb
|
696
692
|
- test/test_copies.rb
|
697
693
|
- test/test_dir_items.rb
|
data/fixtures/scripts/sigdump.sh
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
port=$(reserve_port)
|
4
|
-
|
5
|
-
zold node --trace --invoice=NOPREFIX@ffffffffffffffff \
|
6
|
-
--host=localhost --port=${port} --bind-port=${port} \
|
7
|
-
--threads=0 --standalone &
|
8
|
-
pid=$!
|
9
|
-
trap "halt_nodes ${port}" EXIT
|
10
|
-
|
11
|
-
wait_for_port ${port}
|
12
|
-
|
13
|
-
kill -CONT ${pid}
|
14
|
-
|
15
|
-
wait_for_file sigdump-${pid}.log
|
data/lib/zold/cache.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (c) 2018 Yegor Bugayenko
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
22
|
-
|
23
|
-
# Cache.
|
24
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
25
|
-
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
26
|
-
# License:: MIT
|
27
|
-
module Zold
|
28
|
-
# Cache
|
29
|
-
class Cache
|
30
|
-
def initialize
|
31
|
-
@hash = {}
|
32
|
-
@mutex = Mutex.new
|
33
|
-
end
|
34
|
-
|
35
|
-
def get(key, lifetime: 60 * 60)
|
36
|
-
@mutex.synchronize do
|
37
|
-
rec = @hash[key]
|
38
|
-
rec = nil if !rec.nil? && rec[:start] < Time.now - rec[:lifetime]
|
39
|
-
if rec.nil?
|
40
|
-
@hash[key] = {
|
41
|
-
value: yield,
|
42
|
-
start: Time.now,
|
43
|
-
lifetime: lifetime
|
44
|
-
}
|
45
|
-
end
|
46
|
-
@hash[key][:value]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/test/test_cache.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright (c) 2018 Yegor Bugayenko
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
22
|
-
|
23
|
-
require 'minitest/autorun'
|
24
|
-
require 'threads'
|
25
|
-
require_relative '../lib/zold/cache'
|
26
|
-
|
27
|
-
# Cache test.
|
28
|
-
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
30
|
-
# License:: MIT
|
31
|
-
class TestCache < Minitest::Test
|
32
|
-
def test_caches
|
33
|
-
cache = Zold::Cache.new
|
34
|
-
first = cache.get(:hey, lifetime: 5) { Random.rand }
|
35
|
-
second = cache.get(:hey) { Random.rand }
|
36
|
-
assert(first == second)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_caches_and_expires
|
40
|
-
cache = Zold::Cache.new
|
41
|
-
first = cache.get(:hey, lifetime: 0.01) { Random.rand }
|
42
|
-
sleep 0.1
|
43
|
-
second = cache.get(:hey) { Random.rand }
|
44
|
-
assert(first != second)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_caches_in_threads
|
48
|
-
cache = Zold::Cache.new
|
49
|
-
Threads.new(10).assert(100) do
|
50
|
-
cache.get(:hey, lifetime: 0.0001) { Random.rand }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|