electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 18c64515188494f05e517a099a7356d378a14bda
parent 0fdbf49f089251ef15b0da18ba6522dfbc02ee74
Author: SomberNight <somber.night@protonmail.com>
Date:   Sun, 19 Jan 2020 05:49:12 +0100

json_db: only deserialize transactions on-demand

Diffstat:
Melectrum/json_db.py | 3++-
Melectrum/transaction.py | 6++++--
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/electrum/json_db.py b/electrum/json_db.py @@ -913,7 +913,8 @@ class JsonDB(Logger): self._prevouts_by_scripthash = self.get_data_ref('prevouts_by_scripthash') # type: Dict[str, Set[Tuple[str, int]]] # convert raw transactions to Transaction objects for tx_hash, raw_tx in self.transactions.items(): - self.transactions[tx_hash] = tx_from_any(raw_tx) + # note: for performance, "deserialize=False" so that we will deserialize these on-demand + self.transactions[tx_hash] = tx_from_any(raw_tx, deserialize=False) # convert txi, txo: list to set for t in self.txi, self.txo: for d in t.values(): diff --git a/electrum/transaction.py b/electrum/transaction.py @@ -932,7 +932,8 @@ def convert_raw_tx_to_hex(raw: Union[str, bytes]) -> str: raise ValueError(f"failed to recognize transaction encoding for txt: {raw[:30]}...") -def tx_from_any(raw: Union[str, bytes]) -> Union['PartialTransaction', 'Transaction']: +def tx_from_any(raw: Union[str, bytes], *, + deserialize: bool = True) -> Union['PartialTransaction', 'Transaction']: if isinstance(raw, bytearray): raw = bytes(raw) raw = convert_raw_tx_to_hex(raw) @@ -945,7 +946,8 @@ def tx_from_any(raw: Union[str, bytes]) -> Union['PartialTransaction', 'Transact "the other machine where this transaction was created.") try: tx = Transaction(raw) - tx.deserialize() + if deserialize: + tx.deserialize() return tx except Exception as e: raise SerializationError(f"Failed to recognise tx encoding, or to parse transaction. "