sibit 0.2.0 → 0.3.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/version.rb +1 -1
- data/lib/sibit.rb +10 -21
- data/test/test_sibit.rb +1 -5
- 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: ba379da20ae654c4299c0f9e17069c2940e3040dfd2194dc329a59c3b4b0aebd
|
|
4
|
+
data.tar.gz: '097b99e3666986b4ed2dddf46c39996ae8be476b1e1bff63e30257830b2b4a6a'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 157a29f6c6c4c53b06feb75151d772ed9a9a82f62909e947d9df12d85f988ef08b8659a82988b43041d4c8379bd21b93b3cacf7e3b4b289fffab448b98881399
|
|
7
|
+
data.tar.gz: 0a5fca4e48e0e1d34e13b421295aea80162d07784f02bd0f425343e8dac0dc5aa7c48452807056d6d0b417eba5dd3ea121be2a8cdceb686ee732d3ff5cd5eee0
|
data/lib/sibit/version.rb
CHANGED
data/lib/sibit.rb
CHANGED
|
@@ -50,7 +50,10 @@ class Sibit
|
|
|
50
50
|
|
|
51
51
|
# Get the balance of the address, in satoshi.
|
|
52
52
|
def balance(address)
|
|
53
|
-
get_json("https://blockchain.info/rawaddr/#{address}")
|
|
53
|
+
json = get_json("https://blockchain.info/rawaddr/#{address}")
|
|
54
|
+
debug("Total transactions: #{json['n_tx']}")
|
|
55
|
+
debug("Received/sent: #{json['total_received']}/#{json['total_sent']}")
|
|
56
|
+
json['final_balance']
|
|
54
57
|
end
|
|
55
58
|
|
|
56
59
|
# Send a payment and return the transaction hash.
|
|
@@ -66,7 +69,11 @@ class Sibit
|
|
|
66
69
|
builder = Bitcoin::Builder::TxBuilder.new
|
|
67
70
|
unspent = 0
|
|
68
71
|
size = 100
|
|
69
|
-
utxos
|
|
72
|
+
utxos = get_json(
|
|
73
|
+
"https://blockchain.info/unspent?active=#{sources.join('|')}&limit=1000"
|
|
74
|
+
)['unspent_outputs']
|
|
75
|
+
debug("#{utxos.count} UTXOs found:")
|
|
76
|
+
utxos.each do |utxo|
|
|
70
77
|
unspent += utxo['value']
|
|
71
78
|
builder.input do |i|
|
|
72
79
|
i.prev_out(utxo['tx_hash_big_endian'])
|
|
@@ -75,6 +82,7 @@ class Sibit
|
|
|
75
82
|
i.signature_key(key(pvt))
|
|
76
83
|
end
|
|
77
84
|
size += 180
|
|
85
|
+
debug(" #{utxo['value']}/#{utxo['confirmations']} at #{utxo['tx_hash_big_endian']}")
|
|
78
86
|
break if unspent > satoshi
|
|
79
87
|
end
|
|
80
88
|
raise "Not enough funds to send #{amount}, only #{unspent} left" if unspent < satoshi
|
|
@@ -90,25 +98,6 @@ class Sibit
|
|
|
90
98
|
|
|
91
99
|
private
|
|
92
100
|
|
|
93
|
-
# Retrieve all unspent outputs of the given list of
|
|
94
|
-
# addresses.
|
|
95
|
-
def utxos(sources)
|
|
96
|
-
offset = 0
|
|
97
|
-
txns = []
|
|
98
|
-
loop do
|
|
99
|
-
uri = [
|
|
100
|
-
'https://blockchain.info/unspent?',
|
|
101
|
-
"active=#{sources.join('|')}",
|
|
102
|
-
offset.positive? ? "&offset=#{offset}" : ''
|
|
103
|
-
].join
|
|
104
|
-
list = get_json(uri)['unspent_outputs']
|
|
105
|
-
txns += list
|
|
106
|
-
break if list.empty?
|
|
107
|
-
offset += list.count
|
|
108
|
-
end
|
|
109
|
-
txns
|
|
110
|
-
end
|
|
111
|
-
|
|
112
101
|
# Convert text to amount.
|
|
113
102
|
def satoshi(amount)
|
|
114
103
|
return (amount.gsub(/BTC$/, '').to_f * 100_000_000).to_i if amount.end_with?('BTC')
|
data/test/test_sibit.rb
CHANGED
|
@@ -72,12 +72,8 @@ class TestSibit < Minitest::Test
|
|
|
72
72
|
}
|
|
73
73
|
stub_request(
|
|
74
74
|
:get,
|
|
75
|
-
'https://blockchain.info/unspent?active=1JvCsJtLmCxEk7ddZFnVkGXpr9uhxZPmJi'
|
|
75
|
+
'https://blockchain.info/unspent?active=1JvCsJtLmCxEk7ddZFnVkGXpr9uhxZPmJi&limit=1000'
|
|
76
76
|
).to_return(status: 200, body: JSON.pretty_generate(json))
|
|
77
|
-
stub_request(
|
|
78
|
-
:get,
|
|
79
|
-
'https://blockchain.info/unspent?active=1JvCsJtLmCxEk7ddZFnVkGXpr9uhxZPmJi&offset=1'
|
|
80
|
-
).to_return(status: 200, body: '{"unspent_outputs": []}')
|
|
81
77
|
stub_request(:post, 'https://blockchain.info/pushtx').to_return(status: 200)
|
|
82
78
|
sibit = Sibit.new
|
|
83
79
|
target = sibit.create(sibit.generate)
|