|
|
@ -958,14 +958,13 @@ class Transaction: |
|
|
|
s += script |
|
|
|
return s |
|
|
|
|
|
|
|
def serialize_preimage(self, i): |
|
|
|
def serialize_preimage(self, txin_index: int) -> str: |
|
|
|
nVersion = int_to_hex(self.version, 4) |
|
|
|
nHashType = int_to_hex(1, 4) |
|
|
|
nHashType = int_to_hex(1, 4) # SIGHASH_ALL |
|
|
|
nLocktime = int_to_hex(self.locktime, 4) |
|
|
|
inputs = self.inputs() |
|
|
|
outputs = self.outputs() |
|
|
|
txin = inputs[i] |
|
|
|
# TODO: py3 hex |
|
|
|
txin = inputs[txin_index] |
|
|
|
if self.is_segwit_input(txin): |
|
|
|
hashPrevouts = bh2u(sha256d(bfh(''.join(self.serialize_outpoint(txin) for txin in inputs)))) |
|
|
|
hashSequence = bh2u(sha256d(bfh(''.join(int_to_hex(txin.get('sequence', 0xffffffff - 1), 4) for txin in inputs)))) |
|
|
@ -977,7 +976,8 @@ class Transaction: |
|
|
|
nSequence = int_to_hex(txin.get('sequence', 0xffffffff - 1), 4) |
|
|
|
preimage = nVersion + hashPrevouts + hashSequence + outpoint + scriptCode + amount + nSequence + hashOutputs + nLocktime + nHashType |
|
|
|
else: |
|
|
|
txins = var_int(len(inputs)) + ''.join(self.serialize_input(txin, self.get_preimage_script(txin) if i==k else '') for k, txin in enumerate(inputs)) |
|
|
|
txins = var_int(len(inputs)) + ''.join(self.serialize_input(txin, self.get_preimage_script(txin) if txin_index==k else '') |
|
|
|
for k, txin in enumerate(inputs)) |
|
|
|
txouts = var_int(len(outputs)) + ''.join(self.serialize_output(o) for o in outputs) |
|
|
|
preimage = nVersion + txins + txouts + nLocktime + nHashType |
|
|
|
return preimage |
|
|
|