Skip to content

Commit 29ed1d0

Browse files
authored
adds command to display status for single account (#5595)
'wallet:account' displays the status information available in 'wallet:accounts --extended' for a single account accepted as an arg defaults to the wallet's default account Closes IFL-2651
1 parent 61c7085 commit 29ed1d0

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4+
import { RpcRequestError } from '@ironfish/sdk'
5+
import { Args } from '@oclif/core'
6+
import chalk from 'chalk'
7+
import { IronfishCommand } from '../../command'
8+
import { JsonFlags, RemoteFlags } from '../../flags'
9+
import * as ui from '../../ui'
10+
11+
export class AccountsCommand extends IronfishCommand {
12+
static description = `display status for a wallet account`
13+
static enableJsonFlag = true
14+
15+
static flags = {
16+
...RemoteFlags,
17+
...JsonFlags,
18+
}
19+
20+
static args = {
21+
account: Args.string({
22+
description: 'name of the account to display status for',
23+
}),
24+
}
25+
26+
async start(): Promise<unknown> {
27+
const { args } = await this.parse(AccountsCommand)
28+
29+
const client = await this.connectRpc()
30+
await ui.checkWalletUnlocked(client)
31+
32+
const account =
33+
args.account ?? (await client.wallet.getDefaultAccount()).content.account?.name
34+
35+
if (!account) {
36+
this.log(
37+
'There is currently no account being used.\n' +
38+
' * Create an account: "ironfish wallet:create"\n' +
39+
' * List all accounts: "ironfish wallet:accounts"\n' +
40+
' * Use an existing account: "ironfish wallet:use <name>"',
41+
)
42+
return {}
43+
}
44+
45+
try {
46+
const response = await client.wallet.getAccountStatus({ account })
47+
48+
const status: Record<string, unknown> = {
49+
Account: response.content.account.name,
50+
Default: response.content.account.default ? chalk.green('✓') : '',
51+
'View Only': response.content.account.viewOnly ? chalk.green('✓') : '',
52+
'In Chain': response.content.account.head?.inChain ? chalk.green('✓') : '',
53+
Scanning: response.content.account.scanningEnabled ? chalk.green('✓') : '',
54+
Sequence: response.content.account.head?.sequence,
55+
Head: response.content.account.head?.hash,
56+
}
57+
58+
this.log(ui.card(status))
59+
60+
return status
61+
} catch (e) {
62+
if (e instanceof RpcRequestError && e.codeMessage.includes('No account with name')) {
63+
this.log(e.codeMessage)
64+
return {}
65+
} else {
66+
throw e
67+
}
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)