1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 12:28:09 +00:00

refactor(core/bitcoin): Use global static buffer for Tx serialization.

This commit is contained in:
Andrew Kozlik 2021-03-16 16:45:01 +01:00 committed by Andrew Kozlik
parent fb9b53930e
commit 8538f55edc

View File

@ -36,6 +36,7 @@ if False:
# the number of bytes to preallocate for serialized transaction chunks # the number of bytes to preallocate for serialized transaction chunks
_MAX_SERIALIZED_CHUNK_SIZE = const(2048) _MAX_SERIALIZED_CHUNK_SIZE = const(2048)
_SERIALIZED_TX_BUFFER = empty_bytearray(_MAX_SERIALIZED_CHUNK_SIZE)
class Bitcoin: class Bitcoin:
@ -77,6 +78,8 @@ class Bitcoin:
coin: CoinInfo, coin: CoinInfo,
approver: approvers.Approver | None, approver: approvers.Approver | None,
) -> None: ) -> None:
global _SERIALIZED_TX_BUFFER
self.tx_info = TxInfo(self, helpers.sanitize_sign_tx(tx, coin)) self.tx_info = TxInfo(self, helpers.sanitize_sign_tx(tx, coin))
self.keychain = keychain self.keychain = keychain
self.coin = coin self.coin = coin
@ -93,7 +96,8 @@ class Bitcoin:
self.external: set[int] = set() self.external: set[int] = set()
# transaction and signature serialization # transaction and signature serialization
self.serialized_tx = empty_bytearray(_MAX_SERIALIZED_CHUNK_SIZE) _SERIALIZED_TX_BUFFER[:] = bytes()
self.serialized_tx = _SERIALIZED_TX_BUFFER
self.tx_req = TxRequest() self.tx_req = TxRequest()
self.tx_req.details = TxRequestDetailsType() self.tx_req.details = TxRequestDetailsType()
self.tx_req.serialized = TxRequestSerializedType() self.tx_req.serialized = TxRequestSerializedType()