onchain 2.7 → 2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onchain/transaction.rb +15 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fd37bc684d309bb9c0a1fdacfbb066e61bfc0d0
4
- data.tar.gz: dd377843c1479db0d1fdc5c98692cf94ecc367f9
3
+ metadata.gz: 2703385de3ceefa777d64885f6a047f01f0b6bcf
4
+ data.tar.gz: 82aa03a8de7211bedf7cd825e86d907514b42636
5
5
  SHA512:
6
- metadata.gz: 821744ea8ad3475efd1275ce2088c830c173af33603998405be8b1d55ed749e687a472cd6dca18f870e4e6fcb1fb002eda10c0066c9cca2687bed145bba2c8c9
7
- data.tar.gz: 92de84981941cbfb00e1a98b01877b4a8d1abf623c9677b1ac3080850c2a802c74bc916a052e0d2289e677a043959672ec3333b9042947455d6f921dca003f49
6
+ metadata.gz: 95726ce6f2c934c1d089809b8af5ea125f422b9e4254398e1676f78163b225cc359ba6719b05fada9b6358ec41647d11ffabfe755c2f86ce2838a0fdbb4cc724
7
+ data.tar.gz: 6841cd228889544b0e6ab79f61b9a6e64c3c08882958115513ebd2b22872231a724e46e479a6ee63eba13bc3953aa552f452a8076e3da56d2c09a0323a99ebb0
@@ -223,17 +223,17 @@ class OnChain::Transaction
223
223
  # [0][034000....][:hash => '345435345...']
224
224
  # [0][02fee.....][:hash => '122133445....']
225
225
  #
226
- def create_transaction(redemption_scripts, address, amount_in_satoshi, miners_fee)
226
+ def create_transaction(redemption_scripts, address, amount_in_satoshi, miners_fee, network = :bitcoin)
227
227
 
228
228
  total_amount = miners_fee
229
229
 
230
230
  total_amount = total_amount + amount_in_satoshi
231
231
 
232
232
  addresses = redemption_scripts.map { |rs|
233
- OnChain::Sweeper.generate_address_of_redemption_script(rs)
233
+ generate_address_of_redemption_script(rs, network)
234
234
  }
235
235
 
236
- unspents, indexes, change = OnChain::BlockChain.get_unspent_for_amount(addresses, total_amount)
236
+ unspents, indexes, change = OnChain::BlockChain.get_unspent_for_amount(addresses, total_amount, network)
237
237
 
238
238
  # OK, let's build a transaction.
239
239
  tx = Bitcoin::Protocol::Tx.new
@@ -254,7 +254,7 @@ class OnChain::Transaction
254
254
  #end
255
255
 
256
256
  txout = Bitcoin::Protocol::TxOut.new(amount_in_satoshi,
257
- Bitcoin::Script.to_address_script(address))
257
+ to_address_script(address, network))
258
258
 
259
259
  tx.add_out(txout)
260
260
 
@@ -264,7 +264,7 @@ class OnChain::Transaction
264
264
  if change > 0
265
265
 
266
266
  txout = Bitcoin::Protocol::TxOut.new(change,
267
- Bitcoin::Script.to_address_script(change_address))
267
+ to_address_script(change_address, network))
268
268
 
269
269
  tx.add_out(txout)
270
270
  end
@@ -273,6 +273,16 @@ class OnChain::Transaction
273
273
 
274
274
  return OnChain::bin_to_hex(tx.to_payload), inputs_to_sign
275
275
  end
276
+
277
+ def generate_address_of_redemption_script(redemption_script, network = :bitcoin)
278
+
279
+ Bitcoin.network = network
280
+ hash160 = Bitcoin.hash160(redemption_script)
281
+ addr = Bitcoin.hash160_to_p2sh_address(hash160)
282
+ Bitcoin.network = :bitcoin
283
+
284
+ return addr
285
+ end
276
286
 
277
287
  # Given a transaction in hex string format, apply
278
288
  # the given signature list to it.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onchain
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.7'
4
+ version: '2.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Purton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake