Browse Source

transaction.serialize_preimage: trivial clean-up

dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
SomberNight 6 years ago
parent
commit
a14016275b
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 10
      electrum/transaction.py

10
electrum/transaction.py

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

Loading…
Cancel
Save