UNPKG

@ethersphere/swarm-cli

Version:
126 lines (125 loc) 7.61 kB
"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, currentPrice } = await this.bee.getChainState(); this.console.all((0, text_1.createKeyValue)('Block', `${block.toLocaleString()} / ${chainTip.toLocaleString()} (Δ ${(chainTip - block).toLocaleString()})`)); this.console.all((0, text_1.createKeyValue)('Storage Price', currentPrice.toLocaleString() + ' PLUR / chunk / block')); } 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')); try { 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())); } catch { this.console.all(chalk_1.default.yellow('Wallet balance not available')); this.console.all('This is normal if chequebook is disabled in the node configuration.'); } } 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')); try { 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())); } catch { this.console.all(chalk_1.default.yellow('Chequebook balance not available')); this.console.all('This is normal if chequebook is disabled in the node configuration.'); } } if (nodeInfo.beeMode === bee_js_1.BeeModes.FULL) { this.console.all(''); this.console.all(chalk_1.default.bold('Staking')); const stake = await this.bee.getStake(); const surplusStake = await this.bee.getWithdrawableStake(); this.console.all((0, text_1.createKeyValue)('Staked xBZZ', stake.toDecimalString())); this.console.all((0, text_1.createKeyValue)('Withdrawable staked xBZZ', surplusStake.toDecimalString())); const reserveStatus = await this.bee.getStatus(); this.console.all(''); this.console.all(chalk_1.default.bold('Reserve')); this.console.all((0, text_1.createKeyValue)('Pullsync rate', reserveStatus.pullsyncRate.toFixed(2) + ' chunks/s (' + ((reserveStatus.pullsyncRate * 4096) / 1024 / 1024).toFixed(2) + ' MB/s)')); this.console.all((0, text_1.createKeyValue)('Reserve size', reserveStatus.reserveSize.toLocaleString() + ' chunks (' + ((reserveStatus.reserveSize * 4096) / 1024 / 1024 / 1024).toFixed(2) + ' GB)')); this.console.all((0, text_1.createKeyValue)('Reserve size within radius', reserveStatus.reserveSizeWithinRadius.toLocaleString() + ' chunks (' + ((reserveStatus.reserveSizeWithinRadius * 4096) / 1024 / 1024 / 1024).toFixed(2) + ' GB)')); this.console.all(''); this.console.all(chalk_1.default.bold('Redistribution')); const redistributionState = await this.bee.getRedistributionState(); const currentRound = redistributionState.round; this.console.all((0, text_1.createKeyValue)('Reward', redistributionState.reward.toDecimalString() + ' xBZZ')); 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)('Current round', redistributionState.round)); this.console.all((0, text_1.createKeyValue)('Last selected round', redistributionState.lastSelectedRound + ' (Δ ' + (currentRound - redistributionState.lastSelectedRound) + ')')); this.console.all((0, text_1.createKeyValue)('Last played round', redistributionState.lastPlayedRound + ' (Δ ' + (currentRound - redistributionState.lastPlayedRound) + ')')); this.console.all((0, text_1.createKeyValue)('Last won round', redistributionState.lastWonRound + ' (Δ ' + (currentRound - redistributionState.lastWonRound) + ')')); this.console.all((0, text_1.createKeyValue)('Last sampling duration', redistributionState.lastSampleDurationSeconds + ' seconds')); this.console.all((0, text_1.createKeyValue)('Minimum gas funds', redistributionState.minimumGasFunds.toDecimalString() + ' xDAI')); } } } exports.Status = Status;