Skip to content
Open
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
- Added first-class support for EVM address aliases in `AccountId`, including parsing, serialization, Mirror Node population helpers.
- Add automated bot to recommend next issues to contributors after their first PR merge (#1380)
- Added dry-run support and refactored `.github/workflows/bot-workflows.yml` to use dedicated script `.github/scripts/bot-workflows.js` for improved maintainability and testability. (`#1288`)
- Added MirrorNode based population for `ContractId`, including parsing and serialization support.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Hyphenate “MirrorNode-based”.
Minor grammar fix per LanguageTool.

✏️ Proposed fix
-- Added MirrorNode based population for `ContractId`, including parsing and serialization support.
+- Added MirrorNode-based population for `ContractId`, including parsing and serialization support.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Added MirrorNode based population for `ContractId`, including parsing and serialization support.
- Added MirrorNode-based population for `ContractId`, including parsing and serialization support.
🧰 Tools
🪛 LanguageTool

[grammar] ~124-~124: Use a hyphen to join words.
Context: ...estability. (#1288) - Added MirrorNode based population for ContractId, inclu...

(QB_NEW_EN_HYPHEN)


### Changed
- chore: format tests/unit/mock_server.py with black (#1542)
Expand Down
26 changes: 13 additions & 13 deletions examples/account/account_id_populate_from_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
PrivateKey,
TransferTransaction,
Hbar,
TransactionGetReceiptQuery
TransactionGetReceiptQuery,
)


def generate_evm_address():
"""
Generates a new ECDSA key pair and returns its EVM address.
Expand Down Expand Up @@ -79,21 +80,21 @@ def populate_account_num_example(client, evm_address, created_account_id):
time.sleep(5)

try:
mirror_account_id.populate_account_num(client)
new_account_id = mirror_account_id.populate_account_num(client)
except Exception as e:
Comment on lines 80 to 84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid fixed sleeps; poll the mirror node in examples.
Mirror propagation is variable; a retry loop makes the example reliable for users.

💡 Suggested improvement
+def _wait_for_mirror(fn, timeout_s: float = 30, interval_s: float = 2):
+    end = time.time() + timeout_s
+    last_exc: Exception | None = None
+    while time.time() < end:
+        try:
+            return fn()
+        except (RuntimeError, ValueError) as exc:
+            last_exc = exc
+            time.sleep(interval_s)
+    raise RuntimeError(f"Mirror node did not update within {timeout_s}s") from last_exc
@@
-    time.sleep(5)
-
     try:
-        new_account_id = mirror_account_id.populate_account_num(client)
+        new_account_id = _wait_for_mirror(
+            lambda: mirror_account_id.populate_account_num(client)
+        )
@@
-    time.sleep(5)
-
     try:
-        new_account_id = created_account_id.populate_evm_address(client)
+        new_account_id = _wait_for_mirror(
+            lambda: created_account_id.populate_evm_address(client)
+        )

Also applies to: 110-114

🧰 Tools
🪛 Ruff (0.14.13)

84-84: Do not catch blind exception: Exception

(BLE001)

print(f"Failed to populate account number: {e}")
sys.exit(1)

print("After populate:")
print(f" Shard: {mirror_account_id.shard}")
print(f" Realm: {mirror_account_id.realm}")
print(f" Num: {mirror_account_id.num}")
print(f" Shard: {new_account_id.shard}")
print(f" Realm: {new_account_id.realm}")
print(f" Num: {new_account_id.num}")

if mirror_account_id.num != created_account_id.num:
if new_account_id.num != created_account_id.num:
print(
"Account number mismatch:\n"
f" Expected: {created_account_id.num}\n"
f" Got: {mirror_account_id.num}"
f" Got: {new_account_id.num}"
)
sys.exit(1)

Expand All @@ -109,18 +110,18 @@ def populate_evm_address_example(client, created_account_id, evm_address):
time.sleep(5)

try:
created_account_id.populate_evm_address(client)
new_account_id = created_account_id.populate_evm_address(client)
except Exception as e:
print(f"Failed to populate EVM address: {e}")
sys.exit(1)

print(f"After populate: evm_address = {created_account_id.evm_address}")
print(f"After populate: evm_address = {new_account_id.evm_address}")

if created_account_id.evm_address != evm_address:
if new_account_id.evm_address != evm_address:
print(
"EVM address mismatch:\n"
f" Expected: {evm_address}\n"
f" Got: {created_account_id.evm_address}"
f" Got: {new_account_id.evm_address}"
)
sys.exit(1)

Expand All @@ -139,6 +140,5 @@ def main():
populate_evm_address_example(client, created_account_id, evm_address)



if __name__ == "__main__":
main()
main()
Loading