onchain 2.1.3 → 2.1.4
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/onchain/transaction.rb +13 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b99554b564369f04613638da0a8f4e2e65bb218
|
4
|
+
data.tar.gz: 6ec490f1bbc99024e18c75fdf72ccdf20c1557e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68e682b086b3074a319b67dd741e5b0ee7c2e83baaa3b1e381abf1b59b73ac11267604f4910496e15c061d147f23a0fbcc9e0c3636fed31b4f433e303e482bc2
|
7
|
+
data.tar.gz: 87ddeccd270eceb66998463241f0a6dea4334d235999ea13c8d1ce560a1560544cb524f7ac60fe5286cde665260b96554b1b083b3a2b90a0becb6bb067f62cf1
|
data/lib/onchain/transaction.rb
CHANGED
@@ -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
|
-
|
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)
|