electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 02c3bc131e5427aa06edc8ac39a774a391b67a5d
parent 8e644a4dc8bbb7b3e10bda0ad1c474c279cade35
Author: ThomasV <thomasv@gitorious>
Date:   Thu,  3 Apr 2014 21:23:35 +0200

fix and simplify tx serialization

Diffstat:
Mlib/transaction.py | 32++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/lib/transaction.py b/lib/transaction.py @@ -421,6 +421,7 @@ class Transaction: @classmethod def serialize( klass, inputs, outputs, for_sig = None ): + push_script = lambda x: op_push(len(x)/2) + x s = int_to_hex(1,4) # version s += var_int( len(inputs) ) # number of inputs for i in range(len(inputs)): @@ -431,28 +432,23 @@ class Transaction: if for_sig is None: signatures = txin['signatures'] pubkeys = txin['pubkeys'] + sig_list = '' + for pubkey in pubkeys: + sig = signatures.get(pubkey) + if not sig: + continue + sig = sig + '01' + sig_list += push_script(sig) + if not txin.get('redeemScript'): - pubkey = pubkeys[0] - script = '' - if signatures: - sig = signatures[0] - sig = sig + '01' # hashtype - script += op_push(len(sig)/2) - script += sig - script += op_push(len(pubkey)/2) - script += pubkey + script = sig_list + script += push_script(pubkeys[0]) else: script = '00' # op_0 - for pubkey in pubkeys: - sig = signatures.get(pubkey) - if not sig: continue - sig = sig + '01' - script += op_push(len(sig)/2) - script += sig - + script += sig_list redeem_script = klass.multisig_script(pubkeys,2) - script += op_push(len(redeem_script)/2) - script += redeem_script + assert redeem_script == txin.get('redeemScript') + script += push_script(redeem_script) elif for_sig==i: if txin.get('redeemScript'):