From 5d07b5dbcf584b020c732e84cc8b7229ab3e1083 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Tue, 18 Mar 2025 08:12:24 +0100 Subject: [PATCH] Define raises for async pragma --- ethers/contract.nim | 16 +++++++++++++--- ethers/provider.nim | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/ethers/contract.nim b/ethers/contract.nim index ac5d87d..68a1671 100644 --- a/ethers/contract.nim +++ b/ethers/contract.nim @@ -321,7 +321,7 @@ proc subscribe*[E: Event](contract: Contract, contract.provider.subscribe(filter, logHandler) proc confirm(tx: Confirmable, confirmations, timeout: int): - Future[TransactionReceipt] {.async.} = + Future[TransactionReceipt] {.async: (raises: [CancelledError, EthersError]).} = without response =? tx.response: raise newException( @@ -338,13 +338,23 @@ proc confirm(tx: Confirmable, confirmations, timeout: int): proc confirm*(tx: Future[Confirmable], confirmations: int = EthersDefaultConfirmations, timeout: int = EthersReceiptTimeoutBlks): - Future[TransactionReceipt] {.async.} = + Future[TransactionReceipt] {.async: (raises: [CancelledError, EthersError]).} = ## Convenience method that allows confirm to be chained to a contract ## transaction, eg: ## `await token.connect(signer0) ## .mint(accounts[1], 100.u256) ## .confirm(3)` - return await (await tx).confirm(confirmations, timeout) + try: + return await (await tx).confirm(confirmations, timeout) + except CancelledError as e: + raise e + except EthersError as e: + raise e + except CatchableError as e: + raise newException( + EthersError, + "Error when trying to confirm the contract transaction: " & e.msg + ) proc queryFilter[E: Event](contract: Contract, _: type E, diff --git a/ethers/provider.nim b/ethers/provider.nim index 8dfb30a..5a2153e 100644 --- a/ethers/provider.nim +++ b/ethers/provider.nim @@ -293,13 +293,22 @@ proc confirm*( proc confirm*( tx: Future[TransactionResponse], confirmations: int = EthersDefaultConfirmations, - timeout: int = EthersReceiptTimeoutBlks): Future[TransactionReceipt] {.async.} = + timeout: int = EthersReceiptTimeoutBlks): Future[TransactionReceipt] {.async: (raises: [CancelledError, EthersError]).} = ## Convenience method that allows wait to be chained to a sendTransaction ## call, eg: ## `await signer.sendTransaction(populated).confirm(3)` - - let txResp = await tx - return await txResp.confirm(confirmations, timeout) + try: + let txResp = await tx + return await txResp.confirm(confirmations, timeout) + except CancelledError as e: + raise e + except EthersError as e: + raise e + except CatchableError as e: + raise newException( + EthersError, + "Error when trying to confirm the provider transaction: " & e.msg + ) method close*( provider: Provider