zold 0.22.9 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/zold +5 -0
- data/lib/zold/commands/fetch.rb +5 -1
- data/lib/zold/commands/merge.rb +8 -4
- data/lib/zold/commands/rebase.rb +76 -0
- data/lib/zold/node/entrance.rb +2 -0
- data/lib/zold/patch.rb +8 -13
- data/lib/zold/version.rb +1 -1
- data/test/commands/test_rebase.rb +43 -0
- data/test/test_patch.rb +11 -11
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95430a239fd73f041ab0fcff000ce6406b7d0ff89e4dc4b66b63c6aaa525967e
|
4
|
+
data.tar.gz: 592bf1dd34b5fbe895033565dd481b01cd4da65d4f92145f17008f8bbbac43f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 664086b5fac5d2ba9fc29fe4b31e5b6a3d542c6a314e9ec91cefeed825460b703bf8f85710e7104fb34ad9ea401b9c2d10fe46d80cfc4b7672f3c584590841b3
|
7
|
+
data.tar.gz: bcf469f972e7f2e2c960e19992a3c6d2fe098b2e1884d46bf5ffceb584c32559942a5c3aec42e0b0f5460cbd3afa83f824c2ca60b25d5d570d130d879fa70949
|
data/bin/zold
CHANGED
@@ -81,6 +81,8 @@ 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
|
84
86
|
#{Rainbow('propagate').green} [ID...] [options]
|
85
87
|
Propagate transactions to receiving wallets
|
86
88
|
#{Rainbow('pull').green} [ID...] [options]
|
@@ -237,6 +239,9 @@ cmd = lambda do
|
|
237
239
|
when 'merge'
|
238
240
|
require_relative '../lib/zold/commands/merge'
|
239
241
|
Zold::Merge.new(wallets: wallets, remotes: remotes, copies: copies, log: log).run(args)
|
242
|
+
when 'merge'
|
243
|
+
require_relative '../lib/zold/commands/rebase'
|
244
|
+
Zold::Rebase.new(wallets: wallets, log: log).run(args)
|
240
245
|
when 'propagate'
|
241
246
|
require_relative '../lib/zold/commands/propagate'
|
242
247
|
Zold::Propagate.new(wallets: wallets, log: log).run(args)
|
data/lib/zold/commands/fetch.rb
CHANGED
@@ -56,6 +56,9 @@ module Zold
|
|
56
56
|
# Raises when there are not enough successful nodes.
|
57
57
|
class NoQuorum < StandardError; end
|
58
58
|
|
59
|
+
# Raises when the wallet wasn't found in all visible nodes.
|
60
|
+
class NotFound < StandardError; end
|
61
|
+
|
59
62
|
def initialize(wallets:, remotes:, copies:, log: Log::NULL)
|
60
63
|
@wallets = wallets
|
61
64
|
@remotes = remotes
|
@@ -117,7 +120,8 @@ Available options:"
|
|
117
120
|
end
|
118
121
|
unless opts['quiet-if-absent']
|
119
122
|
if done.value.zero?
|
120
|
-
raise "No nodes out of #{nodes.value} have the wallet #{id};
|
123
|
+
raise NotFound, "No nodes out of #{nodes.value} have the wallet #{id}; \
|
124
|
+
run 'zold remote update' and try again"
|
121
125
|
end
|
122
126
|
if masters.value.zero? && !opts['tolerate-edges']
|
123
127
|
raise EdgesOnly, "There are only edge nodes, run 'zold remote update' or use --tolerate-edges"
|
data/lib/zold/commands/merge.rb
CHANGED
@@ -37,7 +37,7 @@ require_relative '../patch'
|
|
37
37
|
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
38
38
|
# License:: MIT
|
39
39
|
module Zold
|
40
|
-
# MERGE
|
40
|
+
# MERGE command
|
41
41
|
class Merge
|
42
42
|
prepend ThreadBadge
|
43
43
|
|
@@ -128,12 +128,16 @@ into #{@wallets.acq(id, &:mnemo)} in #{Age.new(start, limit: 0.1 + cps.count * 0
|
|
128
128
|
start = Time.now
|
129
129
|
@log.debug("Building a patch for #{wallet.id} from remote copy ##{name} with #{wallet.mnemo}...")
|
130
130
|
if opts['shallow']
|
131
|
-
patch.join(wallet)
|
131
|
+
patch.join(wallet) do |txn|
|
132
|
+
@log.debug("Paying wallet #{txn.bnf} file is absent but it's a \"shallow\" MERGE: #{txn.to_text}")
|
133
|
+
false
|
134
|
+
end
|
132
135
|
else
|
133
|
-
patch.join(wallet) do |
|
136
|
+
patch.join(wallet) do |txn|
|
134
137
|
Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
|
135
|
-
['pull',
|
138
|
+
['pull', txn.bnf.to_s, "--network=#{opts['network']}", '--shallow']
|
136
139
|
)
|
140
|
+
true
|
137
141
|
end
|
138
142
|
end
|
139
143
|
@log.debug("Copy ##{name} of #{wallet.id} merged in #{Age.new(start)}: #{patch}")
|
@@ -0,0 +1,76 @@
|
|
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
|
+
list.uniq.each do |id|
|
58
|
+
rebase(id, opts)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def rebase(id, _)
|
65
|
+
start = Time.now
|
66
|
+
patch = Patch.new(@wallets, log: @log)
|
67
|
+
@wallets.acq(id) do |wallet|
|
68
|
+
patch.join(wallet) do |txn|
|
69
|
+
@log.debug("Paying wallet #{txn.bnf} file is absent: #{txn.to_text}")
|
70
|
+
false
|
71
|
+
end
|
72
|
+
@log.debug("Wallet #{wallet.mnemo} rebased in #{Age.new(start)}")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/zold/node/entrance.rb
CHANGED
@@ -28,6 +28,7 @@ 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'
|
31
32
|
require_relative '../commands/fetch'
|
32
33
|
require_relative '../commands/push'
|
33
34
|
|
@@ -86,6 +87,7 @@ module Zold
|
|
86
87
|
@log.info("Accepted #{id} in #{Age.new(start, limit: 1)} and not modified anything")
|
87
88
|
else
|
88
89
|
@log.info("Accepted #{id} in #{Age.new(start, limit: 1)} and modified #{modified.join(', ')}")
|
90
|
+
Rebase.new(wallets: @wallets, log: @log).run(['rebase'] + modified.map(&:to_s))
|
89
91
|
end
|
90
92
|
sec = (Time.now - start).round(2)
|
91
93
|
@mutex.synchronize do
|
data/lib/zold/patch.rb
CHANGED
@@ -109,20 +109,15 @@ with a new one \"#{txn.to_text}\" from #{wallet.mnemo}")
|
|
109
109
|
@log.error("Payment prefix '#{txn.prefix}' doesn't match with the key of #{wallet.id}: \"#{txn.to_text}\"")
|
110
110
|
next
|
111
111
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
unless @wallets.acq(txn.bnf) { |p| p.includes_negative?(txn.id, wallet.id) }
|
120
|
-
@log.error("The beneficiary #{@wallets.acq(txn.bnf, &:mnemo)} of #{@id} \
|
112
|
+
if !@wallets.acq(txn.bnf, &:exists?) && yield(txn)
|
113
|
+
unless @wallets.acq(txn.bnf, &:exists?)
|
114
|
+
@log.error("Paying wallet #{txn.bnf} file is absent even after PULL: \"#{txn.to_text}\"")
|
115
|
+
next
|
116
|
+
end
|
117
|
+
unless @wallets.acq(txn.bnf) { |p| p.includes_negative?(txn.id, wallet.id) }
|
118
|
+
@log.error("The beneficiary #{@wallets.acq(txn.bnf, &:mnemo)} of #{@id} \
|
121
119
|
doesn't have this transaction: \"#{txn.to_text}\"")
|
122
|
-
|
123
|
-
end
|
124
|
-
else
|
125
|
-
@log.debug("Paying wallet #{txn.bnf} file is absent but it's a \"shallow\" MERGE: #{txn.to_text}")
|
120
|
+
next
|
126
121
|
end
|
127
122
|
end
|
128
123
|
end
|
data/lib/zold/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
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 'minitest/autorun'
|
24
|
+
require 'tmpdir'
|
25
|
+
require_relative '../test__helper'
|
26
|
+
require_relative '../fake_home'
|
27
|
+
require_relative '../../lib/zold/commands/rebase'
|
28
|
+
|
29
|
+
# REBASE test.
|
30
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
31
|
+
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
|
32
|
+
# License:: MIT
|
33
|
+
class TestRebase < Zold::Test
|
34
|
+
def test_rebases_wallet
|
35
|
+
FakeHome.new(log: test_log).run do |home|
|
36
|
+
wallet = home.create_wallet
|
37
|
+
Zold::Rebase.new(wallets: home.wallets, log: test_log).run(
|
38
|
+
['rebase', wallet.id.to_s]
|
39
|
+
)
|
40
|
+
assert_equal(0, wallet.txns.count)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/test/test_patch.rb
CHANGED
@@ -50,9 +50,9 @@ class TestPatch < Zold::Test
|
|
50
50
|
t = third.sub(Zold::Amount.new(zld: 10.0), "NOPREFIX@#{Zold::Id.new}", key)
|
51
51
|
third.add(t.inverse(Zold::Id.new))
|
52
52
|
patch = Zold::Patch.new(home.wallets, log: test_log)
|
53
|
-
patch.join(first)
|
54
|
-
patch.join(second)
|
55
|
-
patch.join(third)
|
53
|
+
patch.join(first) { false }
|
54
|
+
patch.join(second) { false }
|
55
|
+
patch.join(third) { false }
|
56
56
|
assert_equal(true, patch.save(first.path, overwrite: true))
|
57
57
|
assert_equal(Zold::Amount.new(zld: -53.0), first.balance)
|
58
58
|
end
|
@@ -65,8 +65,8 @@ class TestPatch < Zold::Test
|
|
65
65
|
IO.write(second.path, IO.read(first.path))
|
66
66
|
second.add(Zold::Txn.new(1, Time.now, Zold::Amount.new(zld: 11.0), 'NOPREFIX', Zold::Id.new, 'fake'))
|
67
67
|
patch = Zold::Patch.new(home.wallets, log: test_log)
|
68
|
-
patch.join(first)
|
69
|
-
patch.join(second)
|
68
|
+
patch.join(first) { false }
|
69
|
+
patch.join(second) { false }
|
70
70
|
assert_equal(false, patch.save(first.path, overwrite: true))
|
71
71
|
first.flush
|
72
72
|
assert_equal(Zold::Amount::ZERO, first.balance)
|
@@ -82,8 +82,8 @@ class TestPatch < Zold::Test
|
|
82
82
|
key = Zold::Key.new(file: 'fixtures/id_rsa')
|
83
83
|
second.sub(amount, "NOPREFIX@#{Zold::Id.new}", key)
|
84
84
|
patch = Zold::Patch.new(home.wallets, log: test_log)
|
85
|
-
patch.join(first)
|
86
|
-
patch.join(second)
|
85
|
+
patch.join(first) { false }
|
86
|
+
patch.join(second) { false }
|
87
87
|
assert_equal(true, patch.save(first.path, overwrite: true))
|
88
88
|
first.flush
|
89
89
|
assert_equal(amount * -1, first.balance)
|
@@ -104,8 +104,8 @@ class TestPatch < Zold::Test
|
|
104
104
|
)
|
105
105
|
)
|
106
106
|
patch = Zold::Patch.new(home.wallets, log: test_log)
|
107
|
-
patch.join(first)
|
108
|
-
patch.join(second)
|
107
|
+
patch.join(first) { false }
|
108
|
+
patch.join(second) { false }
|
109
109
|
assert_equal(true, patch.save(first.path, overwrite: true))
|
110
110
|
first.flush
|
111
111
|
assert_equal(Zold::Amount.new(zld: 2.0).to_s, first.balance.to_s)
|
@@ -138,8 +138,8 @@ class TestPatch < Zold::Test
|
|
138
138
|
).signed(key, first.id)
|
139
139
|
)
|
140
140
|
patch = Zold::Patch.new(home.wallets, log: test_log)
|
141
|
-
patch.join(first)
|
142
|
-
patch.join(second)
|
141
|
+
patch.join(first) { false }
|
142
|
+
patch.join(second) { false }
|
143
143
|
assert_equal(true, patch.save(first.path, overwrite: true))
|
144
144
|
first.flush
|
145
145
|
assert_equal(3, first.txns.count)
|
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.
|
4
|
+
version: 0.23.0
|
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-02-
|
11
|
+
date: 2019-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|
@@ -620,6 +620,7 @@ files:
|
|
620
620
|
- lib/zold/commands/propagate.rb
|
621
621
|
- lib/zold/commands/pull.rb
|
622
622
|
- lib/zold/commands/push.rb
|
623
|
+
- lib/zold/commands/rebase.rb
|
623
624
|
- lib/zold/commands/remote.rb
|
624
625
|
- lib/zold/commands/remove.rb
|
625
626
|
- lib/zold/commands/routines/audit.rb
|
@@ -690,6 +691,7 @@ files:
|
|
690
691
|
- test/commands/test_propagate.rb
|
691
692
|
- test/commands/test_pull.rb
|
692
693
|
- test/commands/test_push.rb
|
694
|
+
- test/commands/test_rebase.rb
|
693
695
|
- test/commands/test_remote.rb
|
694
696
|
- test/commands/test_remove.rb
|
695
697
|
- test/commands/test_show.rb
|
@@ -751,7 +753,7 @@ licenses:
|
|
751
753
|
- MIT
|
752
754
|
metadata: {}
|
753
755
|
post_install_message: |-
|
754
|
-
Thanks for installing Zold 0.
|
756
|
+
Thanks for installing Zold 0.23.0!
|
755
757
|
Study our White Paper: https://papers.zold.io/wp.pdf
|
756
758
|
Read our blog posts: https://blog.zold.io
|
757
759
|
Try ZLD online wallet at: https://wts.zold.io
|
@@ -799,6 +801,7 @@ test_files:
|
|
799
801
|
- test/commands/test_propagate.rb
|
800
802
|
- test/commands/test_pull.rb
|
801
803
|
- test/commands/test_push.rb
|
804
|
+
- test/commands/test_rebase.rb
|
802
805
|
- test/commands/test_remote.rb
|
803
806
|
- test/commands/test_remove.rb
|
804
807
|
- test/commands/test_show.rb
|