mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 09:37:31 +00:00
json_db: only deserialize transactions on-demand
This commit is contained in:
parent
0fdbf49f08
commit
18c6451518
2 changed files with 6 additions and 3 deletions
|
@ -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():
|
||||
|
|
|
@ -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. "
|
||||
|
|
Loading…
Add table
Reference in a new issue