Define raises for async pragma

This commit is contained in:
Arnaud 2025-03-18 08:12:24 +01:00 committed by GitHub
parent b505ef1ab8
commit 5d07b5dbcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 7 deletions

View File

@ -321,7 +321,7 @@ proc subscribe*[E: Event](contract: Contract,
contract.provider.subscribe(filter, logHandler) contract.provider.subscribe(filter, logHandler)
proc confirm(tx: Confirmable, confirmations, timeout: int): proc confirm(tx: Confirmable, confirmations, timeout: int):
Future[TransactionReceipt] {.async.} = Future[TransactionReceipt] {.async: (raises: [CancelledError, EthersError]).} =
without response =? tx.response: without response =? tx.response:
raise newException( raise newException(
@ -338,13 +338,23 @@ proc confirm(tx: Confirmable, confirmations, timeout: int):
proc confirm*(tx: Future[Confirmable], proc confirm*(tx: Future[Confirmable],
confirmations: int = EthersDefaultConfirmations, confirmations: int = EthersDefaultConfirmations,
timeout: int = EthersReceiptTimeoutBlks): timeout: int = EthersReceiptTimeoutBlks):
Future[TransactionReceipt] {.async.} = Future[TransactionReceipt] {.async: (raises: [CancelledError, EthersError]).} =
## Convenience method that allows confirm to be chained to a contract ## Convenience method that allows confirm to be chained to a contract
## transaction, eg: ## transaction, eg:
## `await token.connect(signer0) ## `await token.connect(signer0)
## .mint(accounts[1], 100.u256) ## .mint(accounts[1], 100.u256)
## .confirm(3)` ## .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, proc queryFilter[E: Event](contract: Contract,
_: type E, _: type E,

View File

@ -293,13 +293,22 @@ proc confirm*(
proc confirm*( proc confirm*(
tx: Future[TransactionResponse], tx: Future[TransactionResponse],
confirmations: int = EthersDefaultConfirmations, 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 ## Convenience method that allows wait to be chained to a sendTransaction
## call, eg: ## call, eg:
## `await signer.sendTransaction(populated).confirm(3)` ## `await signer.sendTransaction(populated).confirm(3)`
try:
let txResp = await tx let txResp = await tx
return await txResp.confirm(confirmations, timeout) 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*( method close*(
provider: Provider provider: Provider