From 568e7d674c0056b8449f9acd18a276af05024983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 30 Sep 2025 13:41:58 +0300 Subject: [PATCH] Attempt optimization (around Address). --- multiversx_sdk/core/address.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/multiversx_sdk/core/address.py b/multiversx_sdk/core/address.py index 38fecea6..8e67fb48 100644 --- a/multiversx_sdk/core/address.py +++ b/multiversx_sdk/core/address.py @@ -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": @@ -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: