Skip to content

Commit

Permalink
feat(cli): Add network name to status. uses id as fallback (#3810)
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-if authored Apr 20, 2023
1 parent c252c84 commit 87fecee
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
12 changes: 11 additions & 1 deletion ironfish-cli/src/commands/status.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { FileUtils, GetNodeStatusResponse, PromiseUtils, TimeUtils } from '@ironfish/sdk'
import {
defaultNetworkName,
FileUtils,
GetNodeStatusResponse,
PromiseUtils,
TimeUtils,
} from '@ironfish/sdk'
import { Assert } from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import blessed from 'blessed'
Expand Down Expand Up @@ -111,6 +117,9 @@ function renderStatus(content: GetNodeStatusResponse, debugOutput: boolean): str

const blockGraffiti = `${content.miningDirector.blockGraffiti}`

const network =
defaultNetworkName(content.node.networkId) || content.node.networkId.toString()

const peerNetworkStatus = `${
content.peerNetwork.isReady ? 'CONNECTED' : 'WAITING'
} - In: ${FileUtils.formatFileSize(
Expand Down Expand Up @@ -195,6 +204,7 @@ Version ${content.node.version} @ ${content.node.git}
Node ${nodeStatus}
Node Name ${nodeName}
Block Graffiti ${blockGraffiti}
Network ${network}
Memory ${memoryStatus}
CPU ${cpuStatus}
P2P Network ${peerNetworkStatus}
Expand Down
11 changes: 11 additions & 0 deletions ironfish/src/defaultNetworkDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ export function isDefaultNetworkId(networkId: number): boolean {
return networkId <= 100
}

export function defaultNetworkName(networkId: number): string | undefined {
switch (networkId) {
case 0:
return 'Testnet'
case 1:
return 'Mainnet'
case 2:
return 'Dev'
}
}

/**
* This account (IronFishGenesisAccount) can be imported to access the funds in the genesis block.
*
Expand Down
6 changes: 5 additions & 1 deletion ironfish/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ export * from './wallet'
export * from './assert'
export * from './blockchain'
export * from './consensus'
export { DEV_GENESIS_ACCOUNT } from './defaultNetworkDefinitions'
export {
DEV_GENESIS_ACCOUNT,
defaultNetworkName,
isDefaultNetworkId,
} from './defaultNetworkDefinitions'
export * from './chainProcessor'
export * from './event'
export * from './fileStores'
Expand Down
3 changes: 3 additions & 0 deletions ironfish/src/rpc/routes/node/getStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type GetNodeStatusResponse = {
version: string
git: string
nodeName: string
networkId: number
}
cpu: {
cores: number
Expand Down Expand Up @@ -116,6 +117,7 @@ export const GetStatusResponseSchema: yup.ObjectSchema<GetNodeStatusResponse> =
version: yup.string().defined(),
git: yup.string().defined(),
nodeName: yup.string().defined(),
networkId: yup.number().defined(),
})
.defined(),
cpu: yup
Expand Down Expand Up @@ -289,6 +291,7 @@ function getStatus(node: IronfishNode): GetNodeStatusResponse {
version: node.pkg.version,
git: node.pkg.git,
nodeName: node.config.get('nodeName'),
networkId: node.internal.get('networkId'),
},
cpu: {
cores: node.metrics.cpuCores,
Expand Down

0 comments on commit 87fecee

Please sign in to comment.