onchain 2.1.3 → 2.1.4

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 +13 -8
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76a6f65d907e5cae3f94db2800fa0b56b76c2691
4
- data.tar.gz: 22f3ca7cca6aa67bb74fa7ce73c0f7dde82ec061
3
+ metadata.gz: 8b99554b564369f04613638da0a8f4e2e65bb218
4
+ data.tar.gz: 6ec490f1bbc99024e18c75fdf72ccdf20c1557e9
5
5
  SHA512:
6
- metadata.gz: ceeb735c3fc276744b680b54f10fac7df6a63ac85d8c2585344381f566ed145600a09fcc64fc057318ccd11e286dc820f77c429671cd2e201fa90586e9689619
7
- data.tar.gz: 902f6c708000154645138e1872d426a5a51c2e445537f1f7f52804a2c2d7a9d515f2fb9c930110fc7064b2497d3216df9fc6747282174da31fa6acb9b3207f2e
6
+ metadata.gz: 68e682b086b3074a319b67dd741e5b0ee7c2e83baaa3b1e381abf1b59b73ac11267604f4910496e15c061d147f23a0fbcc9e0c3636fed31b4f433e303e482bc2
7
+ data.tar.gz: 87ddeccd270eceb66998463241f0a6dea4334d235999ea13c8d1ce560a1560544cb524f7ac60fe5286cde665260b96554b1b083b3a2b90a0becb6bb067f62cf1
@@ -2,7 +2,7 @@ class OnChain::Transaction
2
2
  class << self
3
3
 
4
4
  def create_single_address_transaction(orig_addr, dest_addr, amount, fee_percent, fee_addr)
5
-
5
+
6
6
  tx = Bitcoin::Protocol::Tx.new
7
7
 
8
8
  total_amount = amount + calculate_fee(amount, fee_percent)
@@ -16,19 +16,16 @@ class OnChain::Transaction
16
16
 
17
17
  txin = Bitcoin::Protocol::TxIn.new([ spent[0] ].pack('H*').reverse, spent[1])
18
18
  txin.script_sig = OnChain.hex_to_bin(spent[2])
19
-
20
19
  tx.add_in(txin)
21
20
  end
22
-
23
21
  txout = Bitcoin::Protocol::TxOut.new(amount, Bitcoin::Script.to_address_script(dest_addr))
24
22
 
25
23
  tx.add_out(txout)
26
24
 
27
25
  # Send the change back.
28
26
  if change > 0
29
-
30
- txout = Bitcoin::Protocol::TxOut.new(change,
31
- Bitcoin::Script.to_address_script(orig_addr))
27
+
28
+ txout = Bitcoin::Protocol::TxOut.new(change, Bitcoin::Script.to_address_script(orig_addr))
32
29
 
33
30
  tx.add_out(txout)
34
31
  end
@@ -155,7 +152,7 @@ class OnChain::Transaction
155
152
  # [0]{034000.....' => {'hash' => '345435345....', 'sig' => '435fgdf4553...'}}
156
153
  # [0]{02fee.....' => {'hash' => '122133445....', 'sig' => '435fgdf4553...'}}
157
154
  #
158
- def sign_transaction(transaction_hex, sig_list)
155
+ def sign_transaction(transaction_hex, sig_list, pubkey = nil)
159
156
 
160
157
  tx = Bitcoin::Protocol::Tx.new OnChain::hex_to_bin(transaction_hex)
161
158
 
@@ -179,8 +176,16 @@ class OnChain::Transaction
179
176
  end
180
177
 
181
178
  if sigs.count > 0
182
- txin.script = Bitcoin::Script.to_p2sh_multisig_script_sig(rscript.to_payload, sigs)
179
+ in_script = Bitcoin::Script.new txin.script
180
+ if in_script.is_hash160?
181
+ sig = sigs[0]
182
+ txin.script = Bitcoin::Script.to_pubkey_script_sig(sig, OnChain.hex_to_bin(pubkey))
183
+ else
184
+ txin.script = Bitcoin::Script.to_p2sh_multisig_script_sig(rscript.to_payload, sigs)
185
+ end
183
186
  end
187
+
188
+ #raise "Signature error " + index.to_s if ! tx.verify_input_signature(index, in_script.to_payload)
184
189
  end
185
190
 
186
191
  return OnChain::bin_to_hex(tx.to_payload)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onchain
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Purton