sibit 0.19.1 → 0.20.1
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/lib/sibit/bestof.rb +5 -4
- data/lib/sibit/btc.rb +16 -3
- data/lib/sibit/firstof.rb +5 -4
- data/lib/sibit/version.rb +1 -1
- data/test/test_bestof.rb +12 -0
- data/test/test_btc.rb +34 -0
- data/test/test_firstof.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b0578e225f53b1d3904fae19aa6f41ba7aea719bd137587821b3e2fba2a0373
|
|
4
|
+
data.tar.gz: 82178b4a20da5d18d99101649c31ad8fd3188c88a4ea74577cf2413d1bf6f9e2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 756a8a1273e053f4a880220f8d33db38544e36f4a0d38118ee72cc1421d21311900859b9fbac5732c24260a9c48d7599f0865970db27e7046543ad52b2ceb223
|
|
7
|
+
data.tar.gz: 64650acdb47d4671028075dd84e1d3f7f5c8eefb9c67e5b45212e5d6c5aaec1e1576419a126808b20a4e11fc6dc2bd16ea5f473accbb0d1dac936c2896308ecc
|
data/.rultor.yml
CHANGED
|
@@ -5,7 +5,7 @@ install: |
|
|
|
5
5
|
sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
|
|
6
6
|
release:
|
|
7
7
|
script: |-
|
|
8
|
-
bundle exec rake
|
|
8
|
+
bundle exec rake clean test rubocop copyright
|
|
9
9
|
sed -i "s/1\.0\.snapshot/${tag}/g" lib/sibit/version.rb
|
|
10
10
|
git add lib/sibit/version.rb
|
|
11
11
|
git commit -m "version set to ${tag}"
|
|
@@ -14,7 +14,7 @@ release:
|
|
|
14
14
|
gem push *.gem --config-file ../rubygems.yml
|
|
15
15
|
merge:
|
|
16
16
|
script: |-
|
|
17
|
-
bundle exec rake
|
|
17
|
+
bundle exec rake clean test rubocop copyright
|
|
18
18
|
deploy:
|
|
19
19
|
script: |-
|
|
20
20
|
echo "There is nothing to deploy"
|
data/lib/sibit/bestof.rb
CHANGED
|
@@ -32,9 +32,10 @@ class Sibit
|
|
|
32
32
|
# Best of API.
|
|
33
33
|
class BestOf
|
|
34
34
|
# Constructor.
|
|
35
|
-
def initialize(list, log: Sibit::Log.new)
|
|
35
|
+
def initialize(list, log: Sibit::Log.new, verbose: false)
|
|
36
36
|
@list = list
|
|
37
37
|
@log = log
|
|
38
|
+
@verbose = verbose
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
# Current price of BTC in USD (float returned).
|
|
@@ -106,12 +107,12 @@ class Sibit
|
|
|
106
107
|
begin
|
|
107
108
|
results << yield(api)
|
|
108
109
|
rescue Sibit::Error => e
|
|
109
|
-
@log.info("The API #{api.class.name} failed at #{method}(): #{e.message}")
|
|
110
|
+
@log.info("The API #{api.class.name} failed at #{method}(): #{e.message}") if @verbose
|
|
110
111
|
end
|
|
111
112
|
end
|
|
112
113
|
if results.empty?
|
|
113
|
-
raise Sibit::Error, "No APIs out of #{@
|
|
114
|
-
#{@
|
|
114
|
+
raise Sibit::Error, "No APIs out of #{@list.length} managed to succeed at #{method}(): \
|
|
115
|
+
#{@list.map { |a| a.class.name }.join(', ')}"
|
|
115
116
|
end
|
|
116
117
|
results.group_by(&:to_s).values.max_by(&:size)[0]
|
|
117
118
|
end
|
data/lib/sibit/btc.rb
CHANGED
|
@@ -58,7 +58,16 @@ class Sibit
|
|
|
58
58
|
@log.info("The balance of #{address} is zero (not found)")
|
|
59
59
|
return 0
|
|
60
60
|
end
|
|
61
|
-
|
|
61
|
+
data = json['data']
|
|
62
|
+
if data.nil?
|
|
63
|
+
@log.info("The balance of #{address} is probably zero (not found)")
|
|
64
|
+
return 0
|
|
65
|
+
end
|
|
66
|
+
txns = data['list']
|
|
67
|
+
if txns.nil?
|
|
68
|
+
@log.info("The balance of #{address} is probably zero (not found)")
|
|
69
|
+
return 0
|
|
70
|
+
end
|
|
62
71
|
balance = txns.map { |tx| tx['value'] }.inject(&:+) || 0
|
|
63
72
|
@log.info("The balance of #{address} is #{balance}, total txns: #{txns.count}")
|
|
64
73
|
balance
|
|
@@ -164,9 +173,13 @@ class Sibit
|
|
|
164
173
|
psize = 50
|
|
165
174
|
all = []
|
|
166
175
|
loop do
|
|
167
|
-
|
|
176
|
+
data = Sibit::Json.new(http: @http, log: @log).get(
|
|
168
177
|
URI("https://chain.api.btc.com/v3/block/#{hash}/tx?page=#{page}&pagesize=#{psize}")
|
|
169
|
-
)['data']
|
|
178
|
+
)['data']
|
|
179
|
+
raise Sibit::Error, "The block #{hash} has no data at page #{page}" if data.nil?
|
|
180
|
+
list = data['list']
|
|
181
|
+
raise Sibit::Error, "The list is empty for block #{hash} at page #{page}" if list.nil?
|
|
182
|
+
txns = list.map do |t|
|
|
170
183
|
{
|
|
171
184
|
hash: t['hash'],
|
|
172
185
|
outputs: t['outputs'].reject { |o| o['spent_by_tx'] }.map do |o|
|
data/lib/sibit/firstof.rb
CHANGED
|
@@ -32,9 +32,10 @@ class Sibit
|
|
|
32
32
|
# First of API.
|
|
33
33
|
class FirstOf
|
|
34
34
|
# Constructor.
|
|
35
|
-
def initialize(list, log: Sibit::Log.new)
|
|
35
|
+
def initialize(list, log: Sibit::Log.new, verbose: false)
|
|
36
36
|
@list = list
|
|
37
37
|
@log = log
|
|
38
|
+
@verbose = verbose
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
# Current price of BTC in USD (float returned).
|
|
@@ -109,12 +110,12 @@ class Sibit
|
|
|
109
110
|
done = true
|
|
110
111
|
break
|
|
111
112
|
rescue Sibit::Error => e
|
|
112
|
-
@log.info("The API #{api.class.name} failed at #{method}(): #{e.message}")
|
|
113
|
+
@log.info("The API #{api.class.name} failed at #{method}(): #{e.message}") if @verbose
|
|
113
114
|
end
|
|
114
115
|
end
|
|
115
116
|
unless done
|
|
116
|
-
raise Sibit::Error, "No APIs out of #{@
|
|
117
|
-
#{@
|
|
117
|
+
raise Sibit::Error, "No APIs out of #{@list.length} managed to succeed at #{method}(): \
|
|
118
|
+
#{@list.map { |a| a.class.name }.join(', ')}"
|
|
118
119
|
end
|
|
119
120
|
result
|
|
120
121
|
end
|
data/lib/sibit/version.rb
CHANGED
data/test/test_bestof.rb
CHANGED
|
@@ -47,4 +47,16 @@ class TestBestOf < Minitest::Test
|
|
|
47
47
|
assert_equal(64, sibit.latest.length)
|
|
48
48
|
assert_equal(12, sibit.fees[:S])
|
|
49
49
|
end
|
|
50
|
+
|
|
51
|
+
def test_all_fail
|
|
52
|
+
api = Class.new do
|
|
53
|
+
def latest
|
|
54
|
+
raise Sibit::Error, 'intentionally'
|
|
55
|
+
end
|
|
56
|
+
end.new
|
|
57
|
+
sibit = Sibit::BestOf.new([api, api])
|
|
58
|
+
assert_raises Sibit::Error do
|
|
59
|
+
sibit.latest
|
|
60
|
+
end
|
|
61
|
+
end
|
|
50
62
|
end
|
data/test/test_btc.rb
CHANGED
|
@@ -42,6 +42,28 @@ class TestBtc < Minitest::Test
|
|
|
42
42
|
assert_equal(0, balance)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
def test_get_zero_balance_no_txns
|
|
46
|
+
stub_request(
|
|
47
|
+
:get,
|
|
48
|
+
'https://chain.api.btc.com/v3/address/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f/unspent'
|
|
49
|
+
).to_return(body: '{"data":{}}')
|
|
50
|
+
sibit = Sibit::Btc.new
|
|
51
|
+
balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
|
|
52
|
+
assert(balance.is_a?(Integer))
|
|
53
|
+
assert_equal(0, balance)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_get_broken_balance
|
|
57
|
+
stub_request(
|
|
58
|
+
:get,
|
|
59
|
+
'https://chain.api.btc.com/v3/address/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f/unspent'
|
|
60
|
+
).to_return(body: '{}')
|
|
61
|
+
sibit = Sibit::Btc.new
|
|
62
|
+
balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
|
|
63
|
+
assert(balance.is_a?(Integer))
|
|
64
|
+
assert_equal(0, balance)
|
|
65
|
+
end
|
|
66
|
+
|
|
45
67
|
def test_get_empty_balance
|
|
46
68
|
stub_request(
|
|
47
69
|
:get,
|
|
@@ -64,6 +86,18 @@ class TestBtc < Minitest::Test
|
|
|
64
86
|
assert_equal(123, balance)
|
|
65
87
|
end
|
|
66
88
|
|
|
89
|
+
def test_fetch_block_broken
|
|
90
|
+
hash = '000000000000000007341915521967247f1dec17b3a311b8a8f4495392f1439b'
|
|
91
|
+
stub_request(:get, "https://chain.api.btc.com/v3/block/#{hash}")
|
|
92
|
+
.to_return(body: '{"data": {"next_block_hash": "n", "hash": "h", "prev_block_hash": "p"}}')
|
|
93
|
+
stub_request(:get, "https://chain.api.btc.com/v3/block/#{hash}/tx?page=1&pagesize=50")
|
|
94
|
+
.to_return(body: '{}')
|
|
95
|
+
sibit = Sibit::Btc.new
|
|
96
|
+
assert_raises Sibit::Error do
|
|
97
|
+
sibit.block(hash)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
67
101
|
def test_fetch_block
|
|
68
102
|
hash = '000000000000000007341915521967247f1dec17b3a311b8a8f4495392f1439b'
|
|
69
103
|
stub_request(:get, "https://chain.api.btc.com/v3/block/#{hash}")
|
data/test/test_firstof.rb
CHANGED
|
@@ -47,4 +47,16 @@ class TestFirstOf < Minitest::Test
|
|
|
47
47
|
assert_equal(64, sibit.latest.length)
|
|
48
48
|
assert_equal(12, sibit.fees[:S])
|
|
49
49
|
end
|
|
50
|
+
|
|
51
|
+
def test_all_fail
|
|
52
|
+
api = Class.new do
|
|
53
|
+
def latest
|
|
54
|
+
raise Sibit::Error, 'intentionally'
|
|
55
|
+
end
|
|
56
|
+
end.new
|
|
57
|
+
sibit = Sibit::FirstOf.new([api, api])
|
|
58
|
+
assert_raises Sibit::Error do
|
|
59
|
+
sibit.latest
|
|
60
|
+
end
|
|
61
|
+
end
|
|
50
62
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sibit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.20.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-08-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: backtrace
|