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 +4 -4
- data/lib/sibit/bitcoinchain.rb +5 -0
- data/lib/sibit/blockchain.rb +10 -0
- data/lib/sibit/blockchair.rb +5 -0
- data/lib/sibit/btc.rb +10 -0
- data/lib/sibit/cryptoapis.rb +13 -1
- data/lib/sibit/earn.rb +5 -0
- data/lib/sibit/version.rb +1 -1
- data/lib/sibit.rb +3 -1
- data/test/test_live.rb +9 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a146f6b5c827dd0cabc3736c0cf4218c600e80adf6a78ae6ef72665acd5a9d86
|
|
4
|
+
data.tar.gz: 5dff578a3f2889896f6c8869227efe7451ba97df317ded00284d63ee0dab4a75
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1fe6289d3eedbdc45cc2543e498307f4aa7cfe7b1b1951549d827f5ebd9ce96f659818d6672ad21f57aa0b2856f189ea042e604d65ad40422bb4ae909976d9f2
|
|
7
|
+
data.tar.gz: b76f16791ef4140beac79b9650c6677d22127604592747b43fb9ca1c8b3e1d94faeea868d959aa74fe8debfe8637fe01340f7d0604015646b9a4865a34cff301
|
data/lib/sibit/bitcoinchain.rb
CHANGED
|
@@ -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(
|
data/lib/sibit/blockchain.rb
CHANGED
|
@@ -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(
|
data/lib/sibit/blockchair.rb
CHANGED
|
@@ -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'
|
data/lib/sibit/cryptoapis.rb
CHANGED
|
@@ -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, '
|
|
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
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
|
-
|
|
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('
|
|
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'
|