Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions multiversx_sdk/core/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, pubkey: bytes, hrp: Optional[str] = None) -> None:

self.pubkey = bytes(pubkey)
self.hrp = hrp if hrp else LibraryConfig.default_address_hrp
self._cached_bech32 = ""

@classmethod
def empty(cls) -> "Address":
Expand Down Expand Up @@ -72,9 +73,13 @@ def to_bech32(self) -> str:
if self.is_empty():
return ""

if self._cached_bech32:
return self._cached_bech32

converted = bech32.convertbits(self.pubkey, 8, 5)
assert converted is not None
encoded = bech32.bech32_encode(self.hrp, converted)
self._cached_bech32 = encoded
return encoded

def get_public_key(self) -> bytes:
Expand Down
Loading