zold 0.11.21 → 0.11.22
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 +4 -4
- data/bin/zold-nohup +17 -9
- data/lib/zold/commands/diff.rb +2 -7
- data/lib/zold/commands/merge.rb +1 -1
- data/lib/zold/patch.rb +27 -10
- data/lib/zold/version.rb +1 -1
- data/test/commands/test_diff.rb +1 -1
- data/test/test_patch.rb +6 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc7e111fc1e96f2796c64c793edd9714972680d8
|
4
|
+
data.tar.gz: 5149c712d5e30dd6e92f7e3ead90d0329d904399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29bf131b899ac382814b6ffcefa8b472167387b081269b9224b972ec4d3229bf40aad759c4cd39298e11af193a0d27f49b448679138c434d0c46d0d91f29b700
|
7
|
+
data.tar.gz: f676f48ea7719ccf1552220381e0df2e0a732791686d0b8128a5c57c2d3ca2711318910c70a24f2141d31dad3d835ebc78ca766e817ef963917b89a6aa023c88
|
data/bin/zold-nohup
CHANGED
@@ -57,12 +57,15 @@ def exec(cmd)
|
|
57
57
|
Open3.popen2e(cmd) do |stdin, stdout, thr|
|
58
58
|
log("Started: #{cmd}\n")
|
59
59
|
stdin.close
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
until stdout.eof?
|
61
|
+
begin
|
62
|
+
data = stdout.read_nonblock(1024) unless stdout.eof?
|
63
|
+
rescue EOFError => _
|
64
|
+
break
|
65
|
+
end
|
66
|
+
log(data)
|
64
67
|
end
|
65
|
-
code = thr.value.
|
68
|
+
code = thr.value.to_i
|
66
69
|
log("Exit code is #{code}: #{cmd}\n")
|
67
70
|
raise "Exit code #{code} (non zero)" unless code.zero?
|
68
71
|
end
|
@@ -72,15 +75,20 @@ File.delete($opts['log-file']) if File.exist?($opts['log-file']) && !$opts['skip
|
|
72
75
|
|
73
76
|
$pid = fork do
|
74
77
|
Signal.trap('HUP') do
|
75
|
-
log(
|
78
|
+
log("Received HUP, ignoring...\n")
|
76
79
|
end
|
77
80
|
Signal.trap('TERM') do
|
78
|
-
log(
|
81
|
+
log("Received TERM, terminating...\n")
|
79
82
|
exit(-1)
|
80
83
|
end
|
81
84
|
loop do
|
82
|
-
|
83
|
-
|
85
|
+
begin
|
86
|
+
exec("zold #{$opts.arguments.join(' ')}")
|
87
|
+
exec(($opts['sudo-install'] ? 'sudo ' : '') + 'gem install zold') unless $opts['skip-install']
|
88
|
+
rescue StandardError => e
|
89
|
+
log("#{e.class.name}: #{e.message}\n#{e.backtrace.join("\n\t")}\n")
|
90
|
+
raise e
|
91
|
+
end
|
84
92
|
end
|
85
93
|
end
|
86
94
|
Process.detach($pid)
|
data/lib/zold/commands/diff.rb
CHANGED
@@ -65,14 +65,9 @@ Available options:"
|
|
65
65
|
def diff(wallet, cps, _)
|
66
66
|
raise "There are no remote copies, try 'zold fetch' first" if cps.all.empty?
|
67
67
|
cps = cps.all.sort_by { |c| c[:score] }.reverse
|
68
|
-
patch = Patch.new
|
68
|
+
patch = Patch.new(log: @log)
|
69
69
|
cps.each do |c|
|
70
|
-
|
71
|
-
patch.join(Wallet.new(c[:path]))
|
72
|
-
rescue StandardError => e
|
73
|
-
@log.error("Can't use a copy of #{wallet.id} from #{c[:host]}:#{c[:port]}; #{e.class.name}: #{e.message}")
|
74
|
-
@log.debug(e.backtrace.join("\n\t"))
|
75
|
-
end
|
70
|
+
patch.join(Wallet.new(c[:path]))
|
76
71
|
end
|
77
72
|
before = AtomicFile.new(wallet.path).read
|
78
73
|
after = ''
|
data/lib/zold/commands/merge.rb
CHANGED
@@ -66,7 +66,7 @@ Available options:"
|
|
66
66
|
return
|
67
67
|
end
|
68
68
|
cps = cps.all.sort_by { |c| c[:score] }.reverse
|
69
|
-
patch = Patch.new
|
69
|
+
patch = Patch.new(log: @log)
|
70
70
|
cps.each do |c|
|
71
71
|
merge_one(patch, Wallet.new(c[:path]), "#{c[:host]}:#{c[:port]}")
|
72
72
|
@log.debug("#{c[:host]}:#{c[:port]} merged: #{patch}")
|
data/lib/zold/patch.rb
CHANGED
@@ -18,6 +18,7 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
|
+
require_relative 'log'
|
21
22
|
require_relative 'wallet'
|
22
23
|
require_relative 'signature'
|
23
24
|
require_relative 'atomic_file'
|
@@ -30,6 +31,10 @@ require_relative 'atomic_file'
|
|
30
31
|
module Zold
|
31
32
|
# A patch
|
32
33
|
class Patch
|
34
|
+
def initialize(log: Log::Quiet.new)
|
35
|
+
@log = log
|
36
|
+
end
|
37
|
+
|
33
38
|
def to_s
|
34
39
|
return 'empty' if @id.nil?
|
35
40
|
"#{@txns.count} txns"
|
@@ -40,6 +45,7 @@ module Zold
|
|
40
45
|
@id = wallet.id
|
41
46
|
@key = wallet.key
|
42
47
|
@txns = wallet.txns
|
48
|
+
@log.debug("The baseline: #{@txns.count} transactions, the balance is #{wallet.balance}")
|
43
49
|
@network = wallet.network
|
44
50
|
end
|
45
51
|
if wallet.network != @network
|
@@ -51,17 +57,28 @@ module Zold
|
|
51
57
|
max = negative.empty? ? 0 : negative.max_by(&:id).id
|
52
58
|
wallet.txns.each do |txn|
|
53
59
|
next if @txns.find { |t| t == txn }
|
54
|
-
|
55
|
-
txn.
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
if txn.amount.negative?
|
61
|
+
if txn.id <= max
|
62
|
+
@log.debug("Transaction ID is less than max #{max}: #{txn.to_text}")
|
63
|
+
next
|
64
|
+
end
|
65
|
+
if @txns.find { |t| t.id == txn.id }
|
66
|
+
@log.debug("Transaction ##{txn.id} already exists: #{txn.to_text}")
|
67
|
+
next
|
68
|
+
end
|
69
|
+
if !@txns.empty? && @txns.map(&:amount).inject(&:+) < txn.amount
|
70
|
+
@log.debug("Transaction ##{txn.id} attempts to make the balance negative: #{txn.to_text}")
|
71
|
+
next
|
72
|
+
end
|
73
|
+
unless Signature.new.valid?(@key, wallet.id, txn)
|
74
|
+
@log.debug("Invalid RSA signature at transaction ##{txn.id} of #{wallet.id}: #{txn.to_text}")
|
75
|
+
next
|
76
|
+
end
|
77
|
+
elsif !txn.sign.nil? && !txn.sign.empty?
|
78
|
+
@log.debug("RSA signature is redundant at ##{txn.id} of #{wallet.id}: #{txn.to_text}")
|
79
|
+
next
|
64
80
|
end
|
81
|
+
@log.debug("Merged on top: #{txn.to_text}")
|
65
82
|
@txns << txn
|
66
83
|
end
|
67
84
|
end
|
data/lib/zold/version.rb
CHANGED
data/test/commands/test_diff.rb
CHANGED
data/test/test_patch.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
22
|
require_relative 'fake_home'
|
23
|
+
require_relative 'test__helper'
|
23
24
|
require_relative '../lib/zold/key'
|
24
25
|
require_relative '../lib/zold/id'
|
25
26
|
require_relative '../lib/zold/wallet'
|
@@ -45,17 +46,13 @@ class TestPatch < Minitest::Test
|
|
45
46
|
File.write(third.path, File.read(first.path))
|
46
47
|
t = third.sub(Zold::Amount.new(zld: 10.0), "NOPREFIX@#{Zold::Id.new}", key)
|
47
48
|
third.add(t.inverse(first.id))
|
48
|
-
patch = Zold::Patch.new
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
patch.join(third)
|
53
|
-
rescue StandardError => e
|
54
|
-
test_log.info("Ignore it: #{e.message}")
|
55
|
-
end
|
49
|
+
patch = Zold::Patch.new(log: test_log)
|
50
|
+
patch.join(first)
|
51
|
+
patch.join(second)
|
52
|
+
patch.join(third)
|
56
53
|
FileUtils.rm(first.path)
|
57
54
|
assert_equal(true, patch.save(first.path))
|
58
|
-
assert_equal(Zold::Amount.new(zld: -
|
55
|
+
assert_equal(Zold::Amount.new(zld: -43.0), first.balance)
|
59
56
|
end
|
60
57
|
end
|
61
58
|
end
|