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): Add network name to status. uses id as fallback #3810

Merged
merged 1 commit into from
Apr 20, 2023
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
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