Wait for a transaction to be included in a block.
(rpc_url: str, sender_addr: str, tx_hash: str, timeout_sec: float)
| 119 | |
| 120 | |
| 121 | def wait_for_tx_inclusion(rpc_url: str, sender_addr: str, tx_hash: str, timeout_sec: float) -> bool: |
| 122 | """Wait for a transaction to be included in a block.""" |
| 123 | deadline = time.time() + timeout_sec |
| 124 | |
| 125 | while time.time() < deadline: |
| 126 | try: |
| 127 | req_json = json.dumps({"address": sender_addr, "perPage": 20}) |
| 128 | resp_body = post_raw_json(f"{rpc_url}/v1/query/txs-by-sender", req_json) |
| 129 | result = json.loads(resp_body) |
| 130 | |
| 131 | # Check if our transaction is in the results |
| 132 | for tx in result.get('results', []): |
| 133 | if tx.get('txHash') == tx_hash: |
| 134 | return True |
| 135 | except Exception: |
| 136 | pass |
| 137 | |
| 138 | time.sleep(1) |
| 139 | |
| 140 | return False |
| 141 | |
| 142 | |
| 143 | def check_tx_not_failed(rpc_url: str, sender_addr: str) -> int: |
no test coverage detected