UNPKG

@ethersphere/swarm-cli

Version:
93 lines (92 loc) 3.94 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Stake = void 0; const furious_commander_1 = require("furious-commander"); const spinner_1 = require("../utils/spinner"); const text_1 = require("../utils/text"); const root_command_1 = require("./root-command"); const command_log_1 = require("./root-command/command-log"); const MIN_INITIAL_STAKE_PLUR = BigInt('100000000000000000'); const MIN_INITIAL_STAKE_BZZ = 10; class Stake extends root_command_1.RootCommand { constructor() { super(...arguments); Object.defineProperty(this, "name", { enumerable: true, configurable: true, writable: true, value: 'stake' }); Object.defineProperty(this, "description", { enumerable: true, configurable: true, writable: true, value: `Manages nodes stake` }); Object.defineProperty(this, "amount", { enumerable: true, configurable: true, writable: true, value: void 0 }); } async deposit(amount) { const currentStake = (await this.bee.getStake()).toPLURBigInt(); if (!currentStake && amount < MIN_INITIAL_STAKE_PLUR) { if (this.quiet) { throw new Error(`Insufficient deposit! Initial deposit has to be at least ${MIN_INITIAL_STAKE_BZZ} xBZZ!`); } if (!(await this.console.confirm(`Insufficient deposit! Initial deposit has to be at least ${MIN_INITIAL_STAKE_BZZ} xBZZ. Do you want to increase the deposit to ${MIN_INITIAL_STAKE_BZZ} xBZZ?`))) { throw new Error(`Insufficient deposit! Initial deposit has to be at least ${MIN_INITIAL_STAKE_BZZ} xBZZ!`); } amount = MIN_INITIAL_STAKE_PLUR; } if (!this.quiet && !this.yes) { this.yes = await this.console.confirm('Depositing stake is irreversible! It can not be withdrawn later on. Do you want to continue?'); } if (!this.yes && !this.quiet) { return; } const spinner = (0, spinner_1.createSpinner)('Depositing stake'); if (this.verbosity !== command_log_1.VerbosityLevel.Quiet && !this.curl) { spinner.start(); } try { await this.bee.depositStake(amount.toString()); spinner.stop(); this.console.log('PLUR successfully staked!'); } catch (e) { spinner.stop(); throw e; } } async run() { super.init(); if (this.amount) { await this.deposit(this.amount); } const stake = await this.bee.getStake(); this.console.log((0, text_1.createKeyValue)('Staked xBZZ', stake.toDecimalString())); this.console.quiet(stake.toDecimalString()); } } __decorate([ (0, furious_commander_1.Option)({ key: 'deposit', description: "Amount of PLUR to add to the node's stake", type: 'bigint', minimum: BigInt(1), }), __metadata("design:type", Object) ], Stake.prototype, "amount", void 0); exports.Stake = Stake;