From d1abc670731e875b313d368ee19230de09b49c0a Mon Sep 17 00:00:00 2001 From: Rohan Jadvani <5459049+rohanjadvani@users.noreply.github.com> Date: Mon, 26 Aug 2024 16:45:46 -0400 Subject: [PATCH] feat(cli,ironfish): Check if the wallet is locked before fetching accounts (#5333) --- ironfish-cli/src/utils/account.ts | 5 +++++ ironfish/src/rpc/routes/wallet/utils.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/ironfish-cli/src/utils/account.ts b/ironfish-cli/src/utils/account.ts index 9747ca4f86..a867d86707 100644 --- a/ironfish-cli/src/utils/account.ts +++ b/ironfish-cli/src/utils/account.ts @@ -14,6 +14,11 @@ export async function useAccount( return account } + const status = await client.wallet.getAccountsStatus() + if (status.content.locked) { + throw new Error('Wallet is locked. Unlock the wallet to fetch accounts') + } + const defaultAccount = await client.wallet.getAccounts({ default: true }) if (defaultAccount.content.accounts.length) { diff --git a/ironfish/src/rpc/routes/wallet/utils.ts b/ironfish/src/rpc/routes/wallet/utils.ts index 4e7b343d83..67a7843f71 100644 --- a/ironfish/src/rpc/routes/wallet/utils.ts +++ b/ironfish/src/rpc/routes/wallet/utils.ts @@ -12,6 +12,10 @@ import { serializeRpcWalletNote } from './serializers' import { RpcWalletNote } from './types' export function getAccount(wallet: Wallet, name?: string): Account { + if (wallet.locked) { + throw new RpcValidationError('Wallet is locked. Unlock the wallet to fetch accounts') + } + if (name) { const account = wallet.getAccountByName(name) if (account) {