EstimateGasError is a ProviderError instead of a SignerError
Which allows for it to contain error data
This commit is contained in:
parent
80fcb246f6
commit
1ce9824738
|
@ -15,6 +15,8 @@ type
|
||||||
Provider* = ref object of RootObj
|
Provider* = ref object of RootObj
|
||||||
ProviderError* = object of EthersError
|
ProviderError* = object of EthersError
|
||||||
data*: ?seq[byte]
|
data*: ?seq[byte]
|
||||||
|
EstimateGasError* = object of ProviderError
|
||||||
|
transaction*: Transaction
|
||||||
Subscription* = ref object of RootObj
|
Subscription* = ref object of RootObj
|
||||||
EventFilter* {.serialize.} = ref object of RootObj
|
EventFilter* {.serialize.} = ref object of RootObj
|
||||||
address*: Address
|
address*: Address
|
||||||
|
|
|
@ -199,9 +199,17 @@ method estimateGas*(
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
blockTag = BlockTag.latest): Future[UInt256] {.async: (raises:[ProviderError]).} =
|
blockTag = BlockTag.latest): Future[UInt256] {.async: (raises:[ProviderError]).} =
|
||||||
|
|
||||||
convertError:
|
try:
|
||||||
let client = await provider.client
|
convertError:
|
||||||
return await client.eth_estimateGas(transaction, blockTag)
|
let client = await provider.client
|
||||||
|
return await client.eth_estimateGas(transaction, blockTag)
|
||||||
|
except ProviderError as error:
|
||||||
|
raise (ref EstimateGasError)(
|
||||||
|
msg: "Estimate gas failed: " & error.msg,
|
||||||
|
data: error.data,
|
||||||
|
transaction: transaction,
|
||||||
|
parent: error
|
||||||
|
)
|
||||||
|
|
||||||
method getChainId*(
|
method getChainId*(
|
||||||
provider: JsonRpcProvider): Future[UInt256] {.async: (raises:[ProviderError]).} =
|
provider: JsonRpcProvider): Future[UInt256] {.async: (raises:[ProviderError]).} =
|
||||||
|
|
|
@ -11,27 +11,15 @@ type
|
||||||
lastSeenNonce: ?UInt256
|
lastSeenNonce: ?UInt256
|
||||||
populateLock: AsyncLock
|
populateLock: AsyncLock
|
||||||
SignerError* = object of EthersError
|
SignerError* = object of EthersError
|
||||||
EstimateGasError* = object of SignerError
|
|
||||||
transaction*: Transaction
|
|
||||||
|
|
||||||
template raiseSignerError(message: string, parent: ref ProviderError = nil) =
|
template raiseSignerError(message: string, parent: ref ProviderError = nil) =
|
||||||
raise newException(SignerError, message, parent)
|
raise newException(SignerError, message, parent)
|
||||||
|
|
||||||
proc raiseEstimateGasError(
|
|
||||||
transaction: Transaction,
|
|
||||||
parent: ref ProviderError = nil
|
|
||||||
) {.raises: [EstimateGasError] .} =
|
|
||||||
let e = (ref EstimateGasError)(
|
|
||||||
msg: "Estimate gas failed",
|
|
||||||
transaction: transaction,
|
|
||||||
parent: parent)
|
|
||||||
raise e
|
|
||||||
|
|
||||||
template convertError(body) =
|
template convertError(body) =
|
||||||
try:
|
try:
|
||||||
body
|
body
|
||||||
except EthersError as error:
|
except ProviderError as error:
|
||||||
raiseSignerError(error.msg)
|
raise error # do not convert provider errors
|
||||||
except CatchableError as error:
|
except CatchableError as error:
|
||||||
raiseSignerError(error.msg)
|
raiseSignerError(error.msg)
|
||||||
|
|
||||||
|
@ -68,7 +56,7 @@ method getGasPrice*(
|
||||||
method getTransactionCount*(
|
method getTransactionCount*(
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
blockTag = BlockTag.latest): Future[UInt256]
|
blockTag = BlockTag.latest): Future[UInt256]
|
||||||
{.base, async: (raises:[SignerError]).} =
|
{.base, async: (raises:[SignerError, ProviderError]).} =
|
||||||
|
|
||||||
convertError:
|
convertError:
|
||||||
let address = await signer.getAddress()
|
let address = await signer.getAddress()
|
||||||
|
@ -78,19 +66,11 @@ method estimateGas*(
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
transaction: Transaction,
|
transaction: Transaction,
|
||||||
blockTag = BlockTag.latest): Future[UInt256]
|
blockTag = BlockTag.latest): Future[UInt256]
|
||||||
{.base, async: (raises:[SignerError]).} =
|
{.base, async: (raises:[SignerError, ProviderError]).} =
|
||||||
|
|
||||||
var transaction = transaction
|
var transaction = transaction
|
||||||
var address: Address
|
transaction.sender = some(await signer.getAddress())
|
||||||
|
return await signer.provider.estimateGas(transaction, blockTag)
|
||||||
convertError:
|
|
||||||
address = await signer.getAddress
|
|
||||||
|
|
||||||
transaction.sender = some(address)
|
|
||||||
try:
|
|
||||||
return await signer.provider.estimateGas(transaction, blockTag)
|
|
||||||
except ProviderError as e:
|
|
||||||
raiseEstimateGasError transaction, e
|
|
||||||
|
|
||||||
method getChainId*(
|
method getChainId*(
|
||||||
signer: Signer): Future[UInt256]
|
signer: Signer): Future[UInt256]
|
||||||
|
@ -99,7 +79,7 @@ method getChainId*(
|
||||||
return await signer.provider.getChainId()
|
return await signer.provider.getChainId()
|
||||||
|
|
||||||
method getNonce(
|
method getNonce(
|
||||||
signer: Signer): Future[UInt256] {.base, async: (raises: [SignerError]).} =
|
signer: Signer): Future[UInt256] {.base, async: (raises: [SignerError, ProviderError]).} =
|
||||||
|
|
||||||
var nonce = await signer.getTransactionCount(BlockTag.pending)
|
var nonce = await signer.getTransactionCount(BlockTag.pending)
|
||||||
|
|
||||||
|
@ -183,7 +163,7 @@ method populateTransaction*(
|
||||||
method cancelTransaction*(
|
method cancelTransaction*(
|
||||||
signer: Signer,
|
signer: Signer,
|
||||||
tx: Transaction
|
tx: Transaction
|
||||||
): Future[TransactionResponse] {.base, async: (raises: [SignerError]).} =
|
): Future[TransactionResponse] {.base, async: (raises: [SignerError, ProviderError]).} =
|
||||||
# cancels a transaction by sending with a 0-valued transaction to ourselves
|
# cancels a transaction by sending with a 0-valued transaction to ourselves
|
||||||
# with the failed tx's nonce
|
# with the failed tx's nonce
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue