mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-25 04:25:42 +00:00
core/sign_tx: Rework transaction header writing.
This commit is contained in:
parent
c1effcc374
commit
b60f267da9
@ -160,7 +160,9 @@ class Bitcoin:
|
||||
raise SigningError(FailureType.ActionCancelled, "Total cancelled")
|
||||
|
||||
async def step4_serialize_inputs(self) -> None:
|
||||
self.write_sign_tx_header(self.serialized_tx, bool(self.segwit))
|
||||
self.write_tx_header(self.serialized_tx, self.tx, bool(self.segwit))
|
||||
writers.write_varint(self.serialized_tx, self.tx.inputs_count)
|
||||
|
||||
for i in range(self.tx.inputs_count):
|
||||
progress.advance()
|
||||
if i in self.segwit:
|
||||
@ -294,7 +296,8 @@ class Bitcoin:
|
||||
# should come out the same as h_confirmed, checked before signing the digest
|
||||
h_check = self.create_hash_writer()
|
||||
|
||||
self.write_sign_tx_header(h_sign, has_segwit=False)
|
||||
self.write_tx_header(h_sign, self.tx, has_segwit=False)
|
||||
writers.write_varint(h_sign, self.tx.inputs_count)
|
||||
|
||||
for i in range(self.tx.inputs_count):
|
||||
# STAGE_REQUEST_4_INPUT
|
||||
@ -430,10 +433,6 @@ class Bitcoin:
|
||||
def write_tx_input(self, w: writers.Writer, txi: TxInputType) -> None:
|
||||
writers.write_tx_input(w, txi)
|
||||
|
||||
def write_sign_tx_header(self, w: writers.Writer, has_segwit: bool) -> None:
|
||||
self.write_tx_header(w, self.tx, has_segwit)
|
||||
writers.write_varint(w, self.tx.inputs_count)
|
||||
|
||||
def write_sign_tx_footer(self, w: writers.Writer) -> None:
|
||||
writers.write_uint32(w, self.tx.lock_time)
|
||||
|
||||
|
@ -69,7 +69,8 @@ class Decred(Bitcoin):
|
||||
return HashWriter(blake256())
|
||||
|
||||
async def step1_process_inputs(self) -> None:
|
||||
self.write_sign_tx_header(self.serialized_tx, False)
|
||||
self.write_tx_header(self.serialized_tx, self.tx, has_segwit=False)
|
||||
writers.write_varint(self.serialized_tx, self.tx.inputs_count)
|
||||
await super().step1_process_inputs()
|
||||
|
||||
async def step2_confirm_outputs(self) -> None:
|
||||
@ -179,14 +180,15 @@ class Decred(Bitcoin):
|
||||
def write_tx_input(self, w: writers.Writer, txi: TxInputType) -> None:
|
||||
writers.write_tx_input_decred(w, txi)
|
||||
|
||||
def write_sign_tx_header(self, w: writers.Writer, has_segwit: bool) -> None:
|
||||
writers.write_uint32(w, self.tx.version) # nVersion
|
||||
writers.write_varint(w, self.tx.inputs_count)
|
||||
|
||||
def write_tx_header(
|
||||
self, w: writers.Writer, tx: Union[SignTx, TransactionType], has_segwit: bool
|
||||
) -> None:
|
||||
writers.write_uint32(w, tx.version | DECRED_SERIALIZE_NO_WITNESS)
|
||||
if isinstance(tx, TransactionType):
|
||||
version = tx.version | DECRED_SERIALIZE_NO_WITNESS
|
||||
else:
|
||||
version = tx.version | DECRED_SERIALIZE_FULL
|
||||
|
||||
writers.write_uint32(w, version)
|
||||
|
||||
def write_sign_tx_footer(self, w: writers.Writer) -> None:
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user