zold 0.26.14 → 0.26.15

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
  SHA256:
3
- metadata.gz: 1ecdc52989dd9d8ebaccf6c02649ac87608d5e4a40dd256b621c837da8e7e1c1
4
- data.tar.gz: 19d1ccfdf22e140d06845a7af69d80cea00a3d45a1d8ad8a8347c12429e9126f
3
+ metadata.gz: 5f13f402152afeb770656e632fff9b86f48f4bb99669da498b74f4d78e42dca9
4
+ data.tar.gz: 26e4591a34a4b9b7405181b584df64e04290c62777620ccac4ebf5afa85d8270
5
5
  SHA512:
6
- metadata.gz: 2b95ee04747345f6ebe4494c31ce71e65ae8a48d4c2bea7ceadcc43156dfeade64408ba6aa47630620b240103ba7f7355c78629eb5ddcce25bad2d46ddec47d9
7
- data.tar.gz: fc80522d49c0494deb793ef9b25f2fc6881739eb9be134b52b006ad8fedf0801e90f74652edbf80e4063d470ae35ce648c2855fe050600e5283a468606da175c
6
+ metadata.gz: 3bb478289ca360a81006c2d7eeac834e87fe08805a7374086cd0996babb2099122ef769131ea98c8d59a6d2d2fa9ea9156db6a9457642a2b6dabd8efdbf56b8a
7
+ data.tar.gz: 2b82edcc6fc0ebd2bbeea606ab24206dd6358bbf6472ddcb3ca7e5869f2b79df07253786e0f123abb56c2c3541999f465187e98eb4a1be6894245bd74b5af014
data/bin/zold CHANGED
@@ -81,8 +81,6 @@ Available commands:
81
81
  Remove expired local copies
82
82
  #{Rainbow('merge').green} [ID...] [options]
83
83
  Merge remote copies with the HEAD
84
- #{Rainbow('rebase').green} [ID...] [options]
85
- Rebase local copy of the wallet, removing all inconsistencies
86
84
  #{Rainbow('propagate').green} [ID...] [options]
87
85
  Propagate transactions to receiving wallets
88
86
  #{Rainbow('pull').green} [ID...] [options]
@@ -243,9 +241,6 @@ cmd = lambda do
243
241
  when 'merge'
244
242
  require_relative '../lib/zold/commands/merge'
245
243
  Zold::Merge.new(wallets: wallets, remotes: remotes, copies: copies, log: log).run(args)
246
- when 'rebase'
247
- require_relative '../lib/zold/commands/rebase'
248
- Zold::Rebase.new(wallets: wallets, log: log).run(args)
249
244
  when 'propagate'
250
245
  require_relative '../lib/zold/commands/propagate'
251
246
  Zold::Propagate.new(wallets: wallets, log: log).run(args)
@@ -1 +1,2 @@
1
- --verbose
1
+ --verbose
2
+ --allow-negative-balance
@@ -0,0 +1,6 @@
1
+ test
2
+ 1
3
+ 0000000000000000
4
+ MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnppnkzrCreiKaHF09XKS6bO+2274+wSGo+F8KHvVrNbqear/e09r9PB/P6bFdLoMh4Xc7p/7+NSEZLeu2Eg/dBkQLEb8M/zgkT4gBDGyETW/zusYHIznX/lgf0f8qleIQIIB/3Y7QpDztkamWYTKWlnmlrcQvCVB0uRRPm4ZMcMJouKR9n7E2DpL9eolKyOwr/JY08iJOuK3HuW6tRdvE+0x7I+wDprM65OH/PoArlfO5qnIGbeXwsEGRXt0w6a/ubPpeadFjPXotE7cT1SA4YSD1tWTIVm1ZWppOE967XoDIum6tzt5KfzDNRfs9GbCfO0BL235HxbO8I9rTlVLTKcNAiEe0CWolY9HR5pMaosOgZ6PB54InJEZJs4L2b10c+IlVUX1RSnwfFYg0vy5oqrYyqt7gnipl/06YW4PKIYc7TljogsEHf9Cz/kpEKzqDtsH2LrmjMNsbWiousvNHM+MPgcuMg8ZnwLKwDy9NWdI4XLTpg6hVRJNH9erZdfAO5tg/3ub3JLeJbyNo4Bd5f/Bnr5YN/9ahZ87kSpI7v0Qk94dR4hDPjstEcghyZ9RVUoN52+h1g83cd3cIqksJd0kifMCoBmObD013RSPQqNwr9GGU2JaJEm25Vq35dy2DHAkOQpUZVT8GNg9IM4qUDV0yagTN3bZyvuLWIgufb0CAwEAAQ==
5
+
6
+ 0001;2018-06-22T07:38:23Z;fffffe0000000000;g6hVRJNH;0123456789abcdef;To help you;IFQvo0PN3JkpkuZRjPyQ6BywuM9aSRFI6GdNOevSQ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KcNAiEe0CWolY9HR5pMaosOgZ6PB54InJEZJs4L2b10c+IlVUX1RSnwfFYg0vy5oqrYyqt7gnipl/06YW4PKIYc7TljogsEHf9Cz/kpEKzqDtsH2LrmjMNsbWiousvNHM+MPgcuMg8ZnwLKwDy9NWdI4XLTpg6hVRJNH9erZdfAO5tg/3ub3JLeJbyNo4Bd5f/Bnr5YN/9ahZ87kSpI7v0Qk94dR4hDPjstEcghyZ9RVUoN52+h1g83cd3cIqksJd0kifMCoBmObD013RSPQqNwr9GGU2JaJEm25Vq35dy2DHAkOQpUZVT8GNg9IM4qUDV0yagTN3bZyvuLWIgufb0CAwEAAQ==
5
+
@@ -20,28 +20,6 @@
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 'minitest/autorun'
24
- require 'tmpdir'
25
- require_relative '../test__helper'
26
- require_relative '../fake_home'
27
- require_relative '../../lib/zold/commands/rebase'
28
- require_relative '../../lib/zold/commands/pay'
29
-
30
- # REBASE test.
31
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
33
- # License:: MIT
34
- class TestRebase < Zold::Test
35
- def test_rebases_wallet
36
- FakeHome.new(log: test_log).run do |home|
37
- wallet = home.create_wallet
38
- Zold::Pay.new(wallets: home.wallets, copies: home.dir, remotes: home.remotes, log: test_log).run(
39
- ['pay', wallet.id.to_s, "NOPREFIX@#{Zold::Id.new}", '14.95', '--force', '--private-key=fixtures/id_rsa']
40
- )
41
- Zold::Rebase.new(wallets: home.wallets, log: test_log).run(
42
- ['rebase', wallet.id.to_s]
43
- )
44
- assert_equal(0, wallet.txns.count)
45
- end
46
- end
47
- end
23
+ require_relative 'asserts.rb'
24
+ wallet = Zold::Wallet.new('0123456789abcdef.z')
25
+ assert_equal(Zold::Amount.new(zld: 512.0 - 16 - 32), wallet.balance)
@@ -0,0 +1,6 @@
1
+ test
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/zusYHIznX/lgf0f8qleIQIIB/3Y7QpDztkamWYTKWlnmlrcQvCVB0uRRPm4ZMcMJouKR9n7E2DpL9eolKyOwr/JY08iJOuK3HuW6tRdvE+0x7I+wDprM65OH/PoArlfO5qnIGbeXwsEGRXt0w6a/ubPpeadFjPXotE7cT1SA4YSD1tWTIVm1ZWppOE967XoDIum6tzt5KfzDNRfs9GbCfO0BL235HxbO8I9rTlVLTKcNAiEe0CWolY9HR5pMaosOgZ6PB54InJEZJs4L2b10c+IlVUX1RSnwfFYg0vy5oqrYyqt7gnipl/06YW4PKIYc7TljogsEHf9Cz/kpEKzqDtsH2LrmjMNsbWiousvNHM+MPgcuMg8ZnwLKwDy9NWdI4XLTpg6hVRJNH9erZdfAO5tg/3ub3JLeJbyNo4Bd5f/Bnr5YN/9ahZ87kSpI7v0Qk94dR4hDPjstEcghyZ9RVUoN52+h1g83cd3cIqksJd0kifMCoBmObD013RSPQqNwr9GGU2JaJEm25Vq35dy2DHAkOQpUZVT8GNg9IM4qUDV0yagTN3bZyvuLWIgufb0CAwEAAQ==
5
+
6
+ 0001;2018-06-22T07:38:23Z;0000020000000000;g6hVRJNH;0000000000000000;To help you;
@@ -0,0 +1,3 @@
1
+ 1,0.0.0.0,4096,30,NOW,M
2
+ 2,0.0.0.0,4096,20,NOW,E
3
+ 3,0.0.0.0,4096,10,NOW,E
@@ -0,0 +1 @@
1
+ --verbose
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  zold --help
4
- declare -a commands=(node create invoice remote pay show fetch clean diff rebase merge propagate pull push taxes)
4
+ declare -a commands=(node create invoice remote pay show fetch clean diff merge propagate pull push taxes)
5
5
  for c in "${commands[@]}"
6
6
  do
7
7
  zold --ignore-global-config --trace $c --help
@@ -39,8 +39,6 @@ zold fetch --tolerate-edges --tolerate-quorum=1
39
39
  zold diff 0000000000000000
40
40
  zold merge
41
41
  zold merge 0000000000000000
42
- zold rebase
43
- zold rebase 0000000000000000
44
42
  zold clean
45
43
  zold clean 0000000000000000
46
44
  zold remove
@@ -65,6 +65,9 @@ Available options:"
65
65
  o.bool '--shallow',
66
66
  'Don\'t try to pull other wallets if their confirmations are required',
67
67
  default: false
68
+ o.bool '--allow-negative-balance',
69
+ 'Don\'t check for the negative balance of the wallet after the merge',
70
+ default: false
68
71
  o.string '--ledger',
69
72
  'The name of the file where all new negative transactions will be recorded (default: /dev/null)',
70
73
  default: '/dev/null'
@@ -123,7 +126,9 @@ Available options:"
123
126
  return if opts['quiet-if-absent']
124
127
  raise "There are no copies of #{id}, nothing to merge"
125
128
  end
126
- modified = @wallets.acq(id, exclusive: true) { |w| patch.save(w.path, overwrite: true) }
129
+ modified = @wallets.acq(id, exclusive: true) do |w|
130
+ patch.save(w.path, overwrite: true, allow_negative_balance: opts['allow-negative-balance'])
131
+ end
127
132
  if modified
128
133
  @log.info("#{cps.count} copies with the total score of #{score} successfully merged \
129
134
  into #{@wallets.acq(id, &:mnemo)} in #{Age.new(start, limit: 0.1 + cps.count * 0.01)}")
@@ -28,7 +28,6 @@ require_relative '../tax'
28
28
  require_relative '../age'
29
29
  require_relative '../commands/clean'
30
30
  require_relative '../commands/merge'
31
- require_relative '../commands/rebase'
32
31
  require_relative '../commands/fetch'
33
32
  require_relative '../commands/push'
34
33
 
@@ -86,7 +85,6 @@ module Zold
86
85
  ['clean', id.to_s, '--max-age=1']
87
86
  )
88
87
  copies.remove(host, Remotes::PORT)
89
- modified += Rebase.new(wallets: @wallets, log: @log).run(['rebase', id.to_s])
90
88
  if modified.empty?
91
89
  @log.info("Accepted #{id} in #{Age.new(start, limit: 1)} and not modified anything")
92
90
  else
data/lib/zold/patch.rb CHANGED
@@ -95,12 +95,6 @@ module Zold
95
95
  with a new one \"#{txn.to_text}\" from #{wallet.mnemo}")
96
96
  next
97
97
  end
98
- balance = @txns.map(&:amount).map(&:to_i).inject(&:+).to_i
99
- if balance < txn.amount.to_i * -1 && !wallet.root?
100
- @log.error("The transaction ##{txn.id} attempts to make the balance of \
101
- #{wallet.id}/#{Amount.new(zents: balance).to_zld}/#{@txns.size} negative: \"#{txn.to_text}\"")
102
- next
103
- end
104
98
  unless Signature.new(@network).valid?(@key, wallet.id, txn)
105
99
  @log.error("Invalid RSA signature at the transaction ##{txn.id} of #{wallet.id}: \"#{txn.to_text}\"")
106
100
  next
@@ -162,18 +156,28 @@ doesn't have this transaction: \"#{txn.to_text}\"")
162
156
  end
163
157
 
164
158
  # Returns TRUE if the file was actually modified
165
- def save(file, overwrite: false)
159
+ def save(file, overwrite: false, allow_negative_balance: false)
166
160
  raise 'You have to join at least one wallet in' if empty?
167
161
  before = ''
168
162
  wallet = Wallet.new(file)
169
163
  before = wallet.digest if wallet.exists?
170
- wallet.init(@id, @key, overwrite: overwrite, network: @network)
171
- File.open(file, 'a') do |f|
172
- @txns.each do |txn|
173
- f.print "#{txn}\n"
164
+ Tempfile.open([@id, Wallet::EXT]) do |f|
165
+ temp = Wallet.new(f.path)
166
+ temp.init(@id, @key, overwrite: overwrite, network: @network)
167
+ File.open(f.path, 'a') do |t|
168
+ @txns.each do |txn|
169
+ next if Id::BANNED.include?(txn.bnf.to_s)
170
+ t.print "#{txn}\n"
171
+ end
172
+ end
173
+ temp.refurbish
174
+ if temp.balance.negative? && !temp.id.root? && !allow_negative_balance
175
+ @log.info("The balance is negative, won't merge: #{wallet.mnemo}")
176
+ else
177
+ FileUtils.mkdir_p(File.dirname(file))
178
+ IO.write(file, IO.read(f.path))
174
179
  end
175
180
  end
176
- wallet.refurbish
177
181
  before != wallet.digest
178
182
  end
179
183
  end
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.26.14'
28
+ VERSION = '0.26.15'
29
29
  PROTOCOL = 2
30
30
  REPO = 'zold-io/zold'
31
31
  end
@@ -126,18 +126,6 @@ class TestMerge < Zold::Test
126
126
  end
127
127
  end
128
128
 
129
- def test_removes_negative_fakes
130
- FakeHome.new(log: test_log).run do |home|
131
- wallet = home.create_wallet
132
- key = Zold::Key.new(file: 'fixtures/id_rsa')
133
- wallet.sub(Zold::Amount.new(zld: 9.99), "NOPREFIX@#{Zold::Id.new}", key)
134
- Zold::Merge.new(wallets: home.wallets, remotes: home.remotes, copies: home.copies.root, log: test_log).run(
135
- ['merge', wallet.id.to_s]
136
- )
137
- assert_equal(Zold::Amount::ZERO, wallet.balance)
138
- end
139
- end
140
-
141
129
  base = 'fixtures/merge'
142
130
  Dir.new(base).select { |f| File.directory?(File.join(base, f)) && !f.start_with?('.') }.each do |f|
143
131
  method = "test_#{f}"
@@ -56,7 +56,7 @@ class TestEntrance < Zold::Test
56
56
  ledger = File.join(home.dir, 'ledger.csv')
57
57
  e = Zold::Entrance.new(home.wallets, home.remotes, home.copies(source).root, 'x', ledger: ledger, log: test_log)
58
58
  modified = e.push(source.id, body)
59
- assert_equal(3, modified.count)
59
+ assert_equal(2, modified.count)
60
60
  assert_equal(Zold::Amount.new(zld: -19.99), source.balance)
61
61
  assert_equal(Zold::Amount.new(zld: 19.99), target.balance)
62
62
  assert(modified.include?(sid))
data/test/test_patch.rb CHANGED
@@ -53,7 +53,7 @@ class TestPatch < Zold::Test
53
53
  patch.join(first) { false }
54
54
  patch.join(second) { false }
55
55
  patch.join(third) { false }
56
- assert_equal(true, patch.save(first.path, overwrite: true))
56
+ assert_equal(true, patch.save(first.path, overwrite: true, allow_negative_balance: true))
57
57
  assert_equal(Zold::Amount.new(zld: -53.0), first.balance)
58
58
  end
59
59
  end
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.26.14
4
+ version: 0.26.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-11 00:00:00.000000000 Z
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -586,6 +586,14 @@ files:
586
586
  - fixtures/merge/missed_wallets/copies/0123456789abcdef/1.zc
587
587
  - fixtures/merge/missed_wallets/copies/0123456789abcdef/scores.zc
588
588
  - fixtures/merge/missed_wallets/opts
589
+ - fixtures/merge/negatives_in_between/0000000000000000.z
590
+ - fixtures/merge/negatives_in_between/0123456789abcdef.z
591
+ - fixtures/merge/negatives_in_between/assert.rb
592
+ - fixtures/merge/negatives_in_between/copies/0123456789abcdef/1.zc
593
+ - fixtures/merge/negatives_in_between/copies/0123456789abcdef/2.zc
594
+ - fixtures/merge/negatives_in_between/copies/0123456789abcdef/3.zc
595
+ - fixtures/merge/negatives_in_between/copies/0123456789abcdef/scores.zc
596
+ - fixtures/merge/negatives_in_between/opts
589
597
  - fixtures/merge/random_expenses/0000000000000000.z
590
598
  - fixtures/merge/random_expenses/0123456789abcdef.z
591
599
  - fixtures/merge/random_expenses/assert.rb
@@ -635,7 +643,6 @@ files:
635
643
  - lib/zold/commands/propagate.rb
636
644
  - lib/zold/commands/pull.rb
637
645
  - lib/zold/commands/push.rb
638
- - lib/zold/commands/rebase.rb
639
646
  - lib/zold/commands/remote.rb
640
647
  - lib/zold/commands/remove.rb
641
648
  - lib/zold/commands/routines/audit.rb
@@ -709,7 +716,6 @@ files:
709
716
  - test/commands/test_propagate.rb
710
717
  - test/commands/test_pull.rb
711
718
  - test/commands/test_push.rb
712
- - test/commands/test_rebase.rb
713
719
  - test/commands/test_remote.rb
714
720
  - test/commands/test_remove.rb
715
721
  - test/commands/test_show.rb
@@ -773,7 +779,7 @@ licenses:
773
779
  - MIT
774
780
  metadata: {}
775
781
  post_install_message: |-
776
- Thanks for installing Zold 0.26.14!
782
+ Thanks for installing Zold 0.26.15!
777
783
  Study our White Paper: https://papers.zold.io/wp.pdf
778
784
  Read our blog posts: https://blog.zold.io
779
785
  Try ZLD online wallet at: https://wts.zold.io
@@ -821,7 +827,6 @@ test_files:
821
827
  - test/commands/test_propagate.rb
822
828
  - test/commands/test_pull.rb
823
829
  - test/commands/test_push.rb
824
- - test/commands/test_rebase.rb
825
830
  - test/commands/test_remote.rb
826
831
  - test/commands/test_remove.rb
827
832
  - test/commands/test_show.rb
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2018-2019 Zerocracy, Inc.
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 'slop'
24
- require 'rainbow'
25
- require 'backtrace'
26
- require_relative 'thread_badge'
27
- require_relative 'args'
28
- require_relative '../age'
29
- require_relative '../log'
30
- require_relative '../id'
31
- require_relative '../wallet'
32
- require_relative '../patch'
33
-
34
- # REBASE command.
35
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
36
- # Copyright:: Copyright (c) 2018 Yegor Bugayenko
37
- # License:: MIT
38
- module Zold
39
- # REBASE command
40
- class Rebase
41
- prepend ThreadBadge
42
-
43
- def initialize(wallets:, log: Log::NULL)
44
- @wallets = wallets
45
- @log = log
46
- end
47
-
48
- # Returns the array of modified wallets (IDs)
49
- def run(args = [])
50
- opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
51
- o.banner = "Usage: zold rebase [ID...] [options]
52
- Available options:"
53
- o.bool '--help', 'Print instructions'
54
- end
55
- mine = Args.new(opts, @log).take || return
56
- list = mine.empty? ? @wallets.all : mine.map { |i| Id.new(i) }
57
- modified = []
58
- list.uniq.each do |id|
59
- modified << id if rebase(id, opts)
60
- end
61
- modified
62
- end
63
-
64
- private
65
-
66
- def rebase(id, _)
67
- start = Time.now
68
- patch = Patch.new(@wallets, log: @log)
69
- @wallets.acq(id, exclusive: true) do |wallet|
70
- patch.join(wallet) do |txn|
71
- @log.debug("Paying wallet #{txn.bnf} file is absent: #{txn.to_text}")
72
- false
73
- end
74
- if patch.save(wallet.path, overwrite: true)
75
- @log.info("Wallet #{wallet.mnemo} rebased and modified in #{Age.new(start)}")
76
- else
77
- @log.debug("There is nothing to rebase in #{wallet.mnemo}, took #{Age.new(start)}")
78
- end
79
- end
80
- end
81
- end
82
- end