|
@ -636,7 +636,11 @@ if __name__ == '__main__': |
|
|
r, h = wallet.sendtx( tx ) |
|
|
r, h = wallet.sendtx( tx ) |
|
|
print_msg(h) |
|
|
print_msg(h) |
|
|
else: |
|
|
else: |
|
|
print_json({"hex":str(tx), "complete":tx.is_complete}) |
|
|
out = {"hex":str(tx), "complete":tx.is_complete} |
|
|
|
|
|
if not tx.is_complete: |
|
|
|
|
|
import json |
|
|
|
|
|
out['input_info'] = repr(tx.inputs_info).replace(' ','') |
|
|
|
|
|
print_json(out) |
|
|
|
|
|
|
|
|
if is_temporary: |
|
|
if is_temporary: |
|
|
wallet.imported_keys.pop(from_addr) |
|
|
wallet.imported_keys.pop(from_addr) |
|
@ -732,41 +736,55 @@ if __name__ == '__main__': |
|
|
|
|
|
|
|
|
elif cmd == 'signrawtransaction': |
|
|
elif cmd == 'signrawtransaction': |
|
|
tx = Transaction(args[1]) |
|
|
tx = Transaction(args[1]) |
|
|
txouts = ast.literal_eval(args[2]) if len(args)>2 else [] |
|
|
inputs_info = ast.literal_eval(args[2]) if len(args)>2 else [] |
|
|
private_keys = ast.literal_eval(args[3]) if len(args)>3 else {} |
|
|
private_keys = ast.literal_eval(args[3]) if len(args)>3 else {} |
|
|
unspent_coins = wallet.get_unspent_coins() |
|
|
unspent_coins = wallet.get_unspent_coins() |
|
|
|
|
|
|
|
|
|
|
|
# convert private_keys to dict |
|
|
|
|
|
pk = {} |
|
|
|
|
|
for sec in private_keys: |
|
|
|
|
|
address = bitcoin.address_from_private_key(sec) |
|
|
|
|
|
pk[address] = sec |
|
|
|
|
|
private_keys = pk |
|
|
|
|
|
|
|
|
for txin in tx.inputs: |
|
|
for txin in tx.inputs: |
|
|
# convert to own format |
|
|
# convert to own format |
|
|
txin['tx_hash'] = txin['prevout_hash'] |
|
|
txin['tx_hash'] = txin['prevout_hash'] |
|
|
txin['index'] = txin['prevout_n'] |
|
|
txin['index'] = txin['prevout_n'] |
|
|
|
|
|
|
|
|
for txout in txouts: |
|
|
for item in inputs_info: |
|
|
if txout.get('txid') == txin['tx_hash'] and txout.get('vout') == txin['index']: |
|
|
if item.get('txid') == txin['tx_hash'] and item.get('vout') == txin['index']: |
|
|
txin['raw_output_script'] = txout['scriptPubKey'] |
|
|
txin['raw_output_script'] = item['scriptPubKey'] |
|
|
txin['redeemScript'] = txout['redeemScript'] |
|
|
txin['redeemScript'] = item.get('redeemScript') |
|
|
|
|
|
txin['electrumKeyID'] = item.get('electrumKeyID') |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
for item in unspent_coins: |
|
|
for item in unspent_coins: |
|
|
if txin['tx_hash'] == item['tx_hash'] and txin['index'] == item['index']: |
|
|
if txin['tx_hash'] == item['tx_hash'] and txin['index'] == item['index']: |
|
|
txin['address'] = item['address'] |
|
|
|
|
|
txin['raw_output_script'] = item['raw_output_script'] |
|
|
txin['raw_output_script'] = item['raw_output_script'] |
|
|
break |
|
|
break |
|
|
else: |
|
|
else: |
|
|
# if neither, we might want to get it from the server.. |
|
|
# if neither, we might want to get it from the server.. |
|
|
raise |
|
|
raise |
|
|
|
|
|
|
|
|
if not private_keys: |
|
|
# find the address: |
|
|
for txin in tx.inputs: |
|
|
from lib import deserialize |
|
|
addr = txin['address'] |
|
|
if txin.get('electrumKeyID'): |
|
|
private_keys[addr] = wallet.get_private_key(addr, password) |
|
|
n, for_change = txin.get('electrumKeyID') |
|
|
else: |
|
|
sec = wallet.sequence.get_private_key(n, for_change, seed) |
|
|
pk = {} |
|
|
|
|
|
for sec in private_keys: |
|
|
|
|
|
address = bitcoin.address_from_private_key(sec) |
|
|
address = bitcoin.address_from_private_key(sec) |
|
|
pk[address] = sec |
|
|
txin['address'] = address |
|
|
private_keys = pk |
|
|
private_keys[address] = sec |
|
|
|
|
|
|
|
|
|
|
|
elif txin.get("redeemScript"): |
|
|
|
|
|
txin['address'] = hash_160_to_bc_address(hash_160(txin.get("redeemScript").decode('hex')), 5) |
|
|
|
|
|
|
|
|
|
|
|
elif txin.get("raw_output_script"): |
|
|
|
|
|
addr = deserialize.get_address_from_output_script(txin.get("raw_output_script").decode('hex')) |
|
|
|
|
|
sec = wallet.get_private_key(addr, password) |
|
|
|
|
|
if sec: |
|
|
|
|
|
private_keys[addr] = sec |
|
|
|
|
|
txin['address'] = addr |
|
|
|
|
|
|
|
|
tx.sign( private_keys ) |
|
|
tx.sign( private_keys ) |
|
|
print_json({ "hex":str(tx),"complete":tx.is_complete}) |
|
|
print_json({ "hex":str(tx),"complete":tx.is_complete}) |
|
|