sibit 0.13.0 → 0.13.1
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/blockchain.rb +3 -1
- data/lib/sibit/btc.rb +6 -1
- data/lib/sibit/version.rb +1 -1
- data/test/test_btc.rb +11 -0
- 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: 217f15565505e50e8f5d019458edb7a1ced3ae311d3aa8a3600ee9c00f9636fe
|
|
4
|
+
data.tar.gz: c98b24bb8acdb59652eea6eab03397487ee0e9be66e9791fac3a2397b5a108fc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad0fa1e2cc7589eb8f0016b7ba8735750e033dbf1dd8776f6b6ac0e7e2acbb5f8ae4d6d69918cb35fb1031ab1218b4523cc6c6e27602cb29d0643d9bb990b9a8
|
|
7
|
+
data.tar.gz: 43fc86116a93558807dfea80b9af201a9958c2b5a788309287a72591d9e44bfdb6abf6441d8a6ea3fce952a2a5168c191b1500732b8ac8a5fa8bb03c3b906fd3
|
data/lib/sibit/blockchain.rb
CHANGED
|
@@ -52,7 +52,9 @@ class Sibit
|
|
|
52
52
|
URI('https://blockchain.info/ticker')
|
|
53
53
|
)[currency]
|
|
54
54
|
raise Error, "Unrecognized currency #{currency}" if h.nil?
|
|
55
|
-
h['15m']
|
|
55
|
+
price = h['15m']
|
|
56
|
+
@log.info("The price of BTC is #{price} USD")
|
|
57
|
+
price
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
# Gets the balance of the address, in satoshi.
|
data/lib/sibit/btc.rb
CHANGED
|
@@ -52,7 +52,12 @@ class Sibit
|
|
|
52
52
|
def balance(address)
|
|
53
53
|
uri = URI("https://chain.api.btc.com/v3/address/#{address}/unspent")
|
|
54
54
|
json = Sibit::Json.new(http: @http, log: @log).get(uri)
|
|
55
|
-
|
|
55
|
+
data = json['data']
|
|
56
|
+
if data.nil?
|
|
57
|
+
@log.info("The balance of #{address} is zero (not found)")
|
|
58
|
+
return 0
|
|
59
|
+
end
|
|
60
|
+
txns = data['list']
|
|
56
61
|
balance = txns.map { |tx| tx['value'] }.inject(&:+) || 0
|
|
57
62
|
@log.info("The balance of #{address} is #{balance}, total txns: #{txns.count}")
|
|
58
63
|
balance
|
data/lib/sibit/version.rb
CHANGED
data/test/test_btc.rb
CHANGED
|
@@ -42,6 +42,17 @@ class TestBtc < Minitest::Test
|
|
|
42
42
|
assert_equal(0, balance)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
def test_get_empty_balance
|
|
46
|
+
stub_request(
|
|
47
|
+
:get,
|
|
48
|
+
'https://chain.api.btc.com/v3/address/1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f/unspent'
|
|
49
|
+
).to_return(body: '{"data":null,"err_no":1,"err_msg":"Resource Not Found"}')
|
|
50
|
+
sibit = Sibit::Btc.new
|
|
51
|
+
balance = sibit.balance('1MZT1fa6y8H9UmbZV6HqKF4UY41o9MGT5f')
|
|
52
|
+
assert(balance.is_a?(Integer))
|
|
53
|
+
assert_equal(0, balance)
|
|
54
|
+
end
|
|
55
|
+
|
|
45
56
|
def test_get_balance
|
|
46
57
|
stub_request(
|
|
47
58
|
:get,
|