Browse Source

transaction: cache address determination from output script

In order to avoid repeatedly calling get_addr_from_output_script() on
every read of the "TxOutput.address" property, determine and cache it
only whenever the output script is created/changed.
master
Sebastian Falbesoner 5 years ago committed by SomberNight
parent
commit
ede9b2b372
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 11
      electrum/transaction.py

11
electrum/transaction.py

@ -148,9 +148,18 @@ class TxOutput:
return cls(scriptpubkey=bfh(addr), value=val) return cls(scriptpubkey=bfh(addr), value=val)
raise Exception(f"unexpected legacy address type: {_type}") raise Exception(f"unexpected legacy address type: {_type}")
@property
def scriptpubkey(self) -> bytes:
return self._scriptpubkey
@scriptpubkey.setter
def scriptpubkey(self, scriptpubkey: bytes):
self._scriptpubkey = scriptpubkey
self._address = get_address_from_output_script(scriptpubkey)
@property @property
def address(self) -> Optional[str]: def address(self) -> Optional[str]:
return get_address_from_output_script(self.scriptpubkey) # TODO cache this? return self._address
def get_ui_address_str(self) -> str: def get_ui_address_str(self) -> str:
addr = self.address addr = self.address

Loading…
Cancel
Save