zold 0.16.6 → 0.16.7

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: 7190b0b8462533e8c4bd5f97663d78c7b96a2da53d5676c744f6157f99864d1b
4
- data.tar.gz: 1aa4b614367a48e79cf6ad83fab9018910f4ba09813ea5f2a8e463241d3fddf1
3
+ metadata.gz: a325af91de87bc2bd544f5d92a908eff34f4f114a88fa4cb9248ef286bff9404
4
+ data.tar.gz: 6e4fd9790fdcf55a23c206e60635c8fe6d45ad83eee4194697989b1f6bf5e51f
5
5
  SHA512:
6
- metadata.gz: b74b9b9ac60a0abcb280c81eead4ff9b15fa3b139c7973bf80f4f586bbf15feffbf8c085d9b99e8522febb756ab8014702de294e051817a6a41eb274756ac019
7
- data.tar.gz: 70f498e4469e72e94d881c7692aa6b7166e76aade1d4b50e60fca1358c859ec65da90af4d57630ef24de009d21eb3540edf5ca1da6694d1a5903480e2e53f1f0
6
+ metadata.gz: e827fbbefda31c28ad0fe24f23d5694d94997123f5163080a38ca8eee92c2048d4a0245b640896dab6210da8d2f22ac6dc325e3efe962b76cf3a714608534abe
7
+ data.tar.gz: 41ab159b3f635916fbb289384796e2fe5000aba409e86180248ec2903c684c86bd42642b357dd6e6d34b65b903df6648b4eda4938683cc9850880e3aaac0230a
@@ -177,8 +177,8 @@ Available options:"
177
177
  return
178
178
  end
179
179
  unless opts['skip-ping']
180
- res = Http.new(uri: "http://#{host}:#{port}/version", score: nil, network: opts['network']).get
181
- raise "The node #{host}:#{port} is not responding (code is #{res.code})" unless res.code == '200'
180
+ res = Http.new(uri: "http://#{host}:#{port}/version", network: opts['network']).get
181
+ raise "The node #{host}:#{port} is not responding, #{res.code}:#{res.message}" unless res.code == '200'
182
182
  end
183
183
  @remotes.add(host, port)
184
184
  @log.info("#{host}:#{port} added to the list, #{@remotes.all.count} total")
@@ -115,7 +115,8 @@ Available options:"
115
115
  raise 'The wallet is absent' unless wallet.exists?
116
116
  tax = Tax.new(wallet)
117
117
  debt = tax.debt
118
- @log.info("The current debt of #{wallet.id}/#{wallet.txns.count}t is #{debt} (#{debt.to_i} zents)")
118
+ @log.info("The current debt of #{wallet.id}/#{wallet.txns.count}t is #{debt} (#{debt.to_i} zents), \
119
+ the balance is #{wallet.balance}: #{tax.to_text}")
119
120
  unless tax.in_debt?
120
121
  @log.debug("No need to pay taxes yet, while the debt is less than #{Tax::TRIAL} (#{Tax::TRIAL.to_i} zents)")
121
122
  return
@@ -160,7 +161,7 @@ Available options:"
160
161
  r.assert_valid_score(score)
161
162
  r.assert_score_strength(score) unless opts['ignore-score-weakness']
162
163
  r.assert_score_value(score, Tax::EXACT_SCORE)
163
- @log.info("#{r}: #{Rainbow(score.value).green}")
164
+ @log.info("#{r}: #{Rainbow(score.value).green} to #{score.invoice}")
164
165
  best << score
165
166
  end
166
167
  best.sort_by(&:value).reverse
data/lib/zold/http.rb CHANGED
@@ -26,7 +26,7 @@ require 'timeout'
26
26
  require 'net/http'
27
27
  require 'backtrace'
28
28
  require_relative 'version'
29
- require_relative 'type'
29
+ require_relative 'score'
30
30
 
31
31
  # HTTP page.
32
32
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -34,7 +34,7 @@ require_relative 'type'
34
34
  # License:: MIT
35
35
  module Zold
36
36
  # Http page
37
- class Http < Dry::Struct
37
+ class Http
38
38
  # HTTP header we add to each HTTP request, in order to inform
39
39
  # the other node about the score. If the score is big enough,
40
40
  # the remote node will add us to its list of remote nodes.
@@ -60,23 +60,19 @@ module Zold
60
60
  # Connect timeout in seconds
61
61
  CONNECT_TIMEOUT = 4
62
62
 
63
- # @todo #98:30m/DEV The following two statements are seen as issues by rubocop
64
- # raising a Lint/AmbiguousBlockAssociation offense. It is somthing
65
- # that could be solved by changing the TargetRubyVersion in .rubocop.yml
66
- # that is already taken care of in another issue. I am leaving a todo
67
- # to check that rubocop doesn't complain anymore, otherwise find another
68
- # solution
69
- attribute :uri, (Types::Class.constructor { |v| v.is_a?(URI) ? v : URI(v) })
70
- attribute :score, (Types::Class.constructor { |v| v.nil? ? Score::ZERO : v })
71
- attribute :network, Types::Strict::String.optional.default('test')
63
+ def initialize(uri:, score: Score::ZERO, network: 'test')
64
+ @uri = uri.is_a?(URI) ? uri : URI(uri)
65
+ @score = score
66
+ @network = network
67
+ end
72
68
 
73
69
  def get
74
- http = Net::HTTP.new(uri.host, uri.port)
75
- http.use_ssl = uri.scheme == 'https'
70
+ http = Net::HTTP.new(@uri.host, @uri.port)
71
+ http.use_ssl = @uri.scheme == 'https'
76
72
  http.read_timeout = Http::READ_TIMEOUT
77
73
  http.open_timeout = Http::CONNECT_TIMEOUT
78
- path = uri.path
79
- path += '?' + uri.query if uri.query
74
+ path = @uri.path
75
+ path += '?' + @uri.query if @uri.query
80
76
  Timeout.timeout(Http::READ_TIMEOUT + Http::CONNECT_TIMEOUT) do
81
77
  http.request_get(path, headers)
82
78
  end
@@ -85,12 +81,12 @@ module Zold
85
81
  end
86
82
 
87
83
  def put(body)
88
- http = Net::HTTP.new(uri.host, uri.port)
89
- http.use_ssl = uri.scheme == 'https'
84
+ http = Net::HTTP.new(@uri.host, @uri.port)
85
+ http.use_ssl = @uri.scheme == 'https'
90
86
  http.read_timeout = Http::READ_TIMEOUT
91
87
  http.open_timeout = Http::CONNECT_TIMEOUT
92
- path = uri.path
93
- path += '?' + uri.query if uri.query
88
+ path = @uri.path
89
+ path += '?' + @uri.query if @uri.query
94
90
  Timeout.timeout(Http::READ_TIMEOUT + Http::CONNECT_TIMEOUT) do
95
91
  http.request_put(
96
92
  path, body,
@@ -141,8 +137,8 @@ module Zold
141
137
  }
142
138
  headers[Http::VERSION_HEADER] = Zold::VERSION
143
139
  headers[Http::PROTOCOL_HEADER] = Zold::PROTOCOL.to_s
144
- headers[Http::NETWORK_HEADER] = network
145
- headers[Http::SCORE_HEADER] = score.reduced(4).to_text if score.valid? && !score.expired? && score.value > 3
140
+ headers[Http::NETWORK_HEADER] = @network
141
+ headers[Http::SCORE_HEADER] = @score.reduced(4).to_text if @score.valid? && !@score.expired? && @score.value > 3
146
142
  headers
147
143
  end
148
144
  end
@@ -100,9 +100,7 @@ while #{settings.address} is in '#{settings.network}'")
100
100
  end
101
101
  end
102
102
  check_header(Http::SCORE_HEADER) do |header|
103
- if settings.remotes.all.empty?
104
- settings.log.debug("#{request.url}: we are in standalone mode, won't update remotes")
105
- end
103
+ settings.log.debug("#{request.url}: we are in standalone mode, won't update remotes") if all_remotes.empty?
106
104
  s = Score.parse_text(header)
107
105
  error(400, 'The score is invalid') unless s.valid?
108
106
  error(400, 'The score is weak') if s.strength < Score::STRENGTH && !settings.ignore_score_weakness
@@ -195,8 +193,8 @@ in #{Age.new(@start, limit: 1)}")
195
193
  load: settings.cache.get(:load, lifetime: 5 * 60) { Usagewatch.uw_load.to_f },
196
194
  threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
197
195
  wallets: total_wallets,
198
- remotes: settings.remotes.all.count,
199
- nscore: settings.remotes.all.map { |r| r[:score] }.inject(&:+) || 0,
196
+ remotes: all_remotes.count,
197
+ nscore: all_remotes.map { |r| r[:score] }.inject(&:+) || 0,
200
198
  farm: settings.farm.to_json,
201
199
  entrance: settings.entrance.to_json,
202
200
  date: Time.now.utc.iso8601,
@@ -368,7 +366,7 @@ in #{Age.new(@start, limit: 1)}")
368
366
  version: settings.version,
369
367
  alias: settings.node_alias,
370
368
  score: score.to_h,
371
- all: settings.remotes.all,
369
+ all: all_remotes,
372
370
  mtime: settings.remotes.mtime.utc.iso8601
373
371
  )
374
372
  end
@@ -436,8 +434,14 @@ in #{Age.new(@start, limit: 1)}")
436
434
  settings.wallets.all.count
437
435
  end
438
436
 
437
+ def all_remotes
438
+ settings.cache.get(:remotes, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do
439
+ settings.remotes.all
440
+ end
441
+ end
442
+
439
443
  def score
440
- settings.cache.get(:score, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 1) do
444
+ settings.cache.get(:score, lifetime: settings.network == Wallet::MAIN_NETWORK ? 60 : 0) do
441
445
  b = settings.farm.best
442
446
  raise 'Score is empty, there is something wrong with the Farm!' if b.empty?
443
447
  b[0]
data/lib/zold/remotes.rb CHANGED
@@ -32,7 +32,6 @@ require_relative 'age'
32
32
  require_relative 'score'
33
33
  require_relative 'http'
34
34
  require_relative 'node/farm'
35
- require_relative 'type'
36
35
 
37
36
  # The list of remotes.
38
37
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -40,7 +39,7 @@ require_relative 'type'
40
39
  # License:: MIT
41
40
  module Zold
42
41
  # All remotes
43
- class Remotes < Dry::Struct
42
+ class Remotes
44
43
  # The default TCP port all nodes are supposed to use.
45
44
  PORT = 4096
46
45
 
@@ -50,9 +49,8 @@ module Zold
50
49
  # Default number of nodes to fetch.
51
50
  MAX_NODES = 16
52
51
 
53
- attribute :file, Types::Strict::String
54
- attribute :network, Types::Strict::String.optional.default('test')
55
- attribute :timeout, Types::Strict::Integer.optional.default(16)
52
+ # Default nodes and their ports
53
+ DEFS = CSV.read(File.expand_path(File.join(File.dirname(__FILE__), '../../resources/remotes')))
56
54
 
57
55
  # Empty, for standalone mode
58
56
  class Empty
@@ -74,22 +72,22 @@ module Zold
74
72
  end
75
73
 
76
74
  # One remote.
77
- class Remote < Dry::Struct
78
- attribute :host, Types::Strict::String
79
- attribute :port, Types::Strict::Integer.constrained(gteq: 0, lt: 65_535)
80
- attribute :score, Score
81
- attribute :idx, Types::Strict::Integer
82
- attribute :network, Types::Strict::String.optional.default('test')
83
- attribute :log, (Types::Class.constructor do |value|
84
- value.nil? ? Log::Quiet.new : value
85
- end)
75
+ class Remote
76
+ def initialize(host:, port:, score:, idx:, network: 'test', log: Log::Quiet.new)
77
+ @host = host
78
+ @port = port
79
+ @score = score
80
+ @idx = idx
81
+ @network = network
82
+ @log = log
83
+ end
86
84
 
87
85
  def http(path = '/')
88
- Http.new(uri: "http://#{host}:#{port}#{path}", score: score, network: network)
86
+ Http.new(uri: "http://#{@host}:#{@port}#{path}", score: @score, network: @network)
89
87
  end
90
88
 
91
89
  def to_s
92
- "#{host}:#{port}/#{idx}"
90
+ "#{@host}:#{@port}/#{@idx}"
93
91
  end
94
92
 
95
93
  def assert_code(code, response)
@@ -108,8 +106,8 @@ module Zold
108
106
  end
109
107
 
110
108
  def assert_score_ownership(score)
111
- raise "Masqueraded host #{host} as #{score.host}: #{score}" if host != score.host
112
- raise "Masqueraded port #{port} as #{score.port}: #{score}" if port != score.port
109
+ raise "Masqueraded host #{@host} as #{score.host}: #{score}" if @host != score.host
110
+ raise "Masqueraded port #{@port} as #{score.port}: #{score}" if @port != score.port
113
111
  end
114
112
 
115
113
  def assert_score_strength(score)
@@ -121,6 +119,12 @@ module Zold
121
119
  end
122
120
  end
123
121
 
122
+ def initialize(file:, network: 'test', timeout: 16)
123
+ @file = file
124
+ @network = network
125
+ @timeout = timeout
126
+ end
127
+
124
128
  def all
125
129
  list = load
126
130
  max_score = list.map { |r| r[:score] }.max || 0
@@ -137,9 +141,8 @@ module Zold
137
141
  end
138
142
 
139
143
  def defaults
140
- other = Remotes.new(file: File.expand_path(File.join(File.dirname(__FILE__), '../../resources/remotes')))
141
- other.all.each do |r|
142
- add(r[:host], r[:port])
144
+ Remotes::DEFS.each do |r|
145
+ add(r[0], r[1].to_i)
143
146
  end
144
147
  end
145
148
 
@@ -194,12 +197,12 @@ module Zold
194
197
  score: score,
195
198
  idx: idx,
196
199
  log: log,
197
- network: network
200
+ network: @network
198
201
  )
199
- raise 'Took too long to execute' if (Time.now - start).round > timeout
202
+ raise 'Took too long to execute' if (Time.now - start).round > @timeout
200
203
  rescue StandardError => e
201
204
  error(r[:host], r[:port])
202
- log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: #{e.message} in #{Age.new(start)}")
205
+ log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: \"#{e.message}\" in #{Age.new(start)}")
203
206
  log.debug(Backtrace.new(e).to_s)
204
207
  remove(r[:host], r[:port]) if errors > Remotes::TOLERANCE
205
208
  end
@@ -226,13 +229,17 @@ module Zold
226
229
  end
227
230
 
228
231
  def mtime
229
- File.exist?(file) ? File.mtime(file) : Time.now
232
+ File.exist?(@file) ? File.mtime(@file) : Time.now
233
+ end
234
+
235
+ def default?(host, port)
236
+ !Remotes::DEFS.find { |r| r[0] == host && r[1].to_i == port }.nil?
230
237
  end
231
238
 
232
239
  private
233
240
 
234
241
  def modify
235
- Futex.new(file).open do
242
+ Futex.new(@file).open do
236
243
  save(yield(load))
237
244
  end
238
245
  end
@@ -247,13 +254,14 @@ module Zold
247
254
  end
248
255
 
249
256
  def load
250
- if File.exist?(file)
251
- raw = CSV.read(file).map do |row|
257
+ if File.exist?(@file)
258
+ raw = CSV.read(@file).map do |row|
252
259
  {
253
260
  host: row[0],
254
261
  port: row[1].to_i,
255
262
  score: row[2].to_i,
256
- errors: row[3].to_i
263
+ errors: row[3].to_i,
264
+ default: default?(row[0], row[1].to_i)
257
265
  }
258
266
  end
259
267
  raw.reject { |r| !r[:host] || r[:port].zero? }.map do |r|
@@ -266,9 +274,9 @@ module Zold
266
274
  end
267
275
 
268
276
  def save(list)
269
- FileUtils.mkdir_p(File.dirname(file))
277
+ FileUtils.mkdir_p(File.dirname(@file))
270
278
  IO.write(
271
- file,
279
+ @file,
272
280
  list.uniq { |r| "#{r[:host]}:#{r[:port]}" }.map do |r|
273
281
  [
274
282
  r[:host],
data/lib/zold/score.rb CHANGED
@@ -22,7 +22,6 @@
22
22
 
23
23
  require 'openssl'
24
24
  require 'time'
25
- require_relative 'type'
26
25
 
27
26
  # The score.
28
27
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -30,21 +29,22 @@ require_relative 'type'
30
29
  # License:: MIT
31
30
  module Zold
32
31
  # Score
33
- class Score < Dry::Struct
32
+ class Score
34
33
  # Default strength for the entire system, in production mode.
35
34
  STRENGTH = 6
36
35
 
37
- attribute :time, Types::Strict::Time.optional.default(Time.now)
38
- attribute :host, Types::Strict::String.constrained(
39
- format: /^[a-z0-9\.-]+$/
40
- )
41
- attribute :port, Types::Strict::Integer.constrained(gteq: 0, lt: 65_535)
42
- attribute :invoice, Types::Strict::String.constrained(
43
- format: /^[a-zA-Z0-9]{8,32}@[a-f0-9]{16}$/
44
- )
45
- attribute :suffixes, Types::Strict::Array.optional.default([])
46
- attribute :strength, Types::Strict::Integer.optional.default(STRENGTH)
47
- attribute :created, Types::Strict::Time.optional.default(Time.now)
36
+ attr_reader :time, :host, :port, :invoice, :suffixes, :strength, :created
37
+
38
+ def initialize(time: Time.now, host:, port:, invoice:, suffixes: [],
39
+ strength: Score::STRENGTH, created: Time.now)
40
+ @time = time
41
+ @host = host
42
+ @port = port
43
+ @invoice = invoice
44
+ @suffixes = suffixes
45
+ @strength = strength
46
+ @created = created
47
+ end
48
48
 
49
49
  # The default no-value score.
50
50
  ZERO = Score.new(time: Time.now, host: 'localhost', port: 80, invoice: 'NOPREFIX@ffffffffffffffff')
@@ -96,61 +96,62 @@ module Zold
96
96
  end
97
97
 
98
98
  def hash
99
- raise 'Score has zero value, there is no hash' if suffixes.empty?
100
- suffixes.reduce(prefix) do |pfx, suffix|
99
+ raise 'Score has zero value, there is no hash' if @suffixes.empty?
100
+ @suffixes.reduce(prefix) do |pfx, suffix|
101
101
  OpenSSL::Digest::SHA256.new("#{pfx} #{suffix}").hexdigest
102
102
  end
103
103
  end
104
104
 
105
105
  def to_mnemo
106
- "#{value}:#{time.strftime('%H%M')}"
106
+ "#{value}:#{@time.strftime('%H%M')}"
107
107
  end
108
108
 
109
109
  def to_text
110
- pfx, bnf = invoice.split('@')
110
+ pfx, bnf = @invoice.split('@')
111
111
  [
112
- strength,
113
- time.to_i.to_s(16),
114
- host,
115
- port.to_s(16),
112
+ @strength,
113
+ @time.to_i.to_s(16),
114
+ @host,
115
+ @port.to_s(16),
116
116
  pfx,
117
117
  bnf,
118
- suffixes.join(' ')
118
+ @suffixes.join(' ')
119
119
  ].join(' ')
120
120
  end
121
121
 
122
122
  def to_s
123
123
  [
124
- "#{value}/#{strength}:",
125
- time.utc.iso8601,
126
- host,
127
- port,
128
- invoice,
129
- suffixes.join(' ')
124
+ "#{value}/#{@strength}:",
125
+ @time.utc.iso8601,
126
+ @host,
127
+ @port,
128
+ @invoice,
129
+ @suffixes.join(' ')
130
130
  ].join(' ').strip
131
131
  end
132
132
 
133
133
  def to_h
134
134
  {
135
135
  value: value,
136
- host: host,
137
- port: port,
138
- invoice: invoice,
139
- time: time.utc.iso8601,
140
- suffixes: suffixes,
141
- strength: strength,
136
+ host: @host,
137
+ port: @port,
138
+ invoice: @invoice,
139
+ time: @time.utc.iso8601,
140
+ suffixes: @suffixes,
141
+ strength: @strength,
142
142
  hash: value.zero? ? nil : hash,
143
143
  expired: expired?,
144
144
  valid: valid?,
145
145
  age: (age / 60).round,
146
- created: created.utc.iso8601
146
+ created: @created.utc.iso8601
147
147
  }
148
148
  end
149
149
 
150
150
  def reduced(max = 4)
151
151
  Score.new(
152
- time: time, host: host, port: port, invoice: invoice,
153
- suffixes: suffixes[0..[max, suffixes.count].min - 1], strength: strength, created: nil
152
+ time: @time, host: @host, port: @port, invoice: @invoice,
153
+ suffixes: @suffixes[0..[max, suffixes.count].min - 1],
154
+ strength: @strength
154
155
  )
155
156
  end
156
157
 
@@ -160,14 +161,15 @@ module Zold
160
161
  loop do
161
162
  suffix = idx.to_s(16)
162
163
  score = Score.new(
163
- time: time, host: host, port: port, invoice: invoice, suffixes: suffixes + [suffix],
164
- strength: strength
164
+ time: @time, host: @host, port: @port,
165
+ invoice: @invoice, suffixes: @suffixes + [suffix],
166
+ strength: @strength
165
167
  )
166
168
  return score if score.valid?
167
169
  if score.expired?
168
170
  return Score.new(
169
- time: Time.now, host: host, port: port, invoice: invoice,
170
- suffixes: [], strength: strength
171
+ time: Time.now, host: @host, port: @port, invoice: @invoice,
172
+ suffixes: [], strength: @strength
171
173
  )
172
174
  end
173
175
  idx += 1
@@ -175,7 +177,7 @@ module Zold
175
177
  end
176
178
 
177
179
  def age
178
- Time.now - time
180
+ Time.now - @time
179
181
  end
180
182
 
181
183
  def expired?(hours = 24)
@@ -183,15 +185,15 @@ module Zold
183
185
  end
184
186
 
185
187
  def prefix
186
- "#{time.utc.iso8601} #{host} #{port} #{invoice}"
188
+ "#{@time.utc.iso8601} #{@host} #{@port} #{@invoice}"
187
189
  end
188
190
 
189
191
  def valid?
190
- suffixes.empty? || hash.end_with?('0' * strength)
192
+ @suffixes.empty? || hash.end_with?('0' * @strength)
191
193
  end
192
194
 
193
195
  def value
194
- suffixes.length
196
+ @suffixes.length
195
197
  end
196
198
 
197
199
  def zero?
data/lib/zold/tax.rb CHANGED
@@ -40,7 +40,7 @@ module Zold
40
40
  # The correct amount should be 1 ZLD, but we allow bigger amounts
41
41
  # now since the amount of nodes in the network is still small. When
42
42
  # the network grows up, let's put this number back to 1 ZLD.
43
- MAX_PAYMENT = Amount.new(zld: 16.0)
43
+ MAX_PAYMENT = Amount.new(zld: 64.0)
44
44
 
45
45
  # This is how much we charge per one transaction per hour
46
46
  # of storage. A wallet of 4096 transactions will pay
@@ -76,6 +76,10 @@ module Zold
76
76
  debt > Tax::TRIAL
77
77
  end
78
78
 
79
+ def to_text
80
+ "A=#{@wallet.age}, F=#{Tax::FEE_TXN_HOUR}, T=#{@wallet.txns.count}"
81
+ end
82
+
79
83
  def debt
80
84
  txns = @wallet.txns
81
85
  scored = txns.map do |t|
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.16.6'
28
+ VERSION = '0.16.7'
29
29
  PROTOCOL = 2
30
30
  end
data/resources/remotes CHANGED
@@ -1,6 +1,6 @@
1
- b1.zold.io,80,0,0
2
- b2.zold.io,4096,0,0
3
- 159.203.63.90,4096,0,0
4
- 167.99.77.100,4096,0,0
5
- 159.203.19.189,4096,0,0
6
- 138.197.140.42,4096,0,0
1
+ b1.zold.io,80
2
+ b2.zold.io,4096
3
+ 159.203.63.90,4096
4
+ 167.99.77.100,4096
5
+ 159.203.19.189,4096
6
+ 138.197.140.42,4096
@@ -64,7 +64,7 @@ class FakeNode
64
64
  end
65
65
  uri = "http://localhost:#{port}/"
66
66
  loop do
67
- ping = Zold::Http.new(uri: uri, score: nil, network: Zold::Front.network).get
67
+ ping = Zold::Http.new(uri: uri, network: Zold::Front.network).get
68
68
  break unless ping.code == '599' && node.alive?
69
69
  @log.debug("Waiting for #{uri}: ##{ping.code}...")
70
70
  sleep 0.5
@@ -40,7 +40,7 @@ class FrontTest < Minitest::Test
40
40
 
41
41
  def test_renders_front_json
42
42
  FakeNode.new(log: test_log).run(['--no-metronome', '--network=foo', '--threads=0']) do |port|
43
- res = Zold::Http.new(uri: "http://localhost:#{port}/", network: 'foo', score: nil).get
43
+ res = Zold::Http.new(uri: "http://localhost:#{port}/", network: 'foo').get
44
44
  json = JSON.parse(res.body)
45
45
  assert_equal(Zold::VERSION, json['version'])
46
46
  assert_equal(Zold::PROTOCOL, json['protocol'])
@@ -83,7 +83,7 @@ class FrontTest < Minitest::Test
83
83
  }.each do |code, paths|
84
84
  paths.each do |p|
85
85
  uri = URI("http://localhost:#{port}#{p}")
86
- response = Zold::Http.new(uri: uri, score: nil).get
86
+ response = Zold::Http.new(uri: uri).get
87
87
  assert_equal(
88
88
  code, response.code,
89
89
  "Invalid response code for #{uri}: #{response.message}"
@@ -113,7 +113,7 @@ class FrontTest < Minitest::Test
113
113
  FakeNode.new(log: test_log).run(['--threads=1', '--strength=1', '--no-metronome']) do |port|
114
114
  3.times do |i|
115
115
  assert_equal_wait(true) do
116
- response = Zold::Http.new(uri: "http://localhost:#{port}/", score: nil).get
116
+ response = Zold::Http.new(uri: "http://localhost:#{port}/").get
117
117
  assert_equal('200', response.code, response.body)
118
118
  score = Zold::Score.parse_json(Zold::JsonPage.new(response.body).to_hash['score'])
119
119
  score.value >= i
@@ -127,10 +127,10 @@ class FrontTest < Minitest::Test
127
127
  FakeNode.new(log: test_log).run(['--ignore-score-weakness', '--standalone']) do |port|
128
128
  wallet = home.create_wallet
129
129
  base = "http://localhost:#{port}"
130
- response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil)
130
+ response = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}")
131
131
  .put(IO.read(wallet.path))
132
132
  assert_equal('200', response.code, response.body)
133
- assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
133
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.code }
134
134
  [
135
135
  "/wallet/#{wallet.id}.txt",
136
136
  "/wallet/#{wallet.id}.json",
@@ -141,7 +141,7 @@ class FrontTest < Minitest::Test
141
141
  "/wallet/#{wallet.id}.bin",
142
142
  "/wallet/#{wallet.id}/copies"
143
143
  ].each do |u|
144
- assert_equal_wait('200') { Zold::Http.new(uri: "#{base}#{u}", score: nil).get.code }
144
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}#{u}").get.code }
145
145
  end
146
146
  end
147
147
  end
@@ -152,13 +152,13 @@ class FrontTest < Minitest::Test
152
152
  FakeHome.new(log: test_log).run do |home|
153
153
  wallet = home.create_wallet
154
154
  base = "http://localhost:#{port}"
155
- Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path))
156
- assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
155
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
156
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.code }
157
157
  threads = []
158
158
  mutex = Mutex.new
159
159
  Threads.new(6).assert(100) do
160
160
  assert_equal_wait('200') do
161
- res = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get
161
+ res = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get
162
162
  mutex.synchronize { threads << res.header['X-Zold-Thread'] }
163
163
  res.code
164
164
  end
@@ -175,11 +175,11 @@ class FrontTest < Minitest::Test
175
175
  base = "http://localhost:#{port}"
176
176
  assert_equal(
177
177
  '200',
178
- Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path)).code
178
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path)).code
179
179
  )
180
- assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
180
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.code }
181
181
  3.times do
182
- r = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil)
182
+ r = Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}")
183
183
  .put(IO.read(wallet.path))
184
184
  assert_equal('304', r.code, r.body)
185
185
  end
@@ -193,8 +193,8 @@ class FrontTest < Minitest::Test
193
193
  FakeHome.new(log: test_log).run do |home|
194
194
  Threads.new(5).assert do
195
195
  wallet = home.create_wallet
196
- Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path))
197
- assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
196
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
197
+ assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.code }
198
198
  end
199
199
  end
200
200
  end
@@ -235,7 +235,7 @@ class FrontTest < Minitest::Test
235
235
 
236
236
  def test_gzip
237
237
  FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
238
- response = Zold::Http.new(uri: URI("http://localhost:#{port}/"), score: nil).get
238
+ response = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
239
239
  assert_equal(
240
240
  '200', response.code,
241
241
  "Expected HTTP 200 OK: Found #{response.code}"
@@ -252,7 +252,7 @@ class FrontTest < Minitest::Test
252
252
  FakeNode.new(log: test_log).run(['--threads=4', '--strength=6', '--no-metronome', '--farmer=ruby-proc']) do |port|
253
253
  Threads.new(10).assert(100) do
254
254
  start = Time.now
255
- Zold::Http.new(uri: URI("http://localhost:#{port}/"), score: nil).get
255
+ Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
256
256
  times << Time.now - start
257
257
  end
258
258
  end
@@ -264,7 +264,7 @@ class FrontTest < Minitest::Test
264
264
  def test_headers_are_being_set_correctly
265
265
  Time.stub :now, Time.at(0) do
266
266
  FakeNode.new(log: test_log).run(['--no-metronome', '--threads=0', '--ignore-score-weakness']) do |port|
267
- response = Zold::Http.new(uri: URI("http://localhost:#{port}/"), score: nil).get
267
+ response = Zold::Http.new(uri: URI("http://localhost:#{port}/")).get
268
268
  assert_equal('no-cache', response.header['Cache-Control'])
269
269
  assert_equal('close', response.header['Connection'])
270
270
  assert_equal(app.settings.version, response.header['X-Zold-Version'])
@@ -284,7 +284,7 @@ class FrontTest < Minitest::Test
284
284
  '/remotes'
285
285
  ].each do |path|
286
286
  uri = URI("http://localhost:#{port}#{path}")
287
- response = Zold::Http.new(uri: uri, score: nil).get
287
+ response = Zold::Http.new(uri: uri).get
288
288
  assert_match(
289
289
  name,
290
290
  Zold::JsonPage.new(response.body).to_hash['alias'].to_s,
@@ -297,7 +297,7 @@ class FrontTest < Minitest::Test
297
297
  def test_default_alias_parameter
298
298
  FakeNode.new(log: test_log).run(['--ignore-score-weakness', '--no-metronome']) do |port|
299
299
  uri = URI("http://localhost:#{port}/")
300
- response = Zold::Http.new(uri: uri, score: nil).get
300
+ response = Zold::Http.new(uri: uri).get
301
301
  assert_match(
302
302
  "localhost:#{port}",
303
303
  Zold::JsonPage.new(response.body).to_hash['alias'].to_s,
@@ -310,7 +310,7 @@ class FrontTest < Minitest::Test
310
310
  exception = assert_raises RuntimeError do
311
311
  FakeNode.new(log: test_log).run(['--ignore-score-weakness', '--alias=invalid-alias']) do |port|
312
312
  uri = URI("http://localhost:#{port}/")
313
- Zold::Http.new(uri: uri, score: nil).get
313
+ Zold::Http.new(uri: uri).get
314
314
  end
315
315
  end
316
316
  assert(exception.message.include?('should be a 4 to 16 char long'), exception.message)
@@ -322,16 +322,16 @@ class FrontTest < Minitest::Test
322
322
  FakeHome.new(log: test_log).run do |home|
323
323
  wallet = home.create_wallet(Zold::Id::ROOT)
324
324
  base = "http://localhost:#{port}"
325
- Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path))
326
- assert_equal_wait('200') { Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code }
325
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
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
329
  wallet.sub(Zold::Amount.new(coins: 10), "NOPREFIX@#{Zold::Id.new}", key)
330
- Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).put(IO.read(wallet.path))
331
- assert_equal('200', Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}", score: nil).get.code)
330
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").put(IO.read(wallet.path))
331
+ assert_equal('200', Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}").get.code)
332
332
  end
333
333
  assert_equal_wait(-10 * cycles) do
334
- Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}/balance", score: nil).get.body.to_i
334
+ Zold::Http.new(uri: "#{base}/wallet/#{wallet.id}/balance").get.body.to_i
335
335
  end
336
336
  end
337
337
  end
data/test/test_http.rb CHANGED
@@ -34,14 +34,14 @@ require_relative '../lib/zold/score'
34
34
  class TestHttp < Minitest::Test
35
35
  def test_pings_broken_uri
36
36
  stub_request(:get, 'http://bad-host/').to_return(status: 500)
37
- res = Zold::Http.new(uri: 'http://bad-host/', score: nil).get
37
+ res = Zold::Http.new(uri: 'http://bad-host/').get
38
38
  assert_equal('500', res.code)
39
39
  assert_equal('', res.body)
40
40
  end
41
41
 
42
42
  def test_pings_with_exception
43
43
  stub_request(:get, 'http://exception/').to_return { raise 'Intentionally' }
44
- res = Zold::Http.new(uri: 'http://exception/', score: nil).get
44
+ res = Zold::Http.new(uri: 'http://exception/').get
45
45
  assert_equal('599', res.code)
46
46
  assert(res.body.include?('Intentionally'))
47
47
  assert(!res.header['nothing'])
@@ -49,7 +49,7 @@ class TestHttp < Minitest::Test
49
49
 
50
50
  def test_pings_live_uri
51
51
  stub_request(:get, 'http://good-host/').to_return(status: 200)
52
- res = Zold::Http.new(uri: 'http://good-host/', score: nil).get
52
+ res = Zold::Http.new(uri: 'http://good-host/').get
53
53
  assert_equal('200', res.code)
54
54
  end
55
55
 
@@ -57,7 +57,7 @@ class TestHttp < Minitest::Test
57
57
  stub_request(:get, 'http://some-host-1/')
58
58
  .with(headers: { 'X-Zold-Network' => 'xyz' })
59
59
  .to_return(status: 200)
60
- res = Zold::Http.new(uri: 'http://some-host-1/', score: nil, network: 'xyz').get
60
+ res = Zold::Http.new(uri: 'http://some-host-1/', network: 'xyz').get
61
61
  assert_equal('200', res.code)
62
62
  end
63
63
 
@@ -65,7 +65,7 @@ class TestHttp < Minitest::Test
65
65
  stub_request(:get, 'http://some-host-2/')
66
66
  .with(headers: { 'X-Zold-Protocol' => Zold::PROTOCOL })
67
67
  .to_return(status: 200)
68
- res = Zold::Http.new(uri: 'http://some-host-2/', score: nil).get
68
+ res = Zold::Http.new(uri: 'http://some-host-2/').get
69
69
  assert_equal('200', res.code)
70
70
  end
71
71
 
@@ -74,7 +74,7 @@ class TestHttp < Minitest::Test
74
74
  sleep 100
75
75
  { body: 'This should never be returned!' }
76
76
  end
77
- res = Zold::Http.new(uri: 'http://the-fake-host-99/', score: nil).get
77
+ res = Zold::Http.new(uri: 'http://the-fake-host-99/').get
78
78
  assert_equal('599', res.code)
79
79
  end
80
80
 
@@ -82,7 +82,7 @@ class TestHttp < Minitest::Test
82
82
  stub_request(:get, 'http://some-host-3/')
83
83
  .with(headers: { 'X-Zold-Version' => Zold::VERSION })
84
84
  .to_return(status: 200)
85
- res = Zold::Http.new(uri: 'http://some-host-3/', score: nil).get
86
- assert_equal('200', res.code)
85
+ res = Zold::Http.new(uri: 'http://some-host-3/').get
86
+ assert_equal('200', res.code, res)
87
87
  end
88
88
  end
data/test/test_remotes.rb CHANGED
@@ -45,6 +45,15 @@ class TestRemotes < Minitest::Test
45
45
  end
46
46
  end
47
47
 
48
+ def test_finds_defaults
49
+ Dir.mktmpdir do |dir|
50
+ file = File.join(dir, 'remotes')
51
+ FileUtils.touch(file)
52
+ remotes = Zold::Remotes.new(file: file)
53
+ assert(remotes.default?('b1.zold.io', 80))
54
+ end
55
+ end
56
+
48
57
  def test_reads_broken_file
49
58
  Dir.mktmpdir do |dir|
50
59
  file = File.join(dir, 'remotes')
data/test/test_tax.rb CHANGED
@@ -82,6 +82,14 @@ class TestTax < Minitest::Test
82
82
  end
83
83
  end
84
84
 
85
+ def test_prints_tax_formula
86
+ FakeHome.new(log: test_log).run do |home|
87
+ wallet = home.create_wallet
88
+ tax = Zold::Tax.new(wallet)
89
+ assert(!tax.to_text.nil?)
90
+ end
91
+ end
92
+
85
93
  def test_takes_tax_payment_into_account
86
94
  FakeHome.new(log: test_log).run do |home|
87
95
  wallet = home.create_wallet
data/zold.gemspec CHANGED
@@ -58,8 +58,6 @@ and suggests a different architecture for digital wallet maintenance.'
58
58
  s.add_runtime_dependency 'concurrent-ruby', '~>1.0'
59
59
  s.add_runtime_dependency 'cucumber', '~>3' # has to stay here for Heroku
60
60
  s.add_runtime_dependency 'diffy', '~>3'
61
- s.add_runtime_dependency 'dry-struct', '~>0'
62
- s.add_runtime_dependency 'dry-types', '~>0'
63
61
  s.add_runtime_dependency 'futex', '~>0'
64
62
  s.add_runtime_dependency 'get_process_mem', '~>0'
65
63
  s.add_runtime_dependency 'json', '~>2'
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.16.6
4
+ version: 0.16.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -66,34 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3'
69
- - !ruby/object:Gem::Dependency
70
- name: dry-struct
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: dry-types
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
70
  name: futex
99
71
  requirement: !ruby/object:Gem::Requirement
@@ -574,7 +546,6 @@ files:
574
546
  - lib/zold/tree_wallets.rb
575
547
  - lib/zold/txn.rb
576
548
  - lib/zold/txns.rb
577
- - lib/zold/type.rb
578
549
  - lib/zold/upgrades.rb
579
550
  - lib/zold/verbose_thread.rb
580
551
  - lib/zold/version.rb
data/lib/zold/type.rb DELETED
@@ -1,37 +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
- # @todo #394:30m/DEV Right now only Score, Http, Zold::Remotes and Zold::Remote
24
- # classes have been refactored for using dry-types, even tough the issue has
25
- # been boosted refactoring the whole project is very cumbersome. Please refer
26
- # to Score and Http class on how to perform all the changes for the project to
27
- # adopt dry-types
28
- require 'dry-types'
29
- require 'dry-struct'
30
-
31
- # HTTP page.
32
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
34
- # License:: MIT
35
- module Types
36
- include Dry::Types.module
37
- end