sibit 0.16.0 → 0.16.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/Rakefile +1 -0
- data/lib/sibit/blockchain.rb +25 -25
- data/lib/sibit/btc.rb +26 -5
- data/lib/sibit/version.rb +1 -1
- data/lib/sibit.rb +1 -1
- data/test/test_blockchain.rb +0 -1
- data/test/test_live.rb +12 -3
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5ff1fd9e3917932468cb14ce7d91e23b9b086fb46fee75a828c1a6eed9631a57
|
|
4
|
+
data.tar.gz: 9833b8986c31a248beba236cd4cb11da0e36a723553d187afa31a6634be4f2c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7f29c08168ed4a9a0eeebef06ec5a425878401cfee1daa8409d5858fd1eb33b3cb17484fdeccbf1db5a22e3c3573a053fdbc7cc74cb9328d69c495ccec235064
|
|
7
|
+
data.tar.gz: b7c6f33191f5aa9dc9fd26b1e2a8154af9e7c6cae2c26f26c0700b25a86ca984b61250e55ebf7ee4b9c473a714ad74ac1d917d276db178f8c4ddf58ee66f4a9f
|
data/Rakefile
CHANGED
|
@@ -37,6 +37,7 @@ task default: %i[clean test features rubocop copyright]
|
|
|
37
37
|
|
|
38
38
|
require 'rake/testtask'
|
|
39
39
|
Rake::TestTask.new(:test) do |test|
|
|
40
|
+
ENV['skip_live'] = 'yes'
|
|
40
41
|
Rake::Cleaner.cleanup_files(['coverage'])
|
|
41
42
|
test.libs << 'lib' << 'test'
|
|
42
43
|
test.pattern = 'test/**/test_*.rb'
|
data/lib/sibit/blockchain.rb
CHANGED
|
@@ -69,13 +69,14 @@ class Sibit
|
|
|
69
69
|
|
|
70
70
|
# Get recommended fees.
|
|
71
71
|
def fees
|
|
72
|
-
raise Sibit::Error, 'fees() not
|
|
72
|
+
raise Sibit::Error, 'fees() is not provided by Blockchain API'
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
# Fetch all unspent outputs per address.
|
|
75
|
+
# Fetch all unspent outputs per address. The argument is an array
|
|
76
|
+
# of Bitcoin addresses.
|
|
76
77
|
def utxos(sources)
|
|
77
78
|
Sibit::Json.new(http: @http, log: @log).get(
|
|
78
|
-
URI("https://blockchain.info/unspent?active=#{sources.
|
|
79
|
+
URI("https://blockchain.info/unspent?active=#{sources.join('|')}&limit=1000")
|
|
79
80
|
)['unspent_outputs'].map do |u|
|
|
80
81
|
{
|
|
81
82
|
value: u['value'],
|
|
@@ -106,28 +107,27 @@ class Sibit
|
|
|
106
107
|
end
|
|
107
108
|
|
|
108
109
|
# This method should fetch a Blockchain block and return as a hash.
|
|
109
|
-
def block(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
# }
|
|
110
|
+
def block(hash)
|
|
111
|
+
json = Sibit::Json.new(http: @http, log: @log).get(
|
|
112
|
+
URI("https://blockchain.info/rawblock/#{hash}")
|
|
113
|
+
)
|
|
114
|
+
{
|
|
115
|
+
hash: json['hash'],
|
|
116
|
+
orphan: !json['main_chain'],
|
|
117
|
+
next: json['next_block'][0],
|
|
118
|
+
previous: json['prev_block'],
|
|
119
|
+
txns: json['tx'].map do |t|
|
|
120
|
+
{
|
|
121
|
+
hash: t['hash'],
|
|
122
|
+
outputs: t['out'].map do |o|
|
|
123
|
+
{
|
|
124
|
+
address: o['addr'],
|
|
125
|
+
value: o['value']
|
|
126
|
+
}
|
|
127
|
+
end
|
|
128
|
+
}
|
|
129
|
+
end
|
|
130
|
+
}
|
|
131
131
|
end
|
|
132
132
|
end
|
|
133
133
|
end
|
data/lib/sibit/btc.rb
CHANGED
|
@@ -45,7 +45,7 @@ class Sibit
|
|
|
45
45
|
|
|
46
46
|
# Current price of BTC in USD (float returned).
|
|
47
47
|
def price(_currency)
|
|
48
|
-
raise Sibit::Error, 'Btc.com API doesn\'t provide
|
|
48
|
+
raise Sibit::Error, 'Btc.com API doesn\'t provide prices'
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# Gets the balance of the address, in satoshi.
|
|
@@ -65,7 +65,7 @@ class Sibit
|
|
|
65
65
|
|
|
66
66
|
# Get recommended fees, in satoshi per byte.
|
|
67
67
|
def fees
|
|
68
|
-
raise Sibit::Error, '
|
|
68
|
+
raise Sibit::Error, 'Btc.com doesn\'t provide recommended fees'
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
# Gets the hash of the latest block.
|
|
@@ -78,13 +78,34 @@ class Sibit
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
# Fetch all unspent outputs per address.
|
|
81
|
-
def utxos(
|
|
82
|
-
|
|
81
|
+
def utxos(sources)
|
|
82
|
+
txns = []
|
|
83
|
+
sources.each do |hash|
|
|
84
|
+
json = Sibit::Json.new(http: @http, log: @log).get(
|
|
85
|
+
URI("https://chain.api.btc.com/v3/address/#{hash}/unspent")
|
|
86
|
+
)
|
|
87
|
+
json['data']['list'].each do |u|
|
|
88
|
+
outs = Sibit::Json.new(http: @http, log: @log).get(
|
|
89
|
+
URI("https://chain.api.btc.com/v3/tx/#{u['tx_hash']}?verbose=3")
|
|
90
|
+
)['data']['outputs']
|
|
91
|
+
outs.each_with_index do |o, i|
|
|
92
|
+
next unless o['addresses'].include?(hash)
|
|
93
|
+
txns << {
|
|
94
|
+
value: o['value'],
|
|
95
|
+
hash: u['tx_hash'],
|
|
96
|
+
index: i,
|
|
97
|
+
confirmations: u['confirmations'],
|
|
98
|
+
script: [o['script_hex']].pack('H*')
|
|
99
|
+
}
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
txns
|
|
83
104
|
end
|
|
84
105
|
|
|
85
106
|
# Push this transaction (in hex format) to the network.
|
|
86
107
|
def push(_hex)
|
|
87
|
-
raise Sibit::Error, '
|
|
108
|
+
raise Sibit::Error, 'Btc.com doesn\'t provide payment gateway'
|
|
88
109
|
end
|
|
89
110
|
|
|
90
111
|
# This method should fetch a Blockchain block and return as a hash.
|
data/lib/sibit/version.rb
CHANGED
data/lib/sibit.rb
CHANGED
|
@@ -110,7 +110,7 @@ class Sibit
|
|
|
110
110
|
builder = Bitcoin::Builder::TxBuilder.new
|
|
111
111
|
unspent = 0
|
|
112
112
|
size = 100
|
|
113
|
-
utxos = first_one { |api| api.utxos(sources) }
|
|
113
|
+
utxos = first_one { |api| api.utxos(sources.keys) }
|
|
114
114
|
@log.info("#{utxos.count} UTXOs found, these will be used \
|
|
115
115
|
(value/confirmations at tx_hash):")
|
|
116
116
|
utxos.each do |utxo|
|
data/test/test_blockchain.rb
CHANGED
|
@@ -32,7 +32,6 @@ require_relative '../lib/sibit/blockchain'
|
|
|
32
32
|
# License:: MIT
|
|
33
33
|
class TestBlockchain < Minitest::Test
|
|
34
34
|
def test_fetch_block
|
|
35
|
-
skip
|
|
36
35
|
hash = '0000000000000000000f676241aabc9b62b748d26192a44bc25720c34de27d19'
|
|
37
36
|
stub_request(:get, "https://blockchain.info/rawblock/#{hash}")
|
|
38
37
|
.to_return(body: '{"next_block": "n", "prev_block": "p", "hash": "h",
|
data/test/test_live.rb
CHANGED
|
@@ -67,12 +67,23 @@ class TestLive < Minitest::Test
|
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
def test_utxos
|
|
71
|
+
for_each do |api|
|
|
72
|
+
json = api.utxos(['12fCwqBN4XsHq4iu2Wbfgq5e8YhqEGP3ee'])
|
|
73
|
+
assert_equal(3, json.length)
|
|
74
|
+
assert(json.find { |t| t[:value] == 16_200_000 }, 'UTXO not found')
|
|
75
|
+
assert(json.find { |t| t[:script].unpack('H*').first.start_with?('76a9141231e760') })
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
70
79
|
private
|
|
71
80
|
|
|
72
81
|
def for_each
|
|
73
|
-
skip
|
|
82
|
+
skip if ENV['skip_live']
|
|
74
83
|
WebMock.allow_net_connect!
|
|
75
84
|
apis = []
|
|
85
|
+
require_relative '../lib/sibit/blockchain'
|
|
86
|
+
apis << Sibit::Blockchain.new
|
|
76
87
|
require_relative '../lib/sibit/blockchair'
|
|
77
88
|
apis << Sibit::Blockchair.new
|
|
78
89
|
require_relative '../lib/sibit/cryptoapis'
|
|
@@ -81,8 +92,6 @@ class TestLive < Minitest::Test
|
|
|
81
92
|
apis << Sibit::Btc.new
|
|
82
93
|
require_relative '../lib/sibit/bitcoinchain'
|
|
83
94
|
apis << Sibit::Bitcoinchain.new
|
|
84
|
-
require_relative '../lib/sibit/blockchain'
|
|
85
|
-
apis << Sibit::Blockchain.new
|
|
86
95
|
apis.each do |api|
|
|
87
96
|
begin
|
|
88
97
|
yield api
|
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.16.
|
|
4
|
+
version: 0.16.1
|
|
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-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: backtrace
|