Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions aptos_sdk/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,24 +568,31 @@ async def transaction_pending(self, txn_hash: str) -> bool:
raise ApiError(response.text, response.status_code)
return response.json()["type"] == "pending_transaction"

async def _wait_for_txn(self, txn_hash: str) -> None:
while True:
response = await self._get(endpoint=f"transactions/wait_by_hash/{txn_hash}")
if response.status_code >= 400:
raise ApiError(response.text, response.status_code)
is_pending = response.json()["type"] == "pending_transaction"
if not is_pending:
assert (
"success" in response.json() and response.json()["success"]
), f"{response.text} - {txn_hash}"
return

async def wait_for_transaction(self, txn_hash: str) -> None:
"""
Waits up to the duration specified in client_config for a transaction to move past pending
state.
"""

count = 0
while await self.transaction_pending(txn_hash):
assert (
count < self.client_config.transaction_wait_in_seconds
), f"transaction {txn_hash} timed out"
await asyncio.sleep(1)
count += 1

response = await self._get(endpoint=f"transactions/by_hash/{txn_hash}")
assert (
"success" in response.json() and response.json()["success"]
), f"{response.text} - {txn_hash}"
await asyncio.wait_for(
self._wait_for_txn(txn_hash),
timeout=(
self.client_config.transaction_wait_in_seconds
if self.client_config.transaction_wait_in_seconds
else None
),
)

async def account_transaction_sequence_number_status(
self, address: AccountAddress, sequence_number: int
Expand Down