Skip to content

Commit

Permalink
feat: add node info to status command (#310)
Browse files Browse the repository at this point in the history
* feat: add node info to status command

* test: fix mock
  • Loading branch information
Cafe137 authored Dec 21, 2021
1 parent 981c4d7 commit 5879880
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/command/status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from '@ethersphere/bee-js'
import { NodesInfo, SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from '@ethersphere/bee-js'
import chalk from 'chalk'
import { LeafCommand } from 'furious-commander'
import { createKeyValue } from '../utils/text'
Expand All @@ -21,11 +21,18 @@ export class Status extends RootCommand implements LeafCommand {
const version = await this.checkBeeDebugApiConnection()
await this.checkBeeVersionCompatibility()
const topology = await this.checkTopology()
const nodeInfo = await this.getNodeInfo()

this.console.log(createKeyValue('Bee Version', version, 'Supported Version'.length))
this.console.log(
createKeyValue('Supported Version', SUPPORTED_BEE_VERSION + ' (' + SUPPORTED_BEE_VERSION_EXACT + ')'),
)

if (nodeInfo) {
this.console.divider()
this.console.log(createKeyValue('Gateway Mode', nodeInfo.gatewayMode))
this.console.log(createKeyValue('Bee Mode', nodeInfo.beeMode))
}
this.console.quiet('Bee version - ' + version)
this.console.quiet('Supported version - ' + SUPPORTED_BEE_VERSION_EXACT)

Expand Down Expand Up @@ -76,6 +83,16 @@ export class Status extends RootCommand implements LeafCommand {
}
}

private async getNodeInfo(): Promise<NodesInfo | null> {
try {
const nodeInfo = await this._beeDebug.getNodeInfo()

return nodeInfo
} catch {
return null
}
}

private async checkTopology(): Promise<null | {
connected: number
population: number
Expand Down
9 changes: 9 additions & 0 deletions test/http-mock/cheque-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export function createChequeMockHttpServer(port: number): Server {
if (request.url === '/chequebook/cashout/1105536d0f270ecaa9e6e4347e687d1a1afbde7b534354dfd7050d66b3c0faad') {
response.end(JSON.stringify(lastCashoutCheque1))
}

if (request.url === '/node') {
response.end(JSON.stringify(nodeInfo))
}
})
server.listen(port)

Expand Down Expand Up @@ -72,6 +76,11 @@ const lastCashoutCheque1 = {

const balance = { totalBalance: 100026853000000000, availableBalance: 100018560000000000 }

const nodeInfo = {
beeMode: 'light',
gatewayMode: true,
}

if (process.argv[2] === 'run') {
createChequeMockHttpServer(parseInt(process.argv[3], 10))
}

0 comments on commit 5879880

Please sign in to comment.