Skip to content

Commit 67b47b2

Browse files
authored
Change wallet:status to output aggregation (#5275)
1 parent bed90c6 commit 67b47b2

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed
Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,66 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4-
import chalk from 'chalk'
4+
import { MathUtils, TimeUtils } from '@ironfish/sdk'
55
import { IronfishCommand } from '../../command'
6-
import { RemoteFlags } from '../../flags'
7-
import { table, TableFlags } from '../../ui'
6+
import { JsonFlags, RemoteFlags } from '../../flags'
7+
import * as ui from '../../ui'
88

99
export class StatusCommand extends IronfishCommand {
1010
static description = `Get status of all accounts`
11+
static enableJsonFlag = true
1112

1213
static flags = {
1314
...RemoteFlags,
14-
...TableFlags,
15+
...JsonFlags,
1516
}
1617

17-
async start(): Promise<void> {
18-
const { flags } = await this.parse(StatusCommand)
18+
async start(): Promise<unknown> {
19+
await this.parse(StatusCommand)
1920

2021
const client = await this.connectRpc()
2122

22-
const response = await client.wallet.getAccountsStatus()
23-
24-
table(
25-
response.content.accounts,
26-
{
27-
name: {
28-
get: (row) => row.name,
29-
header: 'Account Name',
30-
minWidth: 11,
31-
},
32-
id: {
33-
get: (row) => row.id,
34-
header: 'Account ID',
35-
},
36-
viewOnly: {
37-
get: (row) => row.viewOnly,
38-
header: 'View Only',
39-
},
40-
headHash: {
41-
get: (row) => row.head?.hash ?? 'NULL',
42-
header: 'Head Hash',
43-
},
44-
headInChain: {
45-
get: (row) => row.head?.inChain ?? 'NULL',
46-
header: 'Head In Chain',
47-
},
48-
sequence: {
49-
get: (row) => row.head?.sequence ?? 'NULL',
50-
header: 'Head Sequence',
51-
},
52-
scanningEnabled: {
53-
get: (row) => (row.scanningEnabled ? chalk.green('✓') : ''),
54-
header: 'Scanning Enabled',
55-
},
56-
},
57-
{
58-
printLine: this.log.bind(this),
59-
...flags,
60-
},
61-
)
23+
const [nodeStatus, walletStatus] = await Promise.all([
24+
client.node.getStatus(),
25+
client.wallet.getAccounts(),
26+
])
27+
28+
const status: Record<string, unknown> = {
29+
Wallet: nodeStatus.content.accounts.enabled ? 'ENABLED' : 'DISABLED',
30+
Accounts: walletStatus.content.accounts.length,
31+
Head: nodeStatus.content.accounts.head.hash,
32+
Sequence: nodeStatus.content.accounts.head.sequence,
33+
Scanner: 'IDLE',
34+
}
35+
36+
if (nodeStatus.content.accounts.scanning) {
37+
const progress = MathUtils.round(
38+
(nodeStatus.content.accounts.scanning.sequence /
39+
nodeStatus.content.accounts.scanning.endSequence) *
40+
100,
41+
2,
42+
)
43+
44+
const duration = Date.now() - nodeStatus.content.accounts.scanning.startedAt
45+
const speed = MathUtils.round(nodeStatus.content.accounts.scanning.speed, 2)
46+
47+
status['Scanner'] = 'SCANNING'
48+
status['Scan Progress'] = progress + '%'
49+
status['Scan Speed'] = `${speed} B/s`
50+
status['Scan Duration'] = TimeUtils.renderSpan(duration, {
51+
hideMilliseconds: true,
52+
forceSecond: true,
53+
})
54+
status[
55+
'Scan Block'
56+
] = `${nodeStatus.content.accounts.scanning.sequence} -> ${nodeStatus.content.accounts.scanning.endSequence}`
57+
}
58+
59+
this.log(ui.card(status))
60+
61+
return {
62+
...nodeStatus.content.accounts,
63+
accountsCount: walletStatus.content.accounts.length,
64+
}
6265
}
6366
}

0 commit comments

Comments
 (0)