1
0

serialize value for segwit-p2sh inputs too

This commit is contained in:
ThomasV
2017-09-17 16:54:40 +02:00
parent 0abb38cf51
commit 5416a4ea8a
2 changed files with 16 additions and 9 deletions

View File

@@ -421,12 +421,15 @@ def parse_input(vds):
d['type'] = 'unknown'
d['num_sig'] = 0
if scriptSig:
if len(scriptSig) == 8:
d['value'] = struct.unpack_from('<Q', scriptSig, 0)[0]
d['scriptSig'] = ''
else:
if scriptSig[0] == 255:
d['value'] = struct.unpack_from('<Q', scriptSig, 1)[0]
scriptSig = scriptSig[9:]
if scriptSig:
d['scriptSig'] = bh2u(scriptSig)
parse_scriptSig(d, scriptSig)
else:
d['scriptSig'] = ''
return d
@@ -660,6 +663,8 @@ class Transaction:
return txin['scriptSig']
pubkeys, sig_list = self.get_siglist(txin, estimate_size)
script = ''.join(push_script(x) for x in sig_list)
if self.is_segwit_input(txin):
segwit_value = '' if self.is_txin_complete(txin) or estimate_size else 'ff' + int_to_hex(txin['value'], 8)
if _type == 'p2pk':
pass
elif _type == 'p2sh':
@@ -670,11 +675,10 @@ class Transaction:
elif _type == 'p2pkh':
script += push_script(pubkeys[0])
elif _type in ['p2wpkh', 'p2wsh']:
# if it is not complete we store the value
return '' if self.is_txin_complete(txin) or estimate_size else int_to_hex(txin['value'], 8)
return segwit_value
elif _type in ['p2wpkh-p2sh', 'p2wsh-p2sh']:
redeem_script = txin.get('redeemScript') or segwit_script(pubkeys[0])
return push_script(redeem_script)
return segwit_value + push_script(redeem_script)
elif _type == 'address':
script += push_script(pubkeys[0])
elif _type == 'unknown':
@@ -693,7 +697,7 @@ class Transaction:
# only for non-segwit
if txin['type'] == 'p2pkh':
return bitcoin.address_to_script(txin['address'])
elif txin['type'] in ['p2sh', 'p2wsh']:
elif txin['type'] in ['p2sh', 'p2wsh', 'p2wsh-p2sh']:
pubkeys, x_pubkeys = self.get_sorted_pubkeys(txin)
return multisig_script(pubkeys, txin['num_sig'])
elif txin['type'] in ['p2wpkh', 'p2wpkh-p2sh']: