signrawtransaction: parse redeemScript
This commit is contained in:
26
electrum
26
electrum
@@ -729,22 +729,38 @@ if __name__ == '__main__':
|
||||
|
||||
|
||||
elif cmd == 'signrawtransaction':
|
||||
from lib.bitcoin import *
|
||||
tx = Transaction(args[1])
|
||||
txouts = ast.literal_eval(args[2]) if len(args)>2 else []
|
||||
private_keys = ast.literal_eval(args[3]) if len(args)>3 else {}
|
||||
|
||||
# lookup addresses
|
||||
for txin in tx.inputs:
|
||||
txid = txin["prevout_hash"]
|
||||
index = txin["prevout_n"]
|
||||
utx = wallet.transactions.get(txid)
|
||||
txout = utx['outputs'][index]
|
||||
txin['address'] = txout['address']
|
||||
txin['raw_output_script'] = txout['raw_output_script']
|
||||
# convert to own format
|
||||
txin['tx_hash'] = txin['prevout_hash']
|
||||
txin['index'] = txin['prevout_n']
|
||||
|
||||
for txout in txouts:
|
||||
if txout.get('txid') == txid and txout.get('vout') == index:
|
||||
# compute addr from redeemScript
|
||||
addr = hash_160_to_bc_address(hash_160(txout['redeemScript'].decode('hex')),5)
|
||||
txin['address'] = addr
|
||||
txin['raw_output_script'] = txout['scriptPubKey']
|
||||
txin['redeemScript'] = txout['redeemScript']
|
||||
break
|
||||
|
||||
else:
|
||||
if wallet.transactions.get(txid):
|
||||
# lookup in my own list of transactions
|
||||
txout = wallet.transactions[txid]['outputs'][index]
|
||||
txin['address'] = txout['address']
|
||||
txin['raw_output_script'] = txout['raw_output_script']
|
||||
|
||||
else:
|
||||
# if neither, we might want to get it from the server..
|
||||
raise
|
||||
|
||||
if not private_keys:
|
||||
for txin in tx.inputs:
|
||||
addr = txin['address']
|
||||
|
||||
Reference in New Issue
Block a user