sibit 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c16c2d9c8fd8acd2635dc38d1b97599dc2138851ffc162db62aa3dc35feec993
4
- data.tar.gz: b17f0c383453182402041ac8793eb2e308480b660e4bd79577a846a6517cf66e
3
+ metadata.gz: 4b0e095b8a42b4036cc160bf0c7cd2d8d80801fb4aa609c34846fe42e711a9a8
4
+ data.tar.gz: 5da2b30520ff7ac48783d6a264c501b8b26dbbcf4934a2927e1b9252803f5666
5
5
  SHA512:
6
- metadata.gz: 3a7234573110a1fd17ed0e67257474f5c07801e0fd74a0212ca1e08453e9088aeae00b803382814119b9e16fe1b22a9f2fab1974724fdc5c1f5f0d11649e5e29
7
- data.tar.gz: '089e4b96cf9c5fb0b3e17bd1692e9ee66f553c2752fd8669a520008a533dacc60063c473264f0469d394a5c272209419026f4920dfa3f3f97bbfc422fe359751'
6
+ metadata.gz: b60bbbaf728cc95fc71078096d850f675f2d933ee889a1edb38798f21267ad4e22b7904f786853bcb8c1507aac7a29c3fa195a56d7be5da41d067a6832983c69
7
+ data.tar.gz: fa7e0c793d4e21d151c1e5758b2c2c8f98fdd1aaa92368bf3c70527083185b85a6b2a769a51f56b9a5a24e6105e0fb6eac0cb0d78470d8de7f1eb236b0f46423
@@ -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"
@@ -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
@@ -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 #{@api.length} managed to succeed at #{method}(): \
114
- #{@api.map { |a| a.class.name }.join(', ')}"
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
@@ -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
- txns = json['data']['list']
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
@@ -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 #{@api.length} managed to succeed at #{method}(): \
117
- #{@api.map { |a| a.class.name }.join(', ')}"
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
@@ -26,5 +26,5 @@
26
26
  # License:: MIT
27
27
  class Sibit
28
28
  # Current version of the library.
29
- VERSION = '0.19.0'
29
+ VERSION = '0.20.0'
30
30
  end
@@ -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
@@ -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,
@@ -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.19.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-06-17 00:00:00.000000000 Z
11
+ date: 2020-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace