From f1a1221d14291012e325798603ddba47f184b559 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 4 Jul 2023 10:40:22 +0200 Subject: [PATCH] Move WalletError into its own module --- ethers/wallet.nim | 13 +++++++------ ethers/wallet/error.nim | 7 +++++++ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 ethers/wallet/error.nim diff --git a/ethers/wallet.nim b/ethers/wallet.nim index 3687b35..900f63f 100644 --- a/ethers/wallet.nim +++ b/ethers/wallet.nim @@ -5,8 +5,10 @@ import eth/common/transaction as ct import ./provider import ./transaction as tx import ./signer +import ./wallet/error export keys +export WalletError var rng {.threadvar.}: ref HmacDrbgContext @@ -17,7 +19,6 @@ proc getRng: ref HmacDrbgContext = type SignableTransaction = common.Transaction -type WalletError* = object of EthersError type Wallet* = ref object of Signer privateKey*: PrivateKey publicKey*: PublicKey @@ -51,7 +52,7 @@ proc createRandom*(_: type Wallet, provider: Provider): Wallet = method provider*(wallet: Wallet): Provider = without provider =? wallet.provider: - raise newException(WalletError, "Wallet has no provider") + raiseWalletError "Wallet has no provider" provider method getAddress(wallet: Wallet): Future[Address] {.async.} = @@ -77,14 +78,14 @@ proc signTransaction(tr: var SignableTransaction, pk: PrivateKey) = of TxEip1559: tr.V = int64(v) else: - raise newException(WalletError, "Transaction type not supported") + raiseWalletError "Transaction type not supported" proc signTransaction*(wallet: Wallet, tx: tx.Transaction): Future[seq[byte]] {.async.} = if sender =? tx.sender and sender != wallet.address: - raise newException(WalletError, "from address mismatch") + raiseWalletError "from address mismatch" without nonce =? tx.nonce and chainId =? tx.chainId and gasLimit =? tx.gasLimit: - raise newException(WalletError, "Transaction is properly populated") + raiseWalletError "Transaction is not properly populated" var s: SignableTransaction @@ -96,7 +97,7 @@ proc signTransaction*(wallet: Wallet, tx: tx.Transaction): Future[seq[byte]] {.a s.txType = TxLegacy s.gasPrice = GasInt(gasPrice.truncate(uint64)) else: - raise newException(WalletError, "Transaction is properly populated") + raiseWalletError "Transaction is not properly populated" s.chainId = ChainId(chainId.truncate(uint64)) s.gasLimit = GasInt(gasLimit.truncate(uint64)) diff --git a/ethers/wallet/error.nim b/ethers/wallet/error.nim new file mode 100644 index 0000000..dc4ab4e --- /dev/null +++ b/ethers/wallet/error.nim @@ -0,0 +1,7 @@ +import ../basics + +type + WalletError* = object of EthersError + +func raiseWalletError*(message: string) = + raise newException(WalletError, message)