sibit 0.18.4 → 0.18.5

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: 9190dd104e8af92e3a5d8f1f6a967ef5d001fcf47e51adbaf260a281ecf043a5
4
- data.tar.gz: f6b2280a10d118ad474b02022ad428de4c5775632c8f98a7f552c100ddb25460
3
+ metadata.gz: 9f85d6af8efe3b90b84fd7a5756ebda0c31ed50da36cc9a264424a531c8a8b10
4
+ data.tar.gz: 8008c7deb9d9981a7a0fc8b959effb2eb4d77b4fd58080e9a0e7a8b2df9476bd
5
5
  SHA512:
6
- metadata.gz: 863c1ce07d8c74d1029d29a27711244e12350d23f2cdcdc0da21a41793fdd98ce5685a8a725814c691d633e65e6d6858aa1cc716382a4465f93973df773a802c
7
- data.tar.gz: 4b7556e9a790db63e63c2cdb0b836b8e3a7f1a9153cb1eba18f722c701b460c379ccda784feb40773f627e78f8129ef78ca7d2e9648431ecaa3608ef6409c89f
6
+ metadata.gz: ea92cf18899819136b9ff0f4a7e8a1fae200a70633e79e9dcfdb01006c42518757577f0105f3b7e78604275b0a38cf23ee37a2f5758c2caddb6add807032305d
7
+ data.tar.gz: 7e2cfe391ea6862616eb475c09ca5a7fb86cc92d95c1366dc56c4d32dba4d3d8fa1d6974d36b0e52ed1eee60658ff82d0fca0ccf56042ed4ce3dcb31781025b9
@@ -236,6 +236,7 @@ class Sibit
236
236
  break
237
237
  end
238
238
  end
239
+ @log.info("Scanned from #{start} to #{json[:hash]} (#{count} blocks)")
239
240
  json[:hash]
240
241
  end
241
242
 
@@ -45,21 +45,24 @@ class Sibit
45
45
 
46
46
  # Current price of BTC in USD (float returned).
47
47
  def price(_currency = 'USD')
48
- raise Sibit::Error, 'Bitcoinchain API doesn\'t provide BTC price'
48
+ raise Sibit::NotSupportedError, 'Bitcoinchain API doesn\'t provide BTC price'
49
49
  end
50
50
 
51
51
  # The height of the block.
52
52
  def height(_hash)
53
- raise Sibit::Error, 'Bitcoinchain API doesn\'t provide height()'
53
+ raise Sibit::NotSupportedError, 'Bitcoinchain API doesn\'t provide height()'
54
54
  end
55
55
 
56
56
  # Get hash of the block after this one.
57
57
  def next_of(hash)
58
- nxt = Sibit::Json.new(http: @http, log: @log).get(
58
+ block = Sibit::Json.new(http: @http, log: @log).get(
59
59
  URI("https://api-r.bitcoinchain.com/v1/block/#{hash}")
60
- )[0]['next_block']
60
+ )[0]
61
+ raise Sibit::Error, "Block #{hash} not found" if block.nil?
62
+ nxt = block['next_block']
61
63
  nxt = nil if nxt == '0000000000000000000000000000000000000000000000000000000000000000'
62
- @log.info("The next block of #{hash} is #{nxt}")
64
+ @log.info("The block #{hash} is the latest, there is no next block") if nxt.nil?
65
+ @log.info("The next block of #{hash} is #{nxt}") unless nxt.nil?
63
66
  nxt
64
67
  end
65
68
 
@@ -76,13 +79,13 @@ class Sibit
76
79
  end
77
80
  b *= 100_000_000
78
81
  b = b.to_i
79
- @log.info("The balance of #{address} is #{b} satoshi")
82
+ @log.info("The balance of #{address} is #{b} satoshi (#{json['transactions']} txns)")
80
83
  b
81
84
  end
82
85
 
83
86
  # Get recommended fees, in satoshi per byte.
84
87
  def fees
85
- raise Sibit::Error, 'Not implemented yet'
88
+ raise Sibit::NotSupportedError, 'Not implemented yet'
86
89
  end
87
90
 
88
91
  # Gets the hash of the latest block.
@@ -96,12 +99,12 @@ class Sibit
96
99
 
97
100
  # Fetch all unspent outputs per address.
98
101
  def utxos(_sources)
99
- raise Sibit::Error, 'Not implemented yet'
102
+ raise Sibit::NotSupportedError, 'Not implemented yet'
100
103
  end
101
104
 
102
105
  # Push this transaction (in hex format) to the network.
103
106
  def push(_hex)
104
- raise Sibit::Error, 'Not implemented yet'
107
+ raise Sibit::NotSupportedError, 'Not implemented yet'
105
108
  end
106
109
 
107
110
  # This method should fetch a Blockchain block and return as a hash. Raises
@@ -59,7 +59,7 @@ class Sibit
59
59
 
60
60
  # Get hash of the block after this one.
61
61
  def next_of(_hash)
62
- raise Sibit::Error, 'Blockchain API doesn\'t provide next_of()'
62
+ raise Sibit::NotSupportedError, 'Blockchain API doesn\'t provide next_of()'
63
63
  end
64
64
 
65
65
  # The height of the block.
@@ -78,13 +78,14 @@ class Sibit
78
78
  URI("https://blockchain.info/rawaddr/#{address}?limit=0"),
79
79
  accept: [200, 500]
80
80
  )
81
- @log.info("Received/sent: #{json['total_received']}/#{json['total_sent']}")
82
- json['final_balance']
81
+ b = json['final_balance']
82
+ @log.info("The balance of #{address} is #{b} satoshi (#{json['n_tx']} txns)")
83
+ b
83
84
  end
84
85
 
85
86
  # Get recommended fees.
86
87
  def fees
87
- raise Sibit::Error, 'fees() is not provided by Blockchain API'
88
+ raise Sibit::NotSupportedError, 'fees() is not provided by Blockchain API'
88
89
  end
89
90
 
90
91
  # Fetch all unspent outputs per address. The argument is an array
@@ -47,18 +47,18 @@ class Sibit
47
47
 
48
48
  # Current price of BTC in USD (float returned).
49
49
  def price(_currency = 'USD')
50
- raise Sibit::Error, 'Blockchair doesn\'t provide BTC price'
50
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t provide BTC price'
51
51
  end
52
52
 
53
53
  # The height of the block.
54
54
  def height(_hash)
55
- raise Sibit::Error, 'Blockchair API doesn\'t provide height()'
55
+ raise Sibit::NotSupportedError, 'Blockchair API doesn\'t provide height()'
56
56
  end
57
57
 
58
58
  # Get hash of the block after this one.
59
59
  def next_of(_hash)
60
60
  # They don't provide next block hash
61
- raise Sibit::Error, 'Blockchair API doesn\'t provide next_of()'
61
+ raise Sibit::NotSupportedError, 'Blockchair API doesn\'t provide next_of()'
62
62
  end
63
63
 
64
64
  # Gets the balance of the address, in satoshi.
@@ -70,24 +70,25 @@ class Sibit
70
70
  @log.info("Address #{address} not found")
71
71
  return 0
72
72
  end
73
- b = json['address']['balance']
74
- @log.info("The balance of #{address} is #{b} satoshi")
73
+ a = json['address']
74
+ b = a['balance']
75
+ @log.info("The balance of #{address} is #{b} satoshi (#{a['transactions'].length} txns)")
75
76
  b
76
77
  end
77
78
 
78
79
  # Get recommended fees, in satoshi per byte.
79
80
  def fees
80
- raise Sibit::Error, 'Blockchair doesn\'t implement fees()'
81
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement fees()'
81
82
  end
82
83
 
83
84
  # Gets the hash of the latest block.
84
85
  def latest
85
- raise Sibit::Error, 'Blockchair doesn\'t implement latest()'
86
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement latest()'
86
87
  end
87
88
 
88
89
  # Fetch all unspent outputs per address.
89
90
  def utxos(_sources)
90
- raise Sibit::Error, 'Blockchair doesn\'t implement utxos()'
91
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement utxos()'
91
92
  end
92
93
 
93
94
  # Push this transaction (in hex format) to the network.
@@ -101,7 +102,7 @@ class Sibit
101
102
 
102
103
  # This method should fetch a Blockchain block and return as a hash.
103
104
  def block(_hash)
104
- raise Sibit::Error, 'Blockchair doesn\'t implement block()'
105
+ raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement block()'
105
106
  end
106
107
 
107
108
  private
@@ -47,7 +47,7 @@ class Sibit
47
47
 
48
48
  # Current price of BTC in USD (float returned).
49
49
  def price(_currency = 'USD')
50
- raise Sibit::Error, 'Btc.com API doesn\'t provide prices'
50
+ raise Sibit::NotSupportedError, 'Btc.com API doesn\'t provide prices'
51
51
  end
52
52
 
53
53
  # Gets the balance of the address, in satoshi.
@@ -71,7 +71,8 @@ class Sibit
71
71
  )
72
72
  nxt = head['data']['next_block_hash']
73
73
  nxt = nil if nxt == '0000000000000000000000000000000000000000000000000000000000000000'
74
- @log.info("The next block of #{hash} is #{nxt}")
74
+ @log.info("The block #{hash} is the latest, there is no next block") if nxt.nil?
75
+ @log.info("The next block of #{hash} is #{nxt}") unless nxt.nil?
75
76
  nxt
76
77
  end
77
78
 
@@ -87,7 +88,7 @@ class Sibit
87
88
 
88
89
  # Get recommended fees, in satoshi per byte.
89
90
  def fees
90
- raise Sibit::Error, 'Btc.com doesn\'t provide recommended fees'
91
+ raise Sibit::NotSupportedError, 'Btc.com doesn\'t provide recommended fees'
91
92
  end
92
93
 
93
94
  # Gets the hash of the latest block.
@@ -127,7 +128,7 @@ class Sibit
127
128
 
128
129
  # Push this transaction (in hex format) to the network.
129
130
  def push(_hex)
130
- raise Sibit::Error, 'Btc.com doesn\'t provide payment gateway'
131
+ raise Sibit::NotSupportedError, 'Btc.com doesn\'t provide payment gateway'
131
132
  end
132
133
 
133
134
  # This method should fetch a Blockchain block and return as a hash.
@@ -54,41 +54,41 @@ class Sibit
54
54
 
55
55
  # Get hash of the block after this one.
56
56
  def next_of(_hash)
57
- raise Sibit::Error, 'Cex.io API doesn\'t provide next_of()'
57
+ raise Sibit::NotSupportedError, 'Cex.io API doesn\'t provide next_of()'
58
58
  end
59
59
 
60
60
  # Gets the balance of the address, in satoshi.
61
61
  def balance(_address)
62
- raise Sibit::Error, 'Cex.io doesn\'t implement balance()'
62
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement balance()'
63
63
  end
64
64
 
65
65
  # The height of the block.
66
66
  def height(_hash)
67
- raise Sibit::Error, 'Cex.io doesn\'t implement height()'
67
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement height()'
68
68
  end
69
69
 
70
70
  # Get recommended fees, in satoshi per byte.
71
71
  def fees
72
- raise Sibit::Error, 'Cex.io doesn\'t implement fees()'
72
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement fees()'
73
73
  end
74
74
 
75
75
  # Gets the hash of the latest block.
76
76
  def latest
77
- raise Sibit::Error, 'Cex.io doesn\'t implement latest()'
77
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement latest()'
78
78
  end
79
79
 
80
80
  # Fetch all unspent outputs per address.
81
81
  def utxos(_sources)
82
- raise Sibit::Error, 'Cex.io doesn\'t implement utxos()'
82
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement utxos()'
83
83
  end
84
84
 
85
85
  # Push this transaction (in hex format) to the network.
86
86
  def push(_hex)
87
- raise Sibit::Error, 'Cex.io doesn\'t implement push()'
87
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement push()'
88
88
  end
89
89
 
90
90
  def block(_hash)
91
- raise Sibit::Error, 'Cex.io doesn\'t implement block()'
91
+ raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement block()'
92
92
  end
93
93
  end
94
94
  end
@@ -46,15 +46,18 @@ class Sibit
46
46
 
47
47
  # Current price of BTC in USD (float returned).
48
48
  def price(_currency = 'USD')
49
- raise Sibit::Error, 'Cryptoapis doesn\'t provide BTC price'
49
+ raise Sibit::NotSupportedError, 'Cryptoapis doesn\'t provide BTC price'
50
50
  end
51
51
 
52
52
  # Get hash of the block after this one.
53
53
  def next_of(hash)
54
- Sibit::Json.new(http: @http, log: @log).get(
54
+ nxt = Sibit::Json.new(http: @http, log: @log).get(
55
55
  URI("https://api.cryptoapis.io/v1/bc/btc/mainnet/blocks/#{hash}"),
56
56
  headers: headers
57
57
  )['payload']['hash']
58
+ @log.info("The block #{hash} is the latest, there is no next block") if nxt.nil?
59
+ @log.info("The next block of #{hash} is #{nxt}") unless nxt.nil?
60
+ nxt
58
61
  end
59
62
 
60
63
  # The height of the block.
@@ -81,7 +84,7 @@ class Sibit
81
84
 
82
85
  # Get recommended fees, in satoshi per byte.
83
86
  def fees
84
- raise Sibit::Error, 'Cryptoapis doesn\'t provide recommended fees'
87
+ raise Sibit::NotSupportedError, 'Cryptoapis doesn\'t provide recommended fees'
85
88
  end
86
89
 
87
90
  # Gets the hash of the latest block.
@@ -96,7 +99,7 @@ class Sibit
96
99
 
97
100
  # Fetch all unspent outputs per address.
98
101
  def utxos(_sources)
99
- raise Sibit::Error, 'Not implemented yet'
102
+ raise Sibit::NotSupportedError, 'Not implemented yet'
100
103
  end
101
104
 
102
105
  # Push this transaction (in hex format) to the network.
@@ -44,22 +44,22 @@ class Sibit
44
44
 
45
45
  # Current price of BTC in USD (float returned).
46
46
  def price(_currency)
47
- raise Sibit::Error, 'price() doesn\'t work here'
47
+ raise Sibit::NotSupportedError, 'price() doesn\'t work here'
48
48
  end
49
49
 
50
50
  # Gets the balance of the address, in satoshi.
51
51
  def balance(_address)
52
- raise Sibit::Error, 'balance() doesn\'t work here'
52
+ raise Sibit::NotSupportedError, 'balance() doesn\'t work here'
53
53
  end
54
54
 
55
55
  # Get hash of the block after this one.
56
56
  def next_of(_hash)
57
- raise Sibit::Error, 'Earn.com API doesn\'t provide next_of()'
57
+ raise Sibit::NotSupportedError, 'Earn.com API doesn\'t provide next_of()'
58
58
  end
59
59
 
60
60
  # The height of the block.
61
61
  def height(_hash)
62
- raise Sibit::Error, 'Earn API doesn\'t provide height()'
62
+ raise Sibit::NotSupportedError, 'Earn API doesn\'t provide height()'
63
63
  end
64
64
 
65
65
  # Get recommended fees, in satoshi per byte. The method returns
@@ -80,22 +80,22 @@ class Sibit
80
80
 
81
81
  # Fetch all unspent outputs per address.
82
82
  def utxos(_sources)
83
- raise Sibit::Error, 'Not implemented yet'
83
+ raise Sibit::NotSupportedError, 'Not implemented yet'
84
84
  end
85
85
 
86
86
  # Push this transaction (in hex format) to the network.
87
87
  def push(_hex)
88
- raise Sibit::Error, 'Not implemented yet'
88
+ raise Sibit::NotSupportedError, 'Not implemented yet'
89
89
  end
90
90
 
91
91
  # Gets the hash of the latest block.
92
92
  def latest
93
- raise Sibit::Error, 'latest() doesn\'t work here'
93
+ raise Sibit::NotSupportedError, 'latest() doesn\'t work here'
94
94
  end
95
95
 
96
96
  # This method should fetch a Blockchain block and return as a hash.
97
97
  def block(_hash)
98
- raise Sibit::Error, 'block() doesn\'t work here'
98
+ raise Sibit::NotSupportedError, 'block() doesn\'t work here'
99
99
  end
100
100
  end
101
101
  end
@@ -28,4 +28,7 @@
28
28
  class Sibit
29
29
  # The error.
30
30
  class Error < StandardError; end
31
+
32
+ # The operation is not supported.
33
+ class NotSupportedError < Error; end
31
34
  end
@@ -26,5 +26,5 @@
26
26
  # License:: MIT
27
27
  class Sibit
28
28
  # Current version of the library.
29
- VERSION = '0.18.4'
29
+ VERSION = '0.18.5'
30
30
  end
@@ -36,9 +36,9 @@ Gem::Specification.new do |s|
36
36
  s.version = Sibit::VERSION
37
37
  s.license = 'MIT'
38
38
  s.summary = 'Simple Bitcoin Client'
39
- s.description = 'This is a simple Bitcoin client, to use from command line \
40
- or from your Ruby app. You don\'t need to run any Bitcoin software, \
41
- no need to install anything, etc. All you need is just a command line \
39
+ s.description = 'This is a simple Bitcoin client, to use from command line
40
+ or from your Ruby app. You don\'t need to run any Bitcoin software,
41
+ no need to install anything, etc. All you need is just a command line
42
42
  and Ruby 2.3+.'
43
43
  s.authors = ['Yegor Bugayenko']
44
44
  s.email = 'yegor256@gmail.com'
@@ -34,7 +34,8 @@ class TestBlockchair < Minitest::Test
34
34
  def test_fetch_balance
35
35
  hash = '1GkQmKAmHtNfnD3LHhTkewJxKHVSta4m2a'
36
36
  stub_request(:get, "https://api.blockchair.com/bitcoin/dashboards/address/#{hash}")
37
- .to_return(body: "{\"data\": {\"#{hash}\": {\"address\": {\"balance\": 1}}}}")
37
+ .to_return(body: "{\"data\": {\"#{hash}\": {\"address\":
38
+ {\"balance\": 1, \"transactions\": []}}}}")
38
39
  sibit = Sibit::Blockchair.new
39
40
  satoshi = sibit.balance(hash)
40
41
  assert_equal(1, satoshi)
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.18.4
4
+ version: 0.18.5
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-03-27 00:00:00.000000000 Z
11
+ date: 2020-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -249,9 +249,9 @@ dependencies:
249
249
  - !ruby/object:Gem::Version
250
250
  version: 3.7.6
251
251
  description: |-
252
- This is a simple Bitcoin client, to use from command line \
253
- or from your Ruby app. You don't need to run any Bitcoin software, \
254
- no need to install anything, etc. All you need is just a command line \
252
+ This is a simple Bitcoin client, to use from command line
253
+ or from your Ruby app. You don't need to run any Bitcoin software,
254
+ no need to install anything, etc. All you need is just a command line
255
255
  and Ruby 2.3+.
256
256
  email: yegor256@gmail.com
257
257
  executables: