zold 0.14.5 → 0.14.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02756005fb2c93a0d5f761508fd96a03ced75595
4
- data.tar.gz: eca849a45be0c29b8e5e11b7579ab16f15429388
3
+ metadata.gz: fe27c493a3594f3ad04a4d024d87c918c54a27c5
4
+ data.tar.gz: b862fc9b4598e823f994c8705407c66895a5f41a
5
5
  SHA512:
6
- metadata.gz: 77f888f0178cf42099ed921f9de20843cedcbc2adb9ea313f42236ee90f20497ad515f9a9055809ee19ffa291bf2986f0daaab522ababca288be60a0f3bacd18
7
- data.tar.gz: 211a846efc40001fce2ba874e874b9cb5d312873719b379a4aae14e93bae4ab86a90b9d828f1440acae2f16faf0b874c17461d078c48bdc973b5a54797154833
6
+ metadata.gz: 4ad796318f03c00a569968618259c56e366dd4ef142a3aea108a143085aa84b4f7a4280079db4d4434bf7eb40742ca56f8417628cbeef461b5749cc7add113a4
7
+ data.tar.gz: 3f48555b78d03a02664637dfee238e970e764844993341c6c1ed6521a212d285729366f8c73b9a32b23b6eb14c76ac0da9eb5f1701c1b260f5b2ca206058a7f4
@@ -71,7 +71,7 @@ Available options:"
71
71
  next
72
72
  end
73
73
  next if target.has?(t.id, me)
74
- unless Prefixes.new(target).valid?(t.prefix)
74
+ unless target.prefix?(t.prefix)
75
75
  @log.error("#{t.amount * -1} to #{t.bnf}: wrong prefix")
76
76
  next
77
77
  end
@@ -57,12 +57,13 @@ module Zold
57
57
  start = Time.now
58
58
  begin
59
59
  r.exec(step)
60
+ @log.info("Routine #{r.class.name} ##{step} done in #{(Time.now - start).round(2)}s")
60
61
  rescue StandardError => e
61
62
  @failures[r.class.name] = Backtrace.new(e).to_s
63
+ @log.error("Routine #{r.class.name} ##{step} failed in #{(Time.now - start).round(2)}s")
64
+ @log.error(Backtrace.new(e).to_s)
62
65
  end
63
66
  step += 1
64
- @log.info("Routine #{r.class.name} ##{step} done in #{(Time.now - start).round(2)}s: \
65
- #{@threads.map { |t| "#{t.name}/#{t.status}" }.join(',')}")
66
67
  sleep(1)
67
68
  end
68
69
  end
@@ -225,13 +225,6 @@ module Zold
225
225
  status 304
226
226
  return
227
227
  end
228
- if before != after && before.length == after.length
229
- settings.log.debug(
230
- "Weird... the wallet #{id} is of the same length #{after.length}, but the content is different:\n" +
231
- Diffy::Diff.new(before, after, context: 0).to_s
232
- )
233
- end
234
- settings.log.info("Wallet #{id} is new: #{before.length}b != #{after.length}b")
235
228
  settings.entrance.push(id, after)
236
229
  JSON.pretty_generate(
237
230
  version: settings.version,
@@ -59,6 +59,10 @@ module Zold
59
59
  Tempfile.open(['', Wallet::EXTENSION]) do |f|
60
60
  File.write(f, body)
61
61
  wallet = Wallet.new(f.path)
62
+ wallet.refurbish
63
+ unless wallet.protocol == Zold::PROTOCOL
64
+ raise "The protocol mismatch, the wallet is in '#{wallet.protocol}', we are in '#{Zold::PROTOCOL}'"
65
+ end
62
66
  unless wallet.network == @network
63
67
  raise "The network name mismatch, the wallet is in '#{wallet.network}', we are in '#{@network}'"
64
68
  end
data/lib/zold/patch.rb CHANGED
@@ -84,7 +84,7 @@ module Zold
84
84
  @log.error("RSA signature is redundant at ##{txn.id} of #{wallet.id}: #{txn.to_text}")
85
85
  next
86
86
  end
87
- unless wallet.key.to_s.include?(txn.prefix)
87
+ unless wallet.prefix?(txn.prefix)
88
88
  @log.error("Payment prefix '#{txn.prefix}' doesn't match with the key of #{wallet.id}: #{txn.to_text}")
89
89
  next
90
90
  end
data/lib/zold/prefixes.rb CHANGED
@@ -35,19 +35,14 @@ module Zold
35
35
  def create(length = 8)
36
36
  raise "Length #{length} is too small" if length < 8
37
37
  raise "Length #{length} is too big" if length > 32
38
- key = body
39
- start = Random.new.rand(key.length - length)
40
- key[start..(start + length - 1)]
41
- end
42
-
43
- def valid?(prefix)
44
- body.include?(prefix)
45
- end
46
-
47
- private
48
-
49
- def body
50
- @wallet.key.to_pub.gsub(/[^A-Z0-9a-z]/, '')
38
+ key = @wallet.key.to_pub
39
+ prefix = ''
40
+ rnd = Random.new
41
+ until prefix =~ /^[a-zA-Z0-9]+$/
42
+ start = rnd.rand(key.length - length)
43
+ prefix = key[start..(start + length - 1)]
44
+ end
45
+ prefix
51
46
  end
52
47
  end
53
48
  end
data/lib/zold/version.rb CHANGED
@@ -23,6 +23,6 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.14.5'.freeze
26
+ VERSION = '0.14.6'.freeze
27
27
  PROTOCOL = 2
28
28
  end
data/lib/zold/wallet.rb CHANGED
@@ -134,6 +134,10 @@ module Zold
134
134
  !txns.find { |t| t.id == id && t.bnf == bnf }.nil?
135
135
  end
136
136
 
137
+ def prefix?(prefix)
138
+ key.to_pub.include?(prefix)
139
+ end
140
+
137
141
  def key
138
142
  Key.new(text: lines[3].strip)
139
143
  end
@@ -36,9 +36,11 @@ class TestPrefixes < Minitest::Test
36
36
  wallet = home.create_wallet
37
37
  prefixes = Zold::Prefixes.new(wallet)
38
38
  (8..32).each do |len|
39
- prefix = prefixes.create(len)
40
- assert_equal(len, prefix.length)
41
- assert(prefixes.valid?(prefix))
39
+ 50.times do
40
+ prefix = prefixes.create(len)
41
+ assert_equal(len, prefix.length)
42
+ assert(wallet.prefix?(prefix), "Prefix '#{prefix}' not found")
43
+ end
42
44
  end
43
45
  end
44
46
  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.5
4
+ version: 0.14.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko