sibit 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 478069971b53901e3037034ee2830d5b66154a77fc1b5087b17f15e94870ca39
4
- data.tar.gz: 48039e52d5835aef4515e28c3fa3575e946e99556fcdb424f71c9f4c022f66e5
3
+ metadata.gz: bffdfd4fc0e852f5e78e27ce795d452f8d73b2e19af8b6d7f0c568a981b042b9
4
+ data.tar.gz: ab3d76f7ffa5d2773c969d74a707cc713a0a91b6f23f79827a8bb860dffd71a4
5
5
  SHA512:
6
- metadata.gz: 80d804206aa880655b81a696a73558a47fc8dd1eee00d0c82fe7965283469d0b0586e56cace8d6309114af8572f8781deda7c259f6522317a9180c889a3e7fe5
7
- data.tar.gz: 92d14ce0a35f45a1d994615a18fdde4472b33e39ff30c64f22606c0691bf37beed91db3a0c71f8a0f9f8b690da11eae24b8606030483213b5d34f42aae36d0fb
6
+ metadata.gz: bcf1082248a88d3d497957e7433a20b9ebb2ac66ee75136390ff8d28aef8082e2a8bbdc8f1ef766fb17b30835e3215c35128c3146ba24ad25788b3cac0519f6f
7
+ data.tar.gz: 41a43a40203b84dc78021a671993abfd5d5e9ed2ff502cc3891d8c4040b4b8d409fcbc9e6fa17ed71c69fdc66e3a78dee92ea72d199eee1ffc6def2b0097951b
data/README.md CHANGED
@@ -57,16 +57,15 @@ $ sibit balance 1CC3X2gu58d6wXUWMffpuzN9JAfTUWu4Kj
57
57
  To send a payment from a few addresses to a new address:
58
58
 
59
59
  ```
60
- $ sibit pay KEY AMOUNT FEE SOURCE1,SOURCE2,... TARGET CHANGE
60
+ $ sibit pay AMOUNT FEE A1:P1,A2:P2,... TARGET CHANGE
61
61
  e87f138c9ebf5986151667719825c28458a28cc66f69fed4f1032a93b399fdf8
62
62
  ```
63
63
 
64
64
  Here,
65
- `KEY` is the private key,
66
65
  `AMOUNT` is the amount of [satoshi](https://en.bitcoin.it/wiki/Satoshi_%28unit%29) you are sending,
67
66
  `FEE` is the [miner fee](https://en.bitcoin.it/wiki/Miner_fees) you are ready to spend to make this transaction delivered
68
67
  (you can say `S`, `M`, `L`, or `XL` if you want it to be calculated automatically),
69
- `SOURCE1,SOURCE2,...` is a comma-separated list of addresses you are sending your coins from,
68
+ `A1:P1,A2:P2,...` is a comma-separated list of addresses `A` and private keys `P` you are sending your coins from,
70
69
  `TARGET` is the address you are sending to,
71
70
  `CHANGE` is the address where the change will be sent to.
72
71
  The transaction hash will be returned.
@@ -90,7 +89,7 @@ address = sibit.create(pkey)
90
89
  balance = sibit.balance(address)
91
90
  target = sibit.create(pkey) # where to send coins to
92
91
  change = sibit.create(pkey) # where the change will sent to
93
- tx = sibit.pay(pkey, 10_000_000, 'XL', [address], target, change)
92
+ tx = sibit.pay(10_000_000, 'XL', { address => pkey }, target, change)
94
93
  ```
95
94
 
96
95
  Should work.
data/bin/sibit CHANGED
@@ -65,19 +65,24 @@ Options are:"
65
65
  raise 'Address argument is required' if address.nil?
66
66
  puts sibit.balance(address)
67
67
  when 'pay'
68
- pvt = opts.arguments[1]
69
- raise 'Private key argument is required' if pvt.nil?
70
- amount = opts.arguments[2]
68
+ amount = opts.arguments[1]
71
69
  raise 'Amount argument is required' if amount.nil?
72
- fee = opts.arguments[3]
70
+ fee = opts.arguments[2]
73
71
  raise 'Miners fee argument is required' if fee.nil?
74
- sources = opts.arguments[4]
72
+ sources = opts.arguments[3]
75
73
  raise 'Addresses argument is required' if sources.nil?
76
- target = opts.arguments[5]
74
+ target = opts.arguments[4]
77
75
  raise 'Target argument is required' if target.nil?
78
- change = opts.arguments[6]
76
+ change = opts.arguments[5]
79
77
  raise 'Change argument is required' if change.nil?
80
- puts sibit.pay(pvt, amount, fee, sources.split(','), target, change)
78
+ puts sibit.pay(
79
+ amount, fee,
80
+ sources.split(',').map do |p|
81
+ address, pvt = p.split(':')
82
+ { address: address, pvt: pvt }
83
+ end,
84
+ target, change
85
+ )
81
86
  else
82
87
  raise "Command #{opts.arguments[0]} is not supported"
83
88
  end
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.5.0'
29
+ VERSION = '0.6.0'
30
30
  end
data/lib/sibit.rb CHANGED
@@ -83,19 +83,19 @@ class Sibit
83
83
  # If there are more than 1000 UTXOs in the address where you are trying
84
84
  # to send bitcoins from, this method won't be helpful.
85
85
  #
86
- # +pvt+: the private key as a Hash160 string
87
86
  # +amount+: the amount either in satoshis or ending with 'BTC', like '0.7BTC'
88
87
  # +fee+: the miners fee in satoshis (as integer) or S/M/X/XL as a string
89
- # +sources+: the array of bitcoin addresses where the coins are now
88
+ # +sources+: the hashmap of bitcoin addresses where the coins are now, with
89
+ # their addresses as keys and private keys as values
90
90
  # +target+: the target address to send to
91
91
  # +change+: the address where the change has to be sent to
92
- def pay(pvt, amount, fee, sources, target, change)
92
+ def pay(amount, fee, sources, target, change)
93
93
  satoshi = satoshi(amount)
94
94
  builder = Bitcoin::Builder::TxBuilder.new
95
95
  unspent = 0
96
96
  size = 100
97
97
  utxos = get_json(
98
- "/unspent?active=#{sources.join('|')}&limit=1000"
98
+ "/unspent?active=#{sources.keys.join('|')}&limit=1000"
99
99
  )['unspent_outputs']
100
100
  debug("#{utxos.count} UTXOs found:")
101
101
  utxos.each do |utxo|
@@ -104,7 +104,8 @@ class Sibit
104
104
  i.prev_out(utxo['tx_hash_big_endian'])
105
105
  i.prev_out_index(utxo['tx_output_n'])
106
106
  i.prev_out_script = [utxo['script']].pack('H*')
107
- i.signature_key(key(pvt))
107
+ address = Bitcoin::Script.new([utxo['script']].pack('H*')).get_address
108
+ i.signature_key(key(sources[address]))
108
109
  end
109
110
  size += 180
110
111
  debug(" #{utxo['value']}/#{utxo['confirmations']} at #{utxo['tx_hash_big_endian']}")
@@ -133,7 +134,7 @@ class Sibit
133
134
  start = Time.now
134
135
  res = Net::HTTP.get_response(URI('https://blockchain.info' + uri))
135
136
  raise Error, "Failed to retrieve #{uri}: #{res.code}" unless res.code == '200'
136
- debug("GET #{uri}: #{res.code} in #{age(start)}")
137
+ debug("GET #{uri}: #{res.code}/#{res.body.length}b in #{age(start)}")
137
138
  JSON.parse(res.body)
138
139
  end
139
140
 
data/test/test_sibit.rb CHANGED
@@ -55,6 +55,7 @@ class TestSibit < Minitest::Test
55
55
  puts "address: #{address}"
56
56
  assert(!address.nil?)
57
57
  assert(/^1[0-9a-zA-Z]+$/.match?(address))
58
+ assert_equal(address, sibit.create(pkey))
58
59
  end
59
60
 
60
61
  def test_get_balance
@@ -99,9 +100,11 @@ class TestSibit < Minitest::Test
99
100
  target = sibit.create(sibit.generate)
100
101
  change = sibit.create(sibit.generate)
101
102
  tx = sibit.pay(
102
- 'fd2333686f49d8647e1ce8d5ef39c304520b08f3c756b67068b30a3db217dcb2',
103
103
  '0.0001BTC', 'S',
104
- ['1JvCsJtLmCxEk7ddZFnVkGXpr9uhxZPmJi'],
104
+ {
105
+ '1JvCsJtLmCxEk7ddZFnVkGXpr9uhxZPmJi' =>
106
+ 'fd2333686f49d8647e1ce8d5ef39c304520b08f3c756b67068b30a3db217dcb2'
107
+ },
105
108
  target, change
106
109
  )
107
110
  assert(!tx.nil?)
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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko