From 241ce6e8f347e01fe6889e78b05b5eefb2267549 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 20 Mar 2024 15:01:48 +0100 Subject: [PATCH] sendTransaction raises ProviderError instead of SignerError Allows it to contain error data. It is not the signing that fails, so it makes sense to use an error type that indicates that the provider failed. --- ethers/providers/jsonrpc.nim | 4 ++-- ethers/signer.nim | 2 +- ethers/signers/wallet.nim | 11 +++++------ testmodule/mocks.nim | 2 +- testmodule/providers/jsonrpc/testJsonRpcProvider.nim | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index 4135b1e..33442f8 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -324,9 +324,9 @@ method signMessage*( method sendTransaction*( signer: JsonRpcSigner, transaction: Transaction): Future[TransactionResponse] - {.async: (raises:[SignerError]).} = + {.async: (raises:[SignerError, ProviderError]).} = - convertSignerError: + convertError: if nonce =? transaction.nonce: signer.updateNonce(nonce) let diff --git a/ethers/signer.nim b/ethers/signer.nim index 13670a3..b38b6ed 100644 --- a/ethers/signer.nim +++ b/ethers/signer.nim @@ -43,7 +43,7 @@ method signMessage*( method sendTransaction*( signer: Signer, transaction: Transaction): Future[TransactionResponse] - {.base, async: (raises:[SignerError]).} = + {.base, async: (raises:[SignerError, ProviderError]).} = doAssert false, "not implemented" diff --git a/ethers/signers/wallet.nim b/ethers/signers/wallet.nim index 18a92cd..edc2254 100644 --- a/ethers/signers/wallet.nim +++ b/ethers/signers/wallet.nim @@ -83,10 +83,9 @@ proc signTransaction*(wallet: Wallet, method sendTransaction*( wallet: Wallet, transaction: Transaction): Future[TransactionResponse] - {.async: (raises:[SignerError]).} = + {.async: (raises:[SignerError, ProviderError]).} = - convertError: - let signed = await signTransaction(wallet, transaction) - if nonce =? transaction.nonce: - wallet.updateNonce(nonce) - return await provider(wallet).sendTransaction(signed) + let signed = await signTransaction(wallet, transaction) + if nonce =? transaction.nonce: + wallet.updateNonce(nonce) + return await provider(wallet).sendTransaction(signed) diff --git a/testmodule/mocks.nim b/testmodule/mocks.nim index eed2c23..a57102b 100644 --- a/testmodule/mocks.nim +++ b/testmodule/mocks.nim @@ -20,6 +20,6 @@ method getAddress*( method sendTransaction*( signer: MockSigner, transaction: Transaction): Future[TransactionResponse] - {.async: (raises:[SignerError]).} = + {.async: (raises:[SignerError, ProviderError]).} = signer.transactions.add(transaction) diff --git a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim index 10d78b1..0a3620f 100644 --- a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim +++ b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim @@ -97,7 +97,7 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]: discard await provider.getBlock(BlockTag.latest) expect JsonRpcProviderError: discard await provider.subscribe(proc(_: Block) = discard) - expect JsonRpcSignerError: + expect JsonRpcProviderError: discard await provider.getSigner().sendTransaction(Transaction.example) test "syncing":