1
0

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.
This commit is contained in:
Sebastian Falbesoner
2021-05-29 20:44:15 +02:00
committed by SomberNight
parent 71697afabd
commit ede9b2b372

View File

@@ -148,9 +148,18 @@ class TxOutput:
return cls(scriptpubkey=bfh(addr), value=val)
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
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:
addr = self.address