mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 03:50:58 +00:00
core/sign_tx: Add write_tx_output() to signer class and override it in Decred.
This commit is contained in:
parent
bdd1d25979
commit
dccf415e0b
@ -226,7 +226,7 @@ class Bitcoin:
|
||||
elif not await helpers.confirm_output(txo, self.coin):
|
||||
raise SigningError(FailureType.ActionCancelled, "Output cancelled")
|
||||
|
||||
writers.write_tx_output(self.h_confirmed, txo_bin)
|
||||
self.write_tx_output(self.h_confirmed, txo_bin)
|
||||
self.hash143_add_output(txo_bin)
|
||||
self.total_out += txo_bin.amount
|
||||
|
||||
@ -345,8 +345,8 @@ class Bitcoin:
|
||||
txo = await helpers.request_tx_output(self.tx_req, i, self.coin)
|
||||
txo_bin.amount = txo.amount
|
||||
txo_bin.script_pubkey = self.output_derive_script(txo)
|
||||
writers.write_tx_output(h_check, txo_bin)
|
||||
writers.write_tx_output(h_sign, txo_bin)
|
||||
self.write_tx_output(h_check, txo_bin)
|
||||
self.write_tx_output(h_sign, txo_bin)
|
||||
|
||||
writers.write_uint32(h_sign, self.tx.lock_time)
|
||||
writers.write_uint32(h_sign, self.get_hash_type())
|
||||
@ -376,7 +376,7 @@ class Bitcoin:
|
||||
txo_bin = TxOutputBinType()
|
||||
txo_bin.amount = txo.amount
|
||||
txo_bin.script_pubkey = self.output_derive_script(txo)
|
||||
writers.write_tx_output(self.serialized_tx, txo_bin)
|
||||
self.write_tx_output(self.serialized_tx, txo_bin)
|
||||
|
||||
async def get_prevtx_output_value(self, prev_hash: bytes, prev_index: int) -> int:
|
||||
amount_out = 0 # output amount
|
||||
@ -407,7 +407,7 @@ class Bitcoin:
|
||||
txo_bin = await helpers.request_tx_output(
|
||||
self.tx_req, i, self.coin, prev_hash
|
||||
)
|
||||
writers.write_tx_output(txh, txo_bin)
|
||||
self.write_tx_output(txh, txo_bin)
|
||||
if i == prev_index:
|
||||
amount_out = txo_bin.amount
|
||||
self.check_prevtx_output(txo_bin)
|
||||
@ -437,6 +437,9 @@ class Bitcoin:
|
||||
def write_tx_input(self, w: writers.Writer, txi: TxInputType) -> None:
|
||||
writers.write_tx_input(w, txi)
|
||||
|
||||
def write_tx_output(self, w: writers.Writer, txo_bin: TxOutputBinType) -> None:
|
||||
writers.write_tx_output(w, txo_bin)
|
||||
|
||||
def write_tx_header(
|
||||
self, w: writers.Writer, tx: Union[SignTx, TransactionType], has_segwit: bool
|
||||
) -> None:
|
||||
|
@ -44,7 +44,7 @@ class Bitcoinlike(Bitcoin):
|
||||
# serialize input with correct signature
|
||||
gc.collect()
|
||||
txi.script_sig = self.input_derive_script(txi, public_key, signature)
|
||||
writers.write_tx_input(self.serialized_tx, txi)
|
||||
self.write_tx_input(self.serialized_tx, txi)
|
||||
self.set_serialized_signature(i_sign, signature)
|
||||
|
||||
async def sign_nonsegwit_input(self, i_sign: int) -> None:
|
||||
|
@ -68,7 +68,7 @@ class Decred(Bitcoin):
|
||||
)
|
||||
txo_bin.decred_script_version = txo.decred_script_version
|
||||
await super().confirm_output(i, txo, txo_bin)
|
||||
writers.write_tx_output(self.serialized_tx, txo_bin)
|
||||
self.write_tx_output(self.serialized_tx, txo_bin)
|
||||
|
||||
async def step4_serialize_inputs(self) -> None:
|
||||
writers.write_varint(self.serialized_tx, self.tx.inputs_count)
|
||||
@ -154,11 +154,14 @@ class Decred(Bitcoin):
|
||||
writers.write_tx_input_decred(self.h_prefix, txi)
|
||||
|
||||
def hash143_add_output(self, txo_bin: TxOutputBinType) -> None:
|
||||
writers.write_tx_output(self.h_prefix, txo_bin)
|
||||
writers.write_tx_output_decred(self.h_prefix, txo_bin)
|
||||
|
||||
def write_tx_input(self, w: writers.Writer, txi: TxInputType) -> None:
|
||||
writers.write_tx_input_decred(w, txi)
|
||||
|
||||
def write_tx_output(self, w: writers.Writer, txo_bin: TxOutputBinType) -> None:
|
||||
writers.write_tx_output_decred(w, txo_bin)
|
||||
|
||||
def write_tx_header(
|
||||
self, w: writers.Writer, tx: Union[SignTx, TransactionType], has_segwit: bool
|
||||
) -> None:
|
||||
|
@ -65,6 +65,11 @@ def write_tx_input_decred_witness(w: Writer, i: TxInputType) -> None:
|
||||
|
||||
|
||||
def write_tx_output(w: Writer, o: TxOutputBinType) -> None:
|
||||
write_uint64(w, o.amount)
|
||||
write_bytes_prefixed(w, o.script_pubkey)
|
||||
|
||||
|
||||
def write_tx_output_decred(w: Writer, o: TxOutputBinType) -> None:
|
||||
write_uint64(w, o.amount)
|
||||
if o.decred_script_version is not None:
|
||||
write_uint16(w, o.decred_script_version)
|
||||
|
Loading…
Reference in New Issue
Block a user