sibit 0.16.1 → 0.17.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ff1fd9e3917932468cb14ce7d91e23b9b086fb46fee75a828c1a6eed9631a57
4
- data.tar.gz: 9833b8986c31a248beba236cd4cb11da0e36a723553d187afa31a6634be4f2c5
3
+ metadata.gz: a146f6b5c827dd0cabc3736c0cf4218c600e80adf6a78ae6ef72665acd5a9d86
4
+ data.tar.gz: 5dff578a3f2889896f6c8869227efe7451ba97df317ded00284d63ee0dab4a75
5
5
  SHA512:
6
- metadata.gz: 7f29c08168ed4a9a0eeebef06ec5a425878401cfee1daa8409d5858fd1eb33b3cb17484fdeccbf1db5a22e3c3573a053fdbc7cc74cb9328d69c495ccec235064
7
- data.tar.gz: b7c6f33191f5aa9dc9fd26b1e2a8154af9e7c6cae2c26f26c0700b25a86ca984b61250e55ebf7ee4b9c473a714ad74ac1d917d276db178f8c4ddf58ee66f4a9f
6
+ metadata.gz: 1fe6289d3eedbdc45cc2543e498307f4aa7cfe7b1b1951549d827f5ebd9ce96f659818d6672ad21f57aa0b2856f189ea042e604d65ad40422bb4ae909976d9f2
7
+ data.tar.gz: b76f16791ef4140beac79b9650c6677d22127604592747b43fb9ca1c8b3e1d94faeea868d959aa74fe8debfe8637fe01340f7d0604015646b9a4865a34cff301
@@ -48,6 +48,11 @@ class Sibit
48
48
  raise Sibit::Error, 'Bitcoinchain API doesn\'t provide BTC price'
49
49
  end
50
50
 
51
+ # The height of the block.
52
+ def height(_hash)
53
+ raise Sibit::Error, 'Bitcoinchain API doesn\'t provide height()'
54
+ end
55
+
51
56
  # Gets the balance of the address, in satoshi.
52
57
  def balance(address)
53
58
  json = Sibit::Json.new(http: @http, log: @log).get(
@@ -57,6 +57,16 @@ class Sibit
57
57
  price
58
58
  end
59
59
 
60
+ # The height of the block.
61
+ def height(hash)
62
+ json = Sibit::Json.new(http: @http, log: @log).get(
63
+ URI("https://blockchain.info/rawblock/#{hash}")
64
+ )
65
+ h = json['height']
66
+ @log.info("The height of #{hash} is #{h}")
67
+ h
68
+ end
69
+
60
70
  # Gets the balance of the address, in satoshi.
61
71
  def balance(address)
62
72
  json = Sibit::Json.new(http: @http, log: @log).get(
@@ -50,6 +50,11 @@ class Sibit
50
50
  raise Sibit::Error, 'Blockchair doesn\'t provide BTC price'
51
51
  end
52
52
 
53
+ # The height of the block.
54
+ def height(_hash)
55
+ raise Sibit::Error, 'Blockchair API doesn\'t provide height()'
56
+ end
57
+
53
58
  # Gets the balance of the address, in satoshi.
54
59
  def balance(address)
55
60
  json = Sibit::Json.new(http: @http, log: @log).get(
data/lib/sibit/btc.rb CHANGED
@@ -63,6 +63,16 @@ class Sibit
63
63
  balance
64
64
  end
65
65
 
66
+ # The height of the block.
67
+ def height(hash)
68
+ json = Sibit::Json.new(http: @http, log: @log).get(
69
+ URI("https://chain.api.btc.com/v3/block/#{hash}")
70
+ )
71
+ h = json['data']['height']
72
+ @log.info("The height of #{hash} is #{h}")
73
+ h
74
+ end
75
+
66
76
  # Get recommended fees, in satoshi per byte.
67
77
  def fees
68
78
  raise Sibit::Error, 'Btc.com doesn\'t provide recommended fees'
@@ -49,6 +49,17 @@ class Sibit
49
49
  raise Sibit::Error, 'Cryptoapis doesn\'t provide BTC price'
50
50
  end
51
51
 
52
+ # The height of the block.
53
+ def height(hash)
54
+ json = Sibit::Json.new(http: @http, log: @log).get(
55
+ URI("https://api.cryptoapis.io/v1/bc/btc/mainnet/blocks/#{hash}"),
56
+ headers: headers
57
+ )['payload']
58
+ h = json['height']
59
+ @log.info("The height of #{hash} is #{h}")
60
+ h
61
+ end
62
+
52
63
  # Gets the balance of the address, in satoshi.
53
64
  def balance(address)
54
65
  json = Sibit::Json.new(http: @http, log: @log).get(
@@ -62,7 +73,7 @@ class Sibit
62
73
 
63
74
  # Get recommended fees, in satoshi per byte.
64
75
  def fees
65
- raise Sibit::Error, 'Not implemented yet'
76
+ raise Sibit::Error, 'Cryptoapis doesn\'t provide recommended fees'
66
77
  end
67
78
 
68
79
  # Gets the hash of the latest block.
@@ -107,6 +118,7 @@ class Sibit
107
118
  private
108
119
 
109
120
  def headers
121
+ return {} if @key.nil? || @key.empty?
110
122
  {
111
123
  'X-API-Key': @key
112
124
  }
data/lib/sibit/earn.rb CHANGED
@@ -52,6 +52,11 @@ class Sibit
52
52
  raise Sibit::Error, 'balance() doesn\'t work here'
53
53
  end
54
54
 
55
+ # The height of the block.
56
+ def height(_hash)
57
+ raise Sibit::Error, 'Earn API doesn\'t provide height()'
58
+ end
59
+
55
60
  # Get recommended fees, in satoshi per byte. The method returns
56
61
  # a hash: { S: 12, M: 45, L: 100, XL: 200 }
57
62
  def fees
data/lib/sibit/version.rb CHANGED
@@ -26,5 +26,5 @@
26
26
  # License:: MIT
27
27
  class Sibit
28
28
  # Current version of the library.
29
- VERSION = '0.16.1'
29
+ VERSION = '0.17.0'
30
30
  end
data/lib/sibit.rb CHANGED
@@ -258,7 +258,9 @@ class Sibit
258
258
  # Convert text to amount.
259
259
  def satoshi(amount)
260
260
  return amount if amount.is_a?(Integer)
261
- raise Error, 'Amount should either be a String or Integer' unless amount.is_a?(String)
261
+ unless amount.is_a?(String)
262
+ raise Error, "Amount should either be a String or Integer, #{amount.class.name} provided"
263
+ end
262
264
  return (amount.gsub(/BTC$/, '').to_f * 100_000_000).to_i if amount.end_with?('BTC')
263
265
  raise Error, "Can't understand the amount #{amount.inspect}"
264
266
  end
data/test/test_live.rb CHANGED
@@ -67,6 +67,14 @@ class TestLive < Minitest::Test
67
67
  end
68
68
  end
69
69
 
70
+ def test_height
71
+ for_each do |api|
72
+ hash = '000000003031a0e73735690c5a1ff2a4be82553b2a12b776fbd3a215dc8f778d'
73
+ height = api.height(hash)
74
+ assert_equal(6, height)
75
+ end
76
+ end
77
+
70
78
  def test_utxos
71
79
  for_each do |api|
72
80
  json = api.utxos(['12fCwqBN4XsHq4iu2Wbfgq5e8YhqEGP3ee'])
@@ -87,7 +95,7 @@ class TestLive < Minitest::Test
87
95
  require_relative '../lib/sibit/blockchair'
88
96
  apis << Sibit::Blockchair.new
89
97
  require_relative '../lib/sibit/cryptoapis'
90
- apis << Sibit::Cryptoapis.new('-key-')
98
+ apis << Sibit::Cryptoapis.new('')
91
99
  require_relative '../lib/sibit/btc'
92
100
  apis << Sibit::Btc.new
93
101
  require_relative '../lib/sibit/bitcoinchain'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko