zold 0.20.2 → 0.20.3

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: d066e22fce978f4fdee5ebf56c935c3f05a09a1c7ad57c6da8ed6388db63eb84
4
- data.tar.gz: e505ab03aafc00413ba0f71513fb4bd0f5e06794da6704a2ea335275285222cb
3
+ metadata.gz: 894d41fc051b31c71d31c13d24e288cc73186e4f01c43bc495765fca9254c5a2
4
+ data.tar.gz: e0d8367e208dd8cf78960a617f5d24ff4ff281e91401c312696e8c4dd6904db7
5
5
  SHA512:
6
- metadata.gz: 4313b16d11fb3226c35a0db9b3e7367b9550b008c2be560c3281ae05c8bae9f5249f53b5a7fbd8cd429f3f8207db098e6dada0ed3af68cb1bff927a1f45ce804
7
- data.tar.gz: e2a483f2eff040a1429e96c0a515a00c8a7566ab200ed23ab18b6d6d5dc89c6fecda4d107ef0c21f3481df4759cf0ae6f70ca0c94b5f9270f798ee211854f737
6
+ metadata.gz: 065e309f3cb221272695ca5a963fe2814b1c17498a0f7c70c368d9b4c281e9faafee6fe6ffbbe182791ea27bb327854540be9c711ac1ca6fcbebcaf199212419
7
+ data.tar.gz: 54ba0d26ab73db4c09d23bbd36b6074a107ae2c5c9a3b3ecc38b67d09a5be7b670a1b3406989e26eeee0195ac7278deb3f8ee18cc91a33dba4a6cb7b9184252b
@@ -149,8 +149,7 @@ run 'zold remote update' or use --tolerate-quorum=1"
149
149
  r.assert_score_ownership(score)
150
150
  r.assert_score_strength(score) unless opts['ignore-score-weakness']
151
151
  Tempfile.open(['', Wallet::EXT]) do |f|
152
- body = json['body']
153
- IO.write(f, body)
152
+ IO.write(f, json['body'])
154
153
  wallet = Wallet.new(f.path)
155
154
  wallet.refurbish
156
155
  if wallet.protocol != Zold::PROTOCOL
data/lib/zold/copies.rb CHANGED
@@ -21,6 +21,7 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  require 'time'
24
+ require 'openssl'
24
25
  require 'csv'
25
26
  require 'futex'
26
27
  require 'backtrace'
@@ -97,12 +98,13 @@ module Zold
97
98
  raise "Time must be in the past: #{time}" if time > Time.now
98
99
  raise 'Score must be Integer' unless score.is_a?(Integer)
99
100
  raise "Score can't be negative: #{score}" if score.negative?
101
+ FileUtils.mkdir_p(@dir)
100
102
  Futex.new(file, log: @log).open do
101
- FileUtils.mkdir_p(@dir)
102
103
  list = load
103
104
  target = list.find do |s|
104
105
  f = File.join(@dir, "#{s[:name]}#{Copies::EXT}")
105
- File.exist?(f) && IO.read(f) == content
106
+ digest = OpenSSL::Digest::SHA256.new(content).hexdigest
107
+ File.exist?(f) && OpenSSL::Digest::SHA256.file(f).hexdigest == digest
106
108
  end
107
109
  if target.nil?
108
110
  max = DirItems.new(@dir).fetch
data/lib/zold/head.rb CHANGED
@@ -39,10 +39,9 @@ module Zold
39
39
 
40
40
  def fetch
41
41
  raise "Wallet file '#{@file}' is absent" unless File.exist?(@file)
42
- lines = IO.read(@file).split(/\n/)
43
- # lines = ['', '', '0123456701234567', '']
42
+ lines = IO.readlines(@file, "\n").take(4)
44
43
  raise "Not enough lines in #{@file}, just #{lines.count}" if lines.count < 4
45
- lines.take(4)
44
+ lines
46
45
  end
47
46
  end
48
47
 
@@ -204,8 +204,7 @@ at #{host}:#{port}, strength is #{@strength}")
204
204
 
205
205
  def load
206
206
  return [] unless File.exist?(@cache)
207
- body = Futex.new(@cache).open(false) { |f| IO.read(f) }
208
- body.split(/\n/).reject(&:empty?).map do |t|
207
+ Futex.new(@cache).open(false) { |f| IO.readlines(f, "\n") }.reject(&:empty?).map do |t|
209
208
  Score.parse(t)
210
209
  rescue StandardError => e
211
210
  @log.error(Backtrace.new(e).to_s)
data/lib/zold/patch.rb CHANGED
@@ -20,6 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
+ require 'openssl'
23
24
  require_relative 'log'
24
25
  require_relative 'wallet'
25
26
  require_relative 'signature'
@@ -132,7 +133,7 @@ doesn't have this transaction: \"#{txn.to_text}\"")
132
133
  def save(file, overwrite: false)
133
134
  raise 'You have to join at least one wallet in' if empty?
134
135
  before = ''
135
- before = IO.read(file) if File.exist?(file)
136
+ before = OpenSSL::Digest::SHA256.file(file).hexdigest if File.exist?(file)
136
137
  wallet = Wallet.new(file)
137
138
  wallet.init(@id, @key, overwrite: overwrite, network: @network)
138
139
  File.open(file, 'a') do |f|
@@ -141,7 +142,7 @@ doesn't have this transaction: \"#{txn.to_text}\"")
141
142
  end
142
143
  end
143
144
  wallet.refurbish
144
- after = IO.read(file)
145
+ after = OpenSSL::Digest::SHA256.file(file).hexdigest
145
146
  before != after
146
147
  end
147
148
  end
data/lib/zold/txn.rb CHANGED
@@ -154,7 +154,7 @@ module Zold
154
154
  def self.parse(line, idx = 0)
155
155
  clean = line.strip
156
156
  parts = PTN.match(clean)
157
- raise "Invalid line ##{idx}: #{line.inspect} #{regex}" unless parts
157
+ raise "Invalid line ##{idx}: #{line.inspect} (doesn't match #{PTN})" unless parts
158
158
  txn = Txn.new(
159
159
  Hexnum.parse(parts[:id]).to_i,
160
160
  parse_time(parts[:date]),
data/lib/zold/txns.rb CHANGED
@@ -39,9 +39,10 @@ module Zold
39
39
 
40
40
  def fetch
41
41
  raise "Wallet file '#{@file}' is absent" unless File.exist?(@file)
42
- lines = IO.read(@file).split(/\n/)
42
+ lines = IO.readlines(@file, "\n")
43
43
  raise "Not enough lines in #{@file}, just #{lines.count}" if lines.count < 4
44
44
  lines.drop(5)
45
+ .reject { |t| t.strip.empty? }
45
46
  .each_with_index
46
47
  .map { |line, i| Txn.parse(line, i + 6) }
47
48
  .sort
data/lib/zold/version.rb CHANGED
@@ -25,7 +25,7 @@
25
25
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Zold
28
- VERSION = '0.20.2'
28
+ VERSION = '0.20.3'
29
29
  PROTOCOL = 2
30
30
  REPO = 'zold-io/zold'
31
31
  end
data/lib/zold/wallet.rb CHANGED
@@ -186,7 +186,7 @@ module Zold
186
186
  end
187
187
 
188
188
  def digest
189
- OpenSSL::Digest::SHA256.new(IO.read(@file)).hexdigest
189
+ OpenSSL::Digest::SHA256.file(@file).hexdigest
190
190
  end
191
191
 
192
192
  # Age of wallet in hours
@@ -150,8 +150,8 @@ class FarmTest < Zold::Test
150
150
  Dir.mktmpdir do |dir|
151
151
  file = File.join(dir, 'corrupted_farm')
152
152
  [
153
- '0/6: 2018-06-26ABCT00:32:43Z 178.128.165.12 4096 MIRhypo1@c13620484b46caa4',
154
- 'some garbage'
153
+ 'some garbage',
154
+ 'some other garbage'
155
155
  ].each do |score_garbage_line|
156
156
  valid_score = Zold::Score.new(
157
157
  time: Time.parse('2017-07-19T21:24:51Z'),
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.20.2
4
+ version: 0.20.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -692,7 +692,7 @@ licenses:
692
692
  - MIT
693
693
  metadata: {}
694
694
  post_install_message: |-
695
- Thanks for installing Zold 0.20.2!
695
+ Thanks for installing Zold 0.20.3!
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