zold 0.13.10 → 0.13.11
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/.rultor.yml +2 -2
- data/INSTALL.md +24 -11
- data/lib/zold/commands/pay.rb +4 -5
- data/lib/zold/commands/remote.rb +0 -5
- data/lib/zold/commands/routines/bonuses.rb +5 -4
- data/lib/zold/node/front.rb +1 -1
- data/lib/zold/score.rb +3 -0
- data/lib/zold/version.rb +1 -1
- data/test/commands/routines/test_bonuses.rb +36 -13
- data/test/test_score.rb +11 -8
- data/test/test_zold.rb +2 -1
- 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: 9c81c7772e47855ebd6af3e85ea2f182c509ba60
|
4
|
+
data.tar.gz: 9ca2681e2924bec9f15b151c983607a1b6371c09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be840135594a5a105bf2a14a7ea46651f69ab500217e78414c90f4db5b9b2d96078227cf4f7d0d0e636f6ed7bffbd40a3cd1807bc02e4c065ef68348214e1ef0
|
7
|
+
data.tar.gz: 253ef4deebb11727c2bacc5ec92e22efb2ff92fc44b42a5c3a37a8e85e39ec4aac9616a4570f5323225be9f96100e018c2d901d318fcd3dbb6fb1d810af87e7c
|
data/.rultor.yml
CHANGED
@@ -9,10 +9,10 @@ install: |
|
|
9
9
|
release:
|
10
10
|
script: |-
|
11
11
|
[[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1
|
12
|
-
bundle install
|
13
|
-
rake
|
14
12
|
rm -rf *.gem
|
15
13
|
sed -i "s/0\.0\.0/${tag}/g" lib/zold/version.rb
|
14
|
+
bundle install
|
15
|
+
rake
|
16
16
|
git add lib/zold/version.rb
|
17
17
|
git commit -m "version set to ${tag}"
|
18
18
|
gem build zold.gemspec
|
data/INSTALL.md
CHANGED
@@ -10,6 +10,10 @@ install [Ruby 2.3+](https://www.ruby-lang.org/en/documentation/installation/),
|
|
10
10
|
[Rubygems](https://rubygems.org/pages/download), and
|
11
11
|
then the [gem](https://rubygems.org/gems/zold).
|
12
12
|
|
13
|
+
We recommend to host nodes at
|
14
|
+
[AWS](https://aws.amazon.com/) or
|
15
|
+
[DigitalOcean](https://www.digitalocean.com/).
|
16
|
+
|
13
17
|
## Debian 9.4
|
14
18
|
|
15
19
|
```bash
|
@@ -28,9 +32,9 @@ $ gem install --no-ri --no-rdoc zold
|
|
28
32
|
|
29
33
|
## OSX
|
30
34
|
|
31
|
-
With
|
35
|
+
With [Homebrew](https://brew.sh/) (recommended):
|
32
36
|
|
33
|
-
```
|
37
|
+
```bash
|
34
38
|
$ brew install rbenv ruby-build
|
35
39
|
$ rbenv install 2.5.1
|
36
40
|
$ rbenv global 2.5.1
|
@@ -40,23 +44,32 @@ $ gem install --no-ri --no-rdoc zold
|
|
40
44
|
|
41
45
|
Without homebrew:
|
42
46
|
|
43
|
-
...
|
47
|
+
... please contribute ...
|
44
48
|
|
45
49
|
## Windows
|
46
50
|
|
47
51
|
... please contribute ...
|
48
52
|
|
49
|
-
## CentOS
|
53
|
+
## CentOS 7.5
|
50
54
|
|
51
|
-
|
55
|
+
As a `root` user:
|
56
|
+
|
57
|
+
```bash
|
58
|
+
$ sudo yum install zlib-devel gcc gcc-c++ ruby-devel rubygems ruby
|
59
|
+
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
60
|
+
$ curl -sSL https://get.rvm.io | bash -s stable
|
61
|
+
$ source /etc/profile.d/rvm.sh
|
62
|
+
$ rvm install 2.5.1
|
63
|
+
$ gem install --no-ri --no-rdoc zold
|
64
|
+
```
|
52
65
|
|
53
66
|
## Amazon Linux (AWS EC2 default image)
|
54
67
|
|
55
68
|
```
|
56
|
-
sudo yum install zlib-devel gcc gcc-c++ ruby-devel rubygems ruby
|
57
|
-
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
58
|
-
curl -sSL https://get.rvm.io | bash -s stable
|
59
|
-
source $HOME/.rvm/scripts/rvm
|
60
|
-
rvm install 2.5.1
|
61
|
-
gem install zold
|
69
|
+
$ sudo yum install zlib-devel gcc gcc-c++ ruby-devel rubygems ruby
|
70
|
+
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
|
71
|
+
$ curl -sSL https://get.rvm.io | bash -s stable
|
72
|
+
$ source $HOME/.rvm/scripts/rvm
|
73
|
+
$ rvm install 2.5.1
|
74
|
+
$ gem install --no-ri --no-rdoc zold
|
62
75
|
```
|
data/lib/zold/commands/pay.rb
CHANGED
@@ -57,7 +57,7 @@ Available options:"
|
|
57
57
|
o.bool '--dont-pay-taxes',
|
58
58
|
'Don\'t pay taxes even if the wallet is in debt',
|
59
59
|
default: false
|
60
|
-
o.bool '--
|
60
|
+
o.bool '--skip-propagate',
|
61
61
|
'Don\'t propagate the paying wallet after successful pay',
|
62
62
|
default: false
|
63
63
|
o.bool '--help', 'Print instructions'
|
@@ -82,11 +82,10 @@ Available options:"
|
|
82
82
|
['taxes', "--private-key=#{opts['private-key']}", id.to_s]
|
83
83
|
)
|
84
84
|
end
|
85
|
-
unless opts['dont-propagate']
|
86
|
-
require_relative 'propagate'
|
87
|
-
Propagate.new(wallets: @wallets, log: @log).run(['propagate', id.to_s])
|
88
|
-
end
|
89
85
|
pay(from, invoice, amount, details, opts)
|
86
|
+
return if opts['skip-propagate']
|
87
|
+
require_relative 'propagate'
|
88
|
+
Propagate.new(wallets: @wallets, log: @log).run(['propagate', from.id.to_s])
|
90
89
|
end
|
91
90
|
|
92
91
|
private
|
data/lib/zold/commands/remote.rb
CHANGED
@@ -218,11 +218,6 @@ it's recommended to reboot, but I don't do it because of --never-reboot")
|
|
218
218
|
|
219
219
|
def terminate
|
220
220
|
@log.info("All threads before exit: #{Thread.list.map { |t| "#{t.name}/#{t.status}" }.join(', ')}")
|
221
|
-
Kernel.at_exit do
|
222
|
-
@log.info("About to terminate #{Thread.list.count} threads...")
|
223
|
-
Thread.each(&:exit)
|
224
|
-
@log.info("#{Thread.list.count} threads terminated")
|
225
|
-
end
|
226
221
|
Kernel.exit(0)
|
227
222
|
end
|
228
223
|
end
|
@@ -47,17 +47,18 @@ module Zold
|
|
47
47
|
raise '--bonus-wallet is required to pay bonuses' unless @opts['bonus-wallet']
|
48
48
|
raise '--bonus-amount is required to pay bonuses' unless @opts['bonus-amount']
|
49
49
|
winners = Remote.new(remotes: @remotes, log: @log, farm: @farm).run(
|
50
|
-
['remote', 'elect', @opts['bonus-wallet'], '--private-key', @opts['private-key']]
|
50
|
+
['remote', 'elect', @opts['bonus-wallet'], '--private-key', @opts['private-key']] +
|
51
|
+
(@opts['ignore-score-weakness'] ? ['--ignore-score-weakness'] : [])
|
51
52
|
)
|
52
53
|
return if winners.empty?
|
53
54
|
winners.each do |score|
|
54
55
|
Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
|
55
|
-
['pull', opts['bonus-wallet']]
|
56
|
+
['pull', @opts['bonus-wallet']]
|
56
57
|
)
|
57
58
|
Pay.new(wallets: @wallets, remotes: @remotes, log: @log).run(
|
58
59
|
[
|
59
|
-
'pay', @opts['bonus-wallet'], score.invoice, @opts['bonus-amount'],
|
60
|
-
"Hosting bonus for #{score.host}
|
60
|
+
'pay', @opts['bonus-wallet'], score.invoice, @opts['bonus-amount'].to_s,
|
61
|
+
"Hosting bonus for #{score.host} #{score.port} #{score.value}",
|
61
62
|
'--private-key', @opts['private-key']
|
62
63
|
]
|
63
64
|
)
|
data/lib/zold/node/front.rb
CHANGED
@@ -129,7 +129,7 @@ module Zold
|
|
129
129
|
remotes: settings.remotes.all.count,
|
130
130
|
farm: settings.farm.to_json,
|
131
131
|
entrance: settings.entrance.to_json,
|
132
|
-
date:
|
132
|
+
date: Time.now.utc.iso8601,
|
133
133
|
hours_alive: ((Time.now - settings.start) / (60 * 60)).round(2),
|
134
134
|
home: 'https://www.zold.io'
|
135
135
|
)
|
data/lib/zold/score.rb
CHANGED
@@ -138,6 +138,8 @@ module Zold
|
|
138
138
|
suffixes: @suffixes,
|
139
139
|
strength: @strength,
|
140
140
|
hash: value.zero? ? nil : hash,
|
141
|
+
expired: expired?,
|
142
|
+
valid: valid?,
|
141
143
|
minutes: ((Time.now - @time) / 60).to_i
|
142
144
|
}
|
143
145
|
end
|
@@ -159,6 +161,7 @@ module Zold
|
|
159
161
|
strength: @strength
|
160
162
|
)
|
161
163
|
return score if score.valid?
|
164
|
+
return Score.new(Time.now, @host, @port, @invoice, [], strength: @strength) if score.expired?
|
162
165
|
idx += 1
|
163
166
|
end
|
164
167
|
end
|
data/lib/zold/version.rb
CHANGED
@@ -19,9 +19,13 @@
|
|
19
19
|
# SOFTWARE.
|
20
20
|
|
21
21
|
require 'minitest/autorun'
|
22
|
+
require 'webmock/minitest'
|
22
23
|
require_relative '../../test__helper'
|
23
24
|
require_relative '../../fake_home'
|
25
|
+
require_relative '../../node/fake_node'
|
24
26
|
require_relative '../../../lib/zold/node/farm.rb'
|
27
|
+
require_relative '../../../lib/zold/commands/push'
|
28
|
+
require_relative '../../../lib/zold/commands/pay'
|
25
29
|
require_relative '../../../lib/zold/commands/routines/bonuses.rb'
|
26
30
|
|
27
31
|
# Bonuses test.
|
@@ -30,19 +34,38 @@ require_relative '../../../lib/zold/commands/routines/bonuses.rb'
|
|
30
34
|
# License:: MIT
|
31
35
|
class TestBonuses < Minitest::Test
|
32
36
|
def test_pays_bonuses
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
FakeNode.new(log: test_log).run(['--ignore-score-weakness']) do |port|
|
38
|
+
FakeHome.new.run do |home|
|
39
|
+
bank = home.create_wallet
|
40
|
+
Zold::Pay.new(wallets: home.wallets, remotes: home.remotes, log: test_log).run(
|
41
|
+
['pay', home.create_wallet.id.to_s, bank.id.to_s, '100', '--force', '--private-key=id_rsa']
|
42
|
+
)
|
43
|
+
assert_equal(Zold::Amount.new(zld: 100.0), bank.balance)
|
44
|
+
opts = {
|
45
|
+
'ignore-score-weakness' => true,
|
46
|
+
'routine-immediately' => true,
|
47
|
+
'private-key' => 'id_rsa',
|
48
|
+
'bonus-wallet' => bank.id.to_s,
|
49
|
+
'bonus-amount' => 1
|
50
|
+
}
|
51
|
+
score = Zold::Score.new(Time.now, 'fake-node.local', 999, 'NOPREFIX@ffffffffffffffff', strength: 1)
|
52
|
+
16.times { score = score.next }
|
53
|
+
remotes = home.remotes
|
54
|
+
remotes.add('localhost', port)
|
55
|
+
remotes.add(score.host, score.port)
|
56
|
+
stub_request(:get, "http://#{score.host}:#{score.port}/").to_return(
|
57
|
+
status: 200,
|
58
|
+
body: {
|
59
|
+
version: Zold::VERSION,
|
60
|
+
score: score.to_h
|
61
|
+
}.to_json
|
62
|
+
)
|
63
|
+
Zold::Routines::Bonuses.new(
|
64
|
+
opts, home.wallets, remotes, home.copies(bank).root,
|
65
|
+
Zold::Farm::Empty.new, log: test_log
|
66
|
+
).exec
|
67
|
+
assert_equal(Zold::Amount.new(zld: 99.0), bank.balance)
|
68
|
+
end
|
46
69
|
end
|
47
70
|
end
|
48
71
|
end
|
data/test/test_score.rb
CHANGED
@@ -38,6 +38,17 @@ class TestScore < Minitest::Test
|
|
38
38
|
assert_equal(64, score.hash.length)
|
39
39
|
end
|
40
40
|
|
41
|
+
def test_drops_to_zero_when_expired
|
42
|
+
score = Zold::Score.new(
|
43
|
+
Time.now - 24 * 60 * 60,
|
44
|
+
'some-host', 9999, 'NOPREFIX@ffffffffffffffff',
|
45
|
+
strength: 50
|
46
|
+
).next
|
47
|
+
assert(score.valid?)
|
48
|
+
assert(!score.expired?)
|
49
|
+
assert_equal(0, score.value)
|
50
|
+
end
|
51
|
+
|
41
52
|
def test_validates_wrong_score
|
42
53
|
score = Zold::Score.new(
|
43
54
|
Time.parse('2017-07-19T21:24:51Z'),
|
@@ -108,14 +119,6 @@ class TestScore < Minitest::Test
|
|
108
119
|
assert(!score.expired?)
|
109
120
|
end
|
110
121
|
|
111
|
-
def test_expires_correctly
|
112
|
-
score = Zold::Score.new(
|
113
|
-
Time.now - 100 * 60 * 60, 'localhost', 443,
|
114
|
-
'NOPREFIX@ffffffffffffffff', strength: 2
|
115
|
-
).next.next.next
|
116
|
-
assert(score.expired?)
|
117
|
-
end
|
118
|
-
|
119
122
|
def test_dont_expire_correctly
|
120
123
|
score = Zold::Score.new(
|
121
124
|
Time.now - 10 * 60 * 60, 'localhost', 443,
|
data/test/test_zold.rb
CHANGED
@@ -22,6 +22,7 @@ require 'minitest/autorun'
|
|
22
22
|
require 'tmpdir'
|
23
23
|
require 'English'
|
24
24
|
require_relative 'test__helper'
|
25
|
+
require_relative '../lib/zold/version'
|
25
26
|
|
26
27
|
# Zold main module test.
|
27
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
@@ -52,7 +53,7 @@ class TestZold < Minitest::Test
|
|
52
53
|
|
53
54
|
def test_show_version
|
54
55
|
stdout = exec('--version')
|
55
|
-
assert(stdout.include?(
|
56
|
+
assert(stdout.include?(Zold::VERSION))
|
56
57
|
end
|
57
58
|
|
58
59
|
def test_create_new_wallet
|