sibit 0.19.0 → 0.20.0
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.rb +1 -1
- data/lib/sibit/bestof.rb +5 -4
- data/lib/sibit/btc.rb +10 -1
- 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 +22 -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: 4b0e095b8a42b4036cc160bf0c7cd2d8d80801fb4aa609c34846fe42e711a9a8
|
|
4
|
+
data.tar.gz: 5da2b30520ff7ac48783d6a264c501b8b26dbbcf4934a2927e1b9252803f5666
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b60bbbaf728cc95fc71078096d850f675f2d933ee889a1edb38798f21267ad4e22b7904f786853bcb8c1507aac7a29c3fa195a56d7be5da41d067a6832983c69
|
|
7
|
+
data.tar.gz: fa7e0c793d4e21d151c1e5758b2c2c8f98fdd1aaa92368bf3c70527083185b85a6b2a769a51f56b9a5a24e6105e0fb6eac0cb0d78470d8de7f1eb236b0f46423
|
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.rb
CHANGED
|
@@ -214,13 +214,13 @@ class Sibit
|
|
|
214
214
|
end
|
|
215
215
|
checked += 1
|
|
216
216
|
end
|
|
217
|
+
count += 1
|
|
217
218
|
@log.info("We checked #{checked} txns and #{checked_outputs} outputs in block #{block}")
|
|
218
219
|
block = json[:next]
|
|
219
220
|
if block.nil?
|
|
220
221
|
@log.info("The next_block is empty in block #{json[:hash]}, this is the end of Blockchain")
|
|
221
222
|
break
|
|
222
223
|
end
|
|
223
|
-
count += 1
|
|
224
224
|
if count > max
|
|
225
225
|
@log.info("Too many blocks (#{count}) in one go, let's get back to it next time")
|
|
226
226
|
break
|
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
|
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,
|
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.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: 2020-
|
|
11
|
+
date: 2020-07-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: backtrace
|