@@ -568,24 +568,31 @@ async def transaction_pending(self, txn_hash: str) -> bool:
568568 raise ApiError (response .text , response .status_code )
569569 return response .json ()["type" ] == "pending_transaction"
570570
571+ async def _wait_for_txn (self , txn_hash : str ) -> None :
572+ while True :
573+ response = await self ._get (endpoint = f"transactions/wait_by_hash/{ txn_hash } " )
574+ if response .status_code >= 400 :
575+ raise ApiError (response .text , response .status_code )
576+ is_pending = response .json ()["type" ] == "pending_transaction"
577+ if not is_pending :
578+ assert (
579+ "success" in response .json () and response .json ()["success" ]
580+ ), f"{ response .text } - { txn_hash } "
581+ return
582+
571583 async def wait_for_transaction (self , txn_hash : str ) -> None :
572584 """
573585 Waits up to the duration specified in client_config for a transaction to move past pending
574586 state.
575587 """
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 } " )
586- assert (
587- "success" in response .json () and response .json ()["success" ]
588- ), f"{ response .text } - { txn_hash } "
588+ await asyncio .wait_for (
589+ self ._wait_for_txn (txn_hash ),
590+ timeout = (
591+ self .client_config .transaction_wait_in_seconds
592+ if self .client_config .transaction_wait_in_seconds
593+ else None
594+ ),
595+ )
589596
590597 async def account_transaction_sequence_number_status (
591598 self , address : AccountAddress , sequence_number : int
0 commit comments