Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Check the wallet is unlocked before prompting for name #5395

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ironfish-cli/src/commands/wallet/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ export class CreateCommand extends IronfishCommand {

async start(): Promise<void> {
const { args } = await this.parse(CreateCommand)
let name = args.name
const client = await this.connectRpc()
await checkWalletUnlocked(client)

let name = args.name
if (!name) {
name = await inputPrompt('Enter the name of the account', true)
}

const client = await this.connectRpc()
await checkWalletUnlocked(client)

this.log(`Creating account ${name}`)
const result = await client.wallet.createAccount({ name })

Expand All @@ -44,5 +43,7 @@ export class CreateCommand extends IronfishCommand {
} else {
this.log(`Run "ironfish wallet:use ${name}" to set the account as default`)
}

this.exit(0)
}
}
2 changes: 1 addition & 1 deletion ironfish/src/rpc/routes/wallet/decrypt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Route wallet/encrypt', () => {

await expect(
routeTest.client.wallet.decrypt({ passphrase: invalidPassphrase }),
).rejects.toThrow('Request failed (400) error: Failed to decrypt account')
).rejects.toThrow('Request failed (400) error: Failed to decrypt wallet')

status = await routeTest.client.wallet.getAccountsStatus()
expect(status.content.encrypted).toBe(true)
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/routes/wallet/unlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Route wallet/unlock', () => {

await expect(
routeTest.client.wallet.unlock({ passphrase: invalidPassphrase }),
).rejects.toThrow('Request failed (400) error: Failed to decrypt account')
).rejects.toThrow('Request failed (400) error: Failed to decrypt wallet')

status = await routeTest.client.wallet.getAccountsStatus()
expect(status.content.encrypted).toBe(true)
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/wallet/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ export class AccountDecryptionFailedError extends Error {

constructor() {
super()
this.message = 'Failed to decrypt account'
this.message = 'Failed to decrypt wallet'
}
}