UNPKG

@ethersphere/swarm-cli

Version:
53 lines (52 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Withdraw = void 0; const bee_js_1 = require("@ethersphere/bee-js"); const spinner_1 = require("../../utils/spinner"); const root_command_1 = require("../root-command"); const command_log_1 = require("../root-command/command-log"); class Withdraw extends root_command_1.RootCommand { constructor() { super(...arguments); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'withdraw' }); Object.defineProperty(this, "description", { enumerable: true, configurable: true, writable: true, value: `Withdraw surplus stake to the node's balance` }); } async run() { super.init(); const surplusStake = await this.bee.getWithdrawableStake(); if (surplusStake.eq(bee_js_1.BZZ.fromDecimalString('0'))) { this.console.log('There is no surplus stake to withdraw.'); return; } if (!this.quiet && !this.yes) { this.yes = await this.console.confirm(`You are about to withdraw a surplus stake of ${surplusStake.toDecimalString()} xBZZ, are you sure you wish to proceed?`); } if (!this.yes && !this.quiet) { return; } const spinner = (0, spinner_1.createSpinner)('Withdrawing surplus stake'); if (this.verbosity !== command_log_1.VerbosityLevel.Quiet && !this.curl) { spinner.start(); } try { await this.bee.withdrawSurplusStake(); spinner.stop(); this.console.log('Successfully withdrawn surplus stake! It may take a few minutes for the withdrawal to be reflected in the node status.'); } catch (e) { spinner.stop(); throw e; } } } exports.Withdraw = Withdraw;