fix #2231: same serialize/deserialize format
This commit is contained in:
parent
9cb576a88c
commit
1aeeab9ec6
|
@ -195,7 +195,9 @@ class Commands:
|
||||||
|
|
||||||
@command('')
|
@command('')
|
||||||
def serialize(self, jsontx):
|
def serialize(self, jsontx):
|
||||||
"""Create a transaction from json inputs. Inputs must have a redeemPubkey. Outputs must be a list of (address, value).
|
"""Create a transaction from json inputs.
|
||||||
|
Inputs must have a redeemPubkey.
|
||||||
|
Outputs must be a list of {'address':address, 'value':satoshi_amount}.
|
||||||
"""
|
"""
|
||||||
keypairs = {}
|
keypairs = {}
|
||||||
inputs = jsontx.get('inputs')
|
inputs = jsontx.get('inputs')
|
||||||
|
@ -206,23 +208,18 @@ class Commands:
|
||||||
prevout_hash, prevout_n = txin['output'].split(':')
|
prevout_hash, prevout_n = txin['output'].split(':')
|
||||||
txin['prevout_n'] = int(prevout_n)
|
txin['prevout_n'] = int(prevout_n)
|
||||||
txin['prevout_hash'] = prevout_hash
|
txin['prevout_hash'] = prevout_hash
|
||||||
else:
|
|
||||||
raise BaseException('Output point missing', txin)
|
|
||||||
if txin.get('redeemPubkey'):
|
if txin.get('redeemPubkey'):
|
||||||
pubkey = txin['redeemPubkey']
|
pubkey = txin['redeemPubkey']
|
||||||
txin['pubkeys'] = [pubkey]
|
txin['type'] = 'p2pkh'
|
||||||
txin['x_pubkeys'] = [pubkey]
|
txin['x_pubkeys'] = [pubkey]
|
||||||
txin['signatures'] = [None]
|
txin['signatures'] = [None]
|
||||||
txin['num_sig'] = 1
|
txin['num_sig'] = 1
|
||||||
privkey = txin.get('privkey')
|
if txin.get('privkey'):
|
||||||
if privkey:
|
keypairs[pubkey] = txin['privkey']
|
||||||
keypairs[pubkey] = privkey
|
|
||||||
elif txin.get('redeemScript'):
|
elif txin.get('redeemScript'):
|
||||||
raise BaseException('Not implemented')
|
raise BaseException('Not implemented')
|
||||||
else:
|
|
||||||
raise BaseException('No redeem script')
|
|
||||||
|
|
||||||
outputs = map(lambda x: (TYPE_ADDRESS, x[0], satoshis(x[1])), outputs)
|
outputs = map(lambda x: (TYPE_ADDRESS, x['address'], int(x['value'])), outputs)
|
||||||
tx = Transaction.from_io(inputs, outputs, locktime=locktime)
|
tx = Transaction.from_io(inputs, outputs, locktime=locktime)
|
||||||
tx.sign(keypairs)
|
tx.sign(keypairs)
|
||||||
return tx.as_dict()
|
return tx.as_dict()
|
||||||
|
|
Loading…
Reference in New Issue