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:
committed by
SomberNight
parent
71697afabd
commit
ede9b2b372
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user