zold 0.20.3 → 0.20.4

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: 894d41fc051b31c71d31c13d24e288cc73186e4f01c43bc495765fca9254c5a2
4
- data.tar.gz: e0d8367e208dd8cf78960a617f5d24ff4ff281e91401c312696e8c4dd6904db7
3
+ metadata.gz: 8f86c74b0e0ba785befac0d7dfe8064e26ed50da6d573f291a7ee31fefc5dac7
4
+ data.tar.gz: 45e481a2b598866032c3fcc487bd7935f05615e7af517a8d76d998ae879bb1a2
5
5
  SHA512:
6
- metadata.gz: 065e309f3cb221272695ca5a963fe2814b1c17498a0f7c70c368d9b4c281e9faafee6fe6ffbbe182791ea27bb327854540be9c711ac1ca6fcbebcaf199212419
7
- data.tar.gz: 54ba0d26ab73db4c09d23bbd36b6074a107ae2c5c9a3b3ecc38b67d09a5be7b670a1b3406989e26eeee0195ac7278deb3f8ee18cc91a33dba4a6cb7b9184252b
6
+ metadata.gz: 74ec4dbe1a0e12603e374a9fe15d8228e4435c81d4d808e8155e4a8c4c91e42bec94a9d69b9bf1437fa3cadb2ed6fc9c04d5e84117a5c15e17d67540000864e4
7
+ data.tar.gz: 72d5ebdcbf091de7dd2b0d52df27390b2a0f9ddd6f3da8ef9e9dcca3eaab4b8435edc4fa01baced1199eec1edc7dd115d14543013367ed972c675d1c083ac83c
@@ -85,8 +85,8 @@ Available options:"
85
85
  'The name of the network we work in',
86
86
  default: 'test'
87
87
  o.integer '--threads',
88
- "How many threads to use for fetching wallets (default: #{[Concurrent.processor_count / 2, 2].max})",
89
- default: [Concurrent.processor_count / 2, 2].max
88
+ 'How many threads to use for fetching wallets (default: 1)',
89
+ default: 1
90
90
  o.bool '--help', 'Print instructions'
91
91
  end
92
92
  mine = Args.new(opts, @log).take || return
@@ -77,8 +77,8 @@ Available options:"
77
77
  'Ignore this node and don\'t push to it',
78
78
  default: []
79
79
  o.integer '--threads',
80
- "How many threads to use for pushing wallets (default: #{[Concurrent.processor_count / 2, 2].max})",
81
- default: [Concurrent.processor_count / 2, 2].max
80
+ 'How many threads to use for pushing wallets (default: 1)',
81
+ default: 1
82
82
  o.bool '--help', 'Print instructions'
83
83
  end
84
84
  mine = Args.new(opts, @log).take || return
@@ -29,6 +29,9 @@ require_relative 'txn'
29
29
  module Zold
30
30
  # Head of the wallet.
31
31
  class Head
32
+ # When can't parse them.
33
+ class CantParse < StandardError; end
34
+
32
35
  def initialize(file)
33
36
  @file = file
34
37
  end
@@ -39,8 +42,11 @@ module Zold
39
42
 
40
43
  def fetch
41
44
  raise "Wallet file '#{@file}' is absent" unless File.exist?(@file)
42
- lines = IO.readlines(@file, "\n").take(4)
43
- raise "Not enough lines in #{@file}, just #{lines.count}" if lines.count < 4
45
+ lines = []
46
+ File.open(@file) do |f|
47
+ lines << f.readline while lines.count < 4 && !f.eof?
48
+ end
49
+ raise CantParse, "Not enough lines in #{@file}, just #{lines.count}" if lines.count < 4
44
50
  lines
45
51
  end
46
52
  end
@@ -34,6 +34,9 @@ require_relative 'signature'
34
34
  module Zold
35
35
  # A single transaction
36
36
  class Txn
37
+ # When can't parse them.
38
+ class CantParse < StandardError; end
39
+
37
40
  # Regular expression for details
38
41
  RE_DETAILS = '[a-zA-Z0-9 @\!\?\*_\-\.:,\'/]+'
39
42
  private_constant :RE_DETAILS
@@ -154,7 +157,7 @@ module Zold
154
157
  def self.parse(line, idx = 0)
155
158
  clean = line.strip
156
159
  parts = PTN.match(clean)
157
- raise "Invalid line ##{idx}: #{line.inspect} (doesn't match #{PTN})" unless parts
160
+ raise CantParse, "Invalid line ##{idx}: #{line.inspect} (doesn't match #{PTN})" unless parts
158
161
  txn = Txn.new(
159
162
  Hexnum.parse(parts[:id]).to_i,
160
163
  parse_time(parts[:date]),
@@ -29,6 +29,9 @@ require_relative 'txn'
29
29
  module Zold
30
30
  # A collection of transactions
31
31
  class Txns
32
+ # When can't parse them.
33
+ class CantParse < StandardError; end
34
+
32
35
  def initialize(file)
33
36
  @file = file
34
37
  end
@@ -39,13 +42,19 @@ module Zold
39
42
 
40
43
  def fetch
41
44
  raise "Wallet file '#{@file}' is absent" unless File.exist?(@file)
42
- lines = IO.readlines(@file, "\n")
43
- raise "Not enough lines in #{@file}, just #{lines.count}" if lines.count < 4
44
- lines.drop(5)
45
- .reject { |t| t.strip.empty? }
46
- .each_with_index
47
- .map { |line, i| Txn.parse(line, i + 6) }
48
- .sort
45
+ txns = []
46
+ i = 0
47
+ File.open(@file) do |f|
48
+ until f.eof?
49
+ line = f.readline
50
+ i += 1
51
+ next if i < 5
52
+ next if line.strip.empty?
53
+ txns << Txn.parse(line, i)
54
+ end
55
+ end
56
+ raise CantParse, "Not enough lines in #{@file}, just #{i}" if i < 4
57
+ txns.sort
49
58
  end
50
59
  end
51
60
 
@@ -25,7 +25,7 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.20.3'
28
+ VERSION = '0.20.4'
29
29
  PROTOCOL = 2
30
30
  REPO = 'zold-io/zold'
31
31
  end
@@ -21,6 +21,7 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'minitest/autorun'
24
+ require 'tmpdir'
24
25
  require_relative 'test__helper'
25
26
  require_relative 'fake_home'
26
27
  require_relative '../lib/zold/key'
@@ -219,6 +220,19 @@ class TestWallet < Zold::Test
219
220
  end
220
221
  end
221
222
 
223
+ def test_raises_when_broken_format
224
+ Dir.mktmpdir do |dir|
225
+ file = File.join(dir, "0123456701234567#{Zold::Wallet::EXT}")
226
+ IO.write(file, 'broken head')
227
+ assert_raises(Zold::Head::CantParse) do
228
+ Zold::Wallet.new(file).id
229
+ end
230
+ assert_raises(Zold::Txns::CantParse) do
231
+ Zold::Wallet.new(file).txns
232
+ end
233
+ end
234
+ end
235
+
222
236
  def test_returns_protocol
223
237
  FakeHome.new(log: test_log).run do |home|
224
238
  wallet = home.create_wallet
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.20.3
4
+ version: 0.20.4
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-12-21 00:00:00.000000000 Z
11
+ date: 2018-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -692,7 +692,7 @@ licenses:
692
692
  - MIT
693
693
  metadata: {}
694
694
  post_install_message: |-
695
- Thanks for installing Zold 0.20.3!
695
+ Thanks for installing Zold 0.20.4!
696
696
  Study our White Paper: https://papers.zold.io/wp.pdf
697
697
  Read our blog posts: https://blog.zold.io
698
698
  Try online wallet at: https://wts.zold.io