diff --git a/electrum/json_db.py b/electrum/json_db.py index 10e6a0032..7a062a27b 100644 --- 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 index 420a439f6..8b36f11df 100644 --- 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. "