sibit 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3a78e7d4292bdaf0bfb92f1de1b662bbd1f08bb592e39c5bc599c6289e979d1
4
- data.tar.gz: 9220954be20e8c6c2a118dc99e7009aac851a3acd5580e4f27632c51dfa4c6b2
3
+ metadata.gz: ba379da20ae654c4299c0f9e17069c2940e3040dfd2194dc329a59c3b4b0aebd
4
+ data.tar.gz: '097b99e3666986b4ed2dddf46c39996ae8be476b1e1bff63e30257830b2b4a6a'
5
5
  SHA512:
6
- metadata.gz: c5be07db0bee669ce400f8ecf7692a9ef8ff5c9c943a6bfe80e024938929584ce4dc899acbae3a81a51250f0ffd86bd523464dd0d59e0453abb9ce48a052cf05
7
- data.tar.gz: e8b51f0a827770bc7fb0ff08480cf9a645588fb4b2ff2b63cced7c8433bc8f6577e8098a3c89e434fe6108e6872d4ac7fef50e2e04dc20687adf336f00d450cb
6
+ metadata.gz: 157a29f6c6c4c53b06feb75151d772ed9a9a82f62909e947d9df12d85f988ef08b8659a82988b43041d4c8379bd21b93b3cacf7e3b4b289fffab448b98881399
7
+ data.tar.gz: 0a5fca4e48e0e1d34e13b421295aea80162d07784f02bd0f425343e8dac0dc5aa7c48452807056d6d0b417eba5dd3ea121be2a8cdceb686ee732d3ff5cd5eee0
data/lib/sibit/version.rb CHANGED
@@ -26,5 +26,5 @@
26
26
  # License:: MIT
27
27
  class Sibit
28
28
  # Current version of the library.
29
- VERSION = '0.2.0'
29
+ VERSION = '0.3.0'
30
30
  end
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}")['final_balance']
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(sources).each do |utxo|
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko