mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-11 01:53:07 +00:00
Update revertReason to work with SignerError
Also update the estimateGas error message, and add the revert exception as the parent.
This commit is contained in:
parent
c22b7d479f
commit
d06edb317b
@ -14,8 +14,8 @@ type
|
||||
|
||||
type SignerError* = object of EthersError
|
||||
|
||||
template raiseSignerError(message: string) =
|
||||
raise newException(SignerError, message)
|
||||
template raiseSignerError(message: string, parent: ref ProviderError = nil) =
|
||||
raise newException(SignerError, message, parent)
|
||||
|
||||
method provider*(signer: Signer): Provider {.base, gcsafe.} =
|
||||
doAssert false, "not implemented"
|
||||
@ -123,8 +123,8 @@ method populateTransaction*(signer: Signer,
|
||||
except ProviderError as e:
|
||||
# send a 0-valued transaction with the errored nonce to prevent stuck txs
|
||||
discard await signer.cancelTransaction(populated)
|
||||
raiseSignerError "estimateGas failed. *A cancellation transaction " &
|
||||
"(0-valued tx to ourselves with the estimateGas nonce) has been sent " &
|
||||
"to prevent stuck transactions.* Error: " & e.msg
|
||||
raiseSignerError "Estimate gas failed -- A cancellation transaction " &
|
||||
"has been sent to prevent stuck transactions. See parent exception " &
|
||||
"for revert reason.", e
|
||||
|
||||
return populated
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import std/strutils
|
||||
import ./provider
|
||||
import ./signer
|
||||
|
||||
proc revertReason*(e: ref ProviderError): string =
|
||||
proc revertReason*(e: ref EthersError): string =
|
||||
var msg = e.msg
|
||||
const revertPrefixes = @[
|
||||
# hardhat
|
||||
@ -22,7 +23,7 @@ proc reverts*[T](call: Future[T]): Future[bool] {.async.} =
|
||||
else:
|
||||
discard await call
|
||||
return false
|
||||
except ProviderError:
|
||||
except ProviderError, SignerError:
|
||||
return true
|
||||
|
||||
proc reverts*[T](call: Future[T], reason: string): Future[bool] {.async.} =
|
||||
@ -32,5 +33,11 @@ proc reverts*[T](call: Future[T], reason: string): Future[bool] {.async.} =
|
||||
else:
|
||||
discard await call
|
||||
return false
|
||||
except ProviderError as error:
|
||||
return reason == error.revertReason
|
||||
except EthersError as error:
|
||||
var passed = reason == error.revertReason
|
||||
if not passed and
|
||||
not error.parent.isNil and
|
||||
error.parent of (ref EthersError):
|
||||
let revertReason = (ref EthersError)(error.parent).revertReason
|
||||
passed = reason == revertReason
|
||||
return passed
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user