@ethersphere/swarm-cli
Version:
CLI tool for Bee
95 lines (94 loc) • 5.33 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Status = void 0;
const bee_js_1 = require("@ethersphere/bee-js");
const chalk_1 = __importDefault(require("chalk"));
const process_1 = require("process");
const text_1 = require("../utils/text");
const root_command_1 = require("./root-command");
class Status extends root_command_1.RootCommand {
constructor() {
super(...arguments);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'status'
});
Object.defineProperty(this, "description", {
enumerable: true,
configurable: true,
writable: true,
value: 'Check Bee status'
});
}
async run() {
super.init();
this.console.all(chalk_1.default.bold('Bee'));
process.stdout.write((0, text_1.createKeyValue)('API', this.beeApiUrl));
try {
await this.bee.checkConnection();
process.stdout.write(chalk_1.default.bold.green(' [OK]') + '\n');
}
catch {
process.stdout.write(chalk_1.default.bold.red(' [FAILED]') + '\n');
process.stdout.write('\nIs your Bee node running?\n');
(0, process_1.exit)(1);
}
const versions = await this.bee.getVersions();
this.console.all((0, text_1.createKeyValue)('Version', versions.beeVersion));
const nodeInfo = await this.bee.getNodeInfo();
this.console.all((0, text_1.createKeyValue)('Mode', nodeInfo.beeMode));
if (nodeInfo.beeMode !== bee_js_1.BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== bee_js_1.BeeModes.DEV) {
this.console.all('');
this.console.all(chalk_1.default.bold('Chainsync'));
const { block, chainTip } = await this.bee.getChainState();
this.console.all((0, text_1.createKeyValue)('Block', `${block.toLocaleString()} / ${chainTip.toLocaleString()} (Δ ${(chainTip - block).toLocaleString()})`));
}
if (nodeInfo.beeMode !== bee_js_1.BeeModes.DEV) {
this.console.all('');
this.console.all(chalk_1.default.bold('Topology'));
const topology = await this.bee.getTopology();
this.console.all((0, text_1.createKeyValue)('Connected Peers', topology.connected));
this.console.all((0, text_1.createKeyValue)('Population', topology.population));
this.console.all((0, text_1.createKeyValue)('Depth', topology.depth));
}
if (nodeInfo.beeMode !== bee_js_1.BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== bee_js_1.BeeModes.DEV) {
this.console.all('');
this.console.all(chalk_1.default.bold('Wallet'));
const { bzzBalance, nativeTokenBalance } = await this.bee.getWalletBalance();
this.console.all((0, text_1.createKeyValue)('xBZZ', bzzBalance.toDecimalString()));
this.console.all((0, text_1.createKeyValue)('xDAI', nativeTokenBalance.toDecimalString()));
}
if (nodeInfo.beeMode !== bee_js_1.BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== bee_js_1.BeeModes.DEV) {
this.console.all('');
this.console.all(chalk_1.default.bold('Chequebook'));
const { totalBalance, availableBalance } = await this.bee.getChequebookBalance();
this.console.all((0, text_1.createKeyValue)('Available xBZZ', availableBalance.toDecimalString()));
this.console.all((0, text_1.createKeyValue)('Total xBZZ', totalBalance.toDecimalString()));
}
if (nodeInfo.beeMode !== bee_js_1.BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== bee_js_1.BeeModes.DEV) {
this.console.all('');
this.console.all(chalk_1.default.bold('Staking'));
const stake = await this.bee.getStake();
this.console.all((0, text_1.createKeyValue)('Staked xBZZ', stake.toDecimalString()));
}
if (nodeInfo.beeMode === bee_js_1.BeeModes.FULL) {
this.console.all('');
this.console.all(chalk_1.default.bold('Redistribution'));
const redistributionState = await this.bee.getRedistributionState();
this.console.all((0, text_1.createKeyValue)('Reward', redistributionState.reward.toDecimalString()));
this.console.all((0, text_1.createKeyValue)('Has sufficient funds', redistributionState.hasSufficientFunds));
this.console.all((0, text_1.createKeyValue)('Fully synced', redistributionState.isFullySynced));
this.console.all((0, text_1.createKeyValue)('Frozen', redistributionState.isFrozen));
this.console.all((0, text_1.createKeyValue)('Last selected round', redistributionState.lastSelectedRound));
this.console.all((0, text_1.createKeyValue)('Last played round', redistributionState.lastPlayedRound));
this.console.all((0, text_1.createKeyValue)('Last won round', redistributionState.lastWonRound));
this.console.all((0, text_1.createKeyValue)('Minimum gas funds', redistributionState.minimumGasFunds.toDecimalString()));
}
}
}
exports.Status = Status;