Browse Source
json_db: only deserialize transactions on-demand
hard-fail-on-bad-server-string
SomberNight
5 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
2 changed files with
6 additions and
3 deletions
-
electrum/json_db.py
-
electrum/transaction.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(): |
|
|
|
|
|
@ -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. " |
|
|
|