diff --git a/core/src/apps/wallet/sign_tx/bitcoin.py b/core/src/apps/wallet/sign_tx/bitcoin.py index 5c386c2b3a..7cc225f83f 100644 --- a/core/src/apps/wallet/sign_tx/bitcoin.py +++ b/core/src/apps/wallet/sign_tx/bitcoin.py @@ -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: diff --git a/core/src/apps/wallet/sign_tx/bitcoinlike.py b/core/src/apps/wallet/sign_tx/bitcoinlike.py index 411bad85fa..a80702eb53 100644 --- a/core/src/apps/wallet/sign_tx/bitcoinlike.py +++ b/core/src/apps/wallet/sign_tx/bitcoinlike.py @@ -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: diff --git a/core/src/apps/wallet/sign_tx/decred.py b/core/src/apps/wallet/sign_tx/decred.py index 4962476594..be8f311a72 100644 --- a/core/src/apps/wallet/sign_tx/decred.py +++ b/core/src/apps/wallet/sign_tx/decred.py @@ -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: diff --git a/core/src/apps/wallet/sign_tx/writers.py b/core/src/apps/wallet/sign_tx/writers.py index be4912994d..938fa7d302 100644 --- a/core/src/apps/wallet/sign_tx/writers.py +++ b/core/src/apps/wallet/sign_tx/writers.py @@ -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)