Skip to content

Commit e3ab90c

Browse files
committed
update wait_for_tansaction api to support long poll
1 parent e5e1ecb commit e3ab90c

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

aptos_sdk/async_client.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright © Aptos Foundation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
import asyncio
54
import logging
65
import time
76
from typing import Any, Dict, List, Optional
@@ -573,16 +572,14 @@ async def wait_for_transaction(self, txn_hash: str) -> None:
573572
Waits up to the duration specified in client_config for a transaction to move past pending
574573
state.
575574
"""
576-
577-
count = 0
578-
while await self.transaction_pending(txn_hash):
579-
assert (
580-
count < self.client_config.transaction_wait_in_seconds
581-
), f"transaction {txn_hash} timed out"
582-
await asyncio.sleep(1)
583-
count += 1
584-
585-
response = await self._get(endpoint=f"transactions/by_hash/{txn_hash}")
575+
while True:
576+
response = await self._get(endpoint=f"transactions/wait_by_hash/{txn_hash}")
577+
if response.status_code == 404:
578+
continue
579+
if response.status_code >= 400:
580+
raise ApiError(response.text, response.status_code)
581+
if response.json()["type"] != "pending_transaction":
582+
break
586583
assert (
587584
"success" in response.json() and response.json()["success"]
588585
), f"{response.text} - {txn_hash}"

0 commit comments

Comments
 (0)