1
0

create Transaction class

This commit is contained in:
thomasv
2013-02-21 14:18:12 +01:00
parent b4bb3c7449
commit ea7718fc59
4 changed files with 101 additions and 64 deletions

View File

@@ -711,38 +711,44 @@ if __name__ == '__main__':
import ast
inputs = ast.literal_eval(args[1])
outputs = ast.literal_eval(args[2])
inputs = map(lambda x: (None, None, x["txid"], x["vout"], None, None), inputs)
outputs = map(lambda x: (x[0],int(x[1]*1e8)), outputs.items())
tx = raw_tx(inputs, outputs, for_sig = -1) # for_sig=-1 means do not sign
# convert to own format
for i in inputs:
i['tx_hash'] = i['txid']
i['index'] = i['vout']
outputs = map(lambda x: (x[0],int(1e8*x[1])), outputs.items())
tx = Transaction.from_io(inputs, outputs)
print_msg( tx )
elif cmd == 'decoderawtransaction':
print_json( bitcoin.deserialize(args[1]) )
tx = Transaction(args[1])
print_json( tx.deserialize() )
elif cmd == 'signrawtransaction':
d = bitcoin.deserialize(args[1])
tx = Transaction(args[1])
txouts = args[2] if len(args)>2 else []
private_keys = args[3] if len(args)>3 else []
inputs = []
for x in d['inputs']:
txid = x["prevout_hash"]
nout = x["prevout_n"]
tx = wallet.transactions.get(txid)
txout = tx['outputs'][nout]
addr = txout['address']
v = txout['value']
inputs.append( (addr, v, txid, nout, txout['raw_output_script'], [(None,None)] ) )
private_keys = args[3] if len(args)>3 else {}
outputs = map(lambda x: (x['address'],x['value']), d['outputs'])
print_error("inputs", inputs)
print_error("outputs", outputs)
tx = wallet.signed_tx( inputs, outputs, password )
if not private_keys:
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']
secexp, compressed = wallet.get_private_key(txin['address'], password)
private_keys[addr] = (secexp,compressed)
tx.sign( private_keys )
print_msg(tx)
if cmd not in offline_commands and not options.offline:
synchronizer.stop()