Skip to content

Commit

Permalink
add: implement cli-table for validatorStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
pLabarta committed Aug 3, 2023
1 parent 738938e commit 0805e8b
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions scripts/cc-cli/src/utils/validatorStatus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApiPromise, BN } from "creditcoin-js";
import { readAmount, readAmountFromHex, toCTCString } from "./balance";
import { timeTillEra } from "./era";
import Table from "cli-table3";

function formatDaysHoursMinutes(ms: number) {
const days = Math.floor(ms / (24 * 60 * 60 * 1000));
Expand Down Expand Up @@ -94,23 +95,22 @@ export async function getValidatorStatus(address: string, api: ApiPromise) {
}

export async function printValidatorStatus(status: Status, api: ApiPromise) {
console.log("Bonded: ", status.bonded);
if (status.stash) console.log("Stash: ", status.stash);
console.log("Controller: ", status.controller);
console.log("Validating: ", status.validating);
console.log("Waiting: ", status.waiting);
console.log("Active: ", status.active);

console.log("Can withdraw: ", status.canWithdraw);
const table = new Table({
head: ["Status"],
});

table.push(["Bonded", status.bonded ? "Yes" : "No"]);
table.push(["Stash", status.stash ? status.stash : "None"]);
table.push(["Controller", status.controller]);
table.push(["Validating", status.validating ? "Yes" : "No"]);
table.push(["Waiting", status.waiting ? "Yes" : "No"]);
table.push(["Active", status.active ? "Yes" : "No"]);
table.push(["Can withdraw", status.canWithdraw ? "Yes" : "No"]);
if (status.canWithdraw) {
console.log("Unlocked chunks: ");
status.readyForWithdraw.forEach((chunk) => {
console.log(
` ${toCTCString(chunk.value)} unlocked since era ${chunk.era}`
);
table.push([`Unlocked since era ${chunk.era}`, toCTCString(chunk.value)]);
});
}

let nextUnlocking = "None";
if (status.nextUnbondingAmount && status.nextUnbondingAmount.eq(new BN(0))) {
nextUnlocking = "None";
Expand All @@ -121,7 +121,9 @@ export async function printValidatorStatus(status: Status, api: ApiPromise) {
nextUnbondingDate.toNumber()
)}`;
}
console.log(`Next unbonding chunk: ${nextUnlocking}`);
table.push(["Next unlocking", nextUnlocking]);

console.log(table.toString());
}

export function requireStatus(
Expand Down

0 comments on commit 0805e8b

Please sign in to comment.