MCPcopy Create free account
hub / github.com/canopy-network/canopy / wait_for_tx_inclusion

Function wait_for_tx_inclusion

plugin/python/tutorial/rpc_test.py:121–140  ·  view source on GitHub ↗

Wait for a transaction to be included in a block.

(rpc_url: str, sender_addr: str, tx_hash: str, timeout_sec: float)

Source from the content-addressed store, hash-verified

119
120
121def 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
143def check_tx_not_failed(rpc_url: str, sender_addr: str) -> int:

Callers 1

test_plugin_transactionsFunction · 0.85

Calls 2

post_raw_jsonFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected