Skip to content

Commit

Permalink
update wait_for_tansaction api to support long poll
Browse files Browse the repository at this point in the history
  • Loading branch information
fishronsage committed Jun 4, 2024
1 parent e5e1ecb commit e3ab90c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions aptos_sdk/async_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright © Aptos Foundation
# SPDX-License-Identifier: Apache-2.0

import asyncio
import logging
import time
from typing import Any, Dict, List, Optional
Expand Down Expand Up @@ -573,16 +572,14 @@ 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}")
while True:
response = await self._get(endpoint=f"transactions/wait_by_hash/{txn_hash}")
if response.status_code == 404:
continue
if response.status_code >= 400:
raise ApiError(response.text, response.status_code)
if response.json()["type"] != "pending_transaction":
break
assert (
"success" in response.json() and response.json()["success"]
), f"{response.text} - {txn_hash}"
Expand Down

0 comments on commit e3ab90c

Please sign in to comment.