-
Notifications
You must be signed in to change notification settings - Fork 185
feat: Add support for populating ContractId num value using MirrorNode query
#1565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
manishdait
wants to merge
11
commits into
hiero-ledger:main
Choose a base branch
from
manishdait:feat/contract-id-mirror-population
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5cbc242
feat: added support for mirror_query to contract_id
manishdait ae43496
chore: extend unit test for the contract_id
manishdait 7d4a305
feat: added integration test or contract_id
manishdait 2c2b488
feat: updated account_id mirror node population to follow contract_id…
manishdait 7203ac3
chore: added black formating to example
manishdait e224a0e
chore: updated changelog.md
manishdait fa38af7
chore: extended the unit test for contract_id
manishdait 753a67c
chore: fix some minimal errors
manishdait 9969570
chore: fix improper rebase issue
manishdait 966b598
chore: added coderabbit suggesttions
manishdait 4755c7b
chore: added wait_for_mirro_node util to e2e test
manishdait File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,9 +20,10 @@ | |
| PrivateKey, | ||
| TransferTransaction, | ||
| Hbar, | ||
| TransactionGetReceiptQuery | ||
| TransactionGetReceiptQuery, | ||
| ) | ||
|
|
||
|
|
||
| def generate_evm_address(): | ||
| """ | ||
| Generates a new ECDSA key pair and returns its EVM address. | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid fixed sleeps; poll the mirror node in examples. 💡 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: (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) | ||
|
|
||
|
|
@@ -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) | ||
|
|
||
|
|
@@ -139,6 +140,5 @@ def main(): | |
| populate_evm_address_example(client, created_account_id, evm_address) | ||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hyphenate “MirrorNode-based”.
Minor grammar fix per LanguageTool.
✏️ Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~124-~124: Use a hyphen to join words.
Context: ...estability. (
#1288) - Added MirrorNode based population forContractId, inclu...(QB_NEW_EN_HYPHEN)