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 +4 -4
- data/lib/sibit.rb +1 -0
- data/lib/sibit/bitcoinchain.rb +12 -9
- data/lib/sibit/blockchain.rb +5 -4
- data/lib/sibit/blockchair.rb +10 -9
- data/lib/sibit/btc.rb +5 -4
- data/lib/sibit/cex.rb +8 -8
- data/lib/sibit/cryptoapis.rb +7 -4
- data/lib/sibit/earn.rb +8 -8
- data/lib/sibit/error.rb +3 -0
- data/lib/sibit/version.rb +1 -1
- data/sibit.gemspec +3 -3
- data/test/test_blockchair.rb +2 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f85d6af8efe3b90b84fd7a5756ebda0c31ed50da36cc9a264424a531c8a8b10
|
4
|
+
data.tar.gz: 8008c7deb9d9981a7a0fc8b959effb2eb4d77b4fd58080e9a0e7a8b2df9476bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea92cf18899819136b9ff0f4a7e8a1fae200a70633e79e9dcfdb01006c42518757577f0105f3b7e78604275b0a38cf23ee37a2f5758c2caddb6add807032305d
|
7
|
+
data.tar.gz: 7e2cfe391ea6862616eb475c09ca5a7fb86cc92d95c1366dc56c4d32dba4d3d8fa1d6974d36b0e52ed1eee60658ff82d0fca0ccf56042ed4ce3dcb31781025b9
|
data/lib/sibit.rb
CHANGED
data/lib/sibit/bitcoinchain.rb
CHANGED
@@ -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::
|
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::
|
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
|
-
|
58
|
+
block = Sibit::Json.new(http: @http, log: @log).get(
|
59
59
|
URI("https://api-r.bitcoinchain.com/v1/block/#{hash}")
|
60
|
-
)[0]
|
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
|
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::
|
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::
|
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::
|
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
|
data/lib/sibit/blockchain.rb
CHANGED
@@ -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::
|
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
|
-
|
82
|
-
json['
|
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::
|
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
|
data/lib/sibit/blockchair.rb
CHANGED
@@ -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::
|
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::
|
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::
|
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
|
-
|
74
|
-
|
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::
|
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::
|
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::
|
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::
|
105
|
+
raise Sibit::NotSupportedError, 'Blockchair doesn\'t implement block()'
|
105
106
|
end
|
106
107
|
|
107
108
|
private
|
data/lib/sibit/btc.rb
CHANGED
@@ -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::
|
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
|
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::
|
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::
|
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.
|
data/lib/sibit/cex.rb
CHANGED
@@ -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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
87
|
+
raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement push()'
|
88
88
|
end
|
89
89
|
|
90
90
|
def block(_hash)
|
91
|
-
raise Sibit::
|
91
|
+
raise Sibit::NotSupportedError, 'Cex.io doesn\'t implement block()'
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
data/lib/sibit/cryptoapis.rb
CHANGED
@@ -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::
|
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::
|
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::
|
102
|
+
raise Sibit::NotSupportedError, 'Not implemented yet'
|
100
103
|
end
|
101
104
|
|
102
105
|
# Push this transaction (in hex format) to the network.
|
data/lib/sibit/earn.rb
CHANGED
@@ -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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
98
|
+
raise Sibit::NotSupportedError, 'block() doesn\'t work here'
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
data/lib/sibit/error.rb
CHANGED
data/lib/sibit/version.rb
CHANGED
data/sibit.gemspec
CHANGED
@@ -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'
|
data/test/test_blockchair.rb
CHANGED
@@ -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\":
|
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
|
+
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-
|
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:
|