beeline-cli
Version:
A terminal wallet for the Hive blockchain - type, sign, rule the chain
151 lines • 7.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const neon_js_1 = require("../utils/neon.js");
const crypto_js_1 = require("../utils/crypto.js");
const hive_js_1 = require("../utils/hive.js");
class PowerDownStatus extends core_1.Command {
async run() {
const { args, flags } = await this.parse(PowerDownStatus);
const keyManager = new crypto_js_1.KeyManager();
await keyManager.initialize();
let account = args.account;
// Clean @ prefix if provided
if (account?.startsWith('@')) {
account = account.substring(1);
}
// Use default account if no account specified
if (!account) {
account = keyManager.getDefaultAccount();
if (!account) {
console.log(neon_js_1.neonChalk.warning(`${neon_js_1.neonSymbols.cross} No account specified and no default account set`));
console.log(neon_js_1.neonChalk.info('Specify an account or import a key first'));
return;
}
}
console.log(neon_js_1.neonChalk.glow(`${neon_js_1.neonSymbols.diamond} Checking powerdown status...`));
console.log('');
const spinner = (0, neon_js_1.neonSpinner)('Fetching powerdown information');
try {
const hiveClient = new hive_js_1.HiveClient(keyManager, flags.node);
const accountData = await hiveClient.getAccount(account);
clearInterval(spinner);
process.stdout.write('\r' + ' '.repeat(80) + '\r');
if (!accountData) {
console.log(neon_js_1.neonChalk.error(`${neon_js_1.neonSymbols.cross} Account @${account} not found`));
return;
}
// Parse powerdown data
const withdrawRate = parseFloat(accountData.vesting_withdraw_rate?.split(' ')[0] || '0');
const nextWithdrawal = new Date(accountData.next_vesting_withdrawal);
const withdrawn = accountData.withdrawn;
const toWithdraw = accountData.to_withdraw;
// Calculate powerdown status
const isPoweringDown = withdrawRate > 0;
const remainingWithdrawals = isPoweringDown ? Math.ceil((toWithdraw - withdrawn) / 13) : 0;
const weeksPassed = withdrawn;
const totalWeeks = toWithdraw / 13; // Each withdrawal is 1/13th
if (flags.format === 'json') {
console.log(JSON.stringify({
account,
is_powering_down: isPoweringDown,
vesting_withdraw_rate: accountData.vesting_withdraw_rate,
next_vesting_withdrawal: accountData.next_vesting_withdrawal,
withdrawn,
to_withdraw: toWithdraw,
weeks_passed: weeksPassed,
total_weeks: Math.round(totalWeeks),
remaining_withdrawals: remainingWithdrawals,
timestamp: new Date().toISOString()
}, null, 2));
return;
}
if (!isPoweringDown) {
console.log(neon_js_1.neonChalk.info(`${neon_js_1.neonSymbols.info} No active powerdown for @${account}`));
console.log('');
const noPowerdownMessage = [
`${neon_js_1.neonChalk.darkCyan('Account: @' + account)}`,
``,
`${neon_js_1.neonChalk.green('Status: No active powerdown')}`,
`${neon_js_1.neonChalk.info('All Hive Power is available and not powering down')}`,
``,
`${neon_js_1.neonChalk.info('💡 Use:')} ${neon_js_1.neonChalk.highlight('beeline powerdown <amount> HP')} ${neon_js_1.neonChalk.info('to start powerdown')}`
].join('\n');
console.log((0, neon_js_1.createNeonBox)(noPowerdownMessage, `${neon_js_1.neonSymbols.star} POWERDOWN STATUS ${neon_js_1.neonSymbols.star}`));
return;
}
// Display active powerdown information
const isOverdue = nextWithdrawal < new Date();
const timeUntilNext = isPoweringDown ? this.formatTimeUntil(nextWithdrawal) : 'N/A';
const powerdownDetails = [
`${neon_js_1.neonChalk.cyan('Account: @' + account)}`,
``,
`${neon_js_1.neonChalk.orange('Status:')} ${neon_js_1.neonChalk.warning('POWERING DOWN')} ${neon_js_1.neonSymbols.warning}`,
`${neon_js_1.neonChalk.electric('Withdraw Rate:')} ${neon_js_1.neonChalk.white(withdrawRate.toFixed(6))} ${neon_js_1.neonChalk.yellow('VESTS/week')}`,
``,
`${neon_js_1.neonChalk.magenta('Progress:')} ${neon_js_1.neonChalk.white(weeksPassed)}/${neon_js_1.neonChalk.white(Math.round(totalWeeks))} weeks completed`,
`${neon_js_1.neonChalk.pink('Remaining:')} ${neon_js_1.neonChalk.white(remainingWithdrawals)} withdrawals`,
``,
`${neon_js_1.neonChalk.cyan('Next Withdrawal:')} ${neon_js_1.neonChalk.white(nextWithdrawal.toLocaleString())}`,
`${neon_js_1.neonChalk.info('Time Until Next:')} ${isOverdue ? neon_js_1.neonChalk.warning('OVERDUE') : neon_js_1.neonChalk.white(timeUntilNext)}`,
``,
isPoweringDown ? `${neon_js_1.neonChalk.warning('⚠️ Powerdown in progress - cannot be stopped, only increased')}` : ''
].filter(Boolean).join('\n');
console.log((0, neon_js_1.createNeonBox)(powerdownDetails, `${neon_js_1.neonSymbols.star} POWERDOWN STATUS ${neon_js_1.neonSymbols.star}`));
console.log('');
// Status indicators
console.log(neon_js_1.neonChalk.info(`${neon_js_1.neonSymbols.bullet} Check again with: ${neon_js_1.neonChalk.highlight(`beeline powerdown-status ${account}`)}`));
console.log(neon_js_1.neonChalk.info(`${neon_js_1.neonSymbols.bullet} Increase powerdown: ${neon_js_1.neonChalk.highlight(`beeline powerdown <amount> HP`)}`));
}
catch (error) {
clearInterval(spinner);
process.stdout.write('\r' + ' '.repeat(80) + '\r');
console.log(neon_js_1.neonChalk.error(`${neon_js_1.neonSymbols.cross} Failed to fetch powerdown status: ${error instanceof Error ? error.message : 'Unknown error'}`));
}
}
formatTimeUntil(targetDate) {
const now = new Date();
const diffMs = targetDate.getTime() - now.getTime();
if (diffMs <= 0) {
return 'Now';
}
const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));
const hours = Math.floor((diffMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((diffMs % (1000 * 60 * 60)) / (1000 * 60));
if (days > 0) {
return `${days}d ${hours}h`;
}
else if (hours > 0) {
return `${hours}h ${minutes}m`;
}
else {
return `${minutes}m`;
}
}
}
PowerDownStatus.description = 'Check current powerdown status and withdrawal schedule';
PowerDownStatus.examples = [
`$ beeline powerdown-status`,
`$ beeline powerdown-status alice`,
`$ beeline powerdown-status alice --format json`
];
PowerDownStatus.flags = {
node: core_1.Flags.string({
char: 'n',
description: 'RPC node to use'
}),
format: core_1.Flags.string({
char: 'f',
description: 'output format',
options: ['table', 'json'],
default: 'table'
})
};
PowerDownStatus.args = {
account: core_1.Args.string({
description: 'account to check powerdown status for',
required: false
})
};
exports.default = PowerDownStatus;
//# sourceMappingURL=powerdown-status.js.map