Skip to content

Commit

Permalink
rename getStatus to getValidatorStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
pLabarta committed Aug 3, 2023
1 parent b6f1482 commit 738938e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions scripts/cc-cli/src/commands/chill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
initKeyringPair,
} from "../utils/account";
import { chill } from "../utils/validate";
import { getStatus, requireStatus } from "../utils/validatorStatus";
import { getValidatorStatus, requireStatus } from "../utils/validatorStatus";

export function makeChillCommand() {
const cmd = new Command("chill");
Expand All @@ -23,13 +23,13 @@ async function chillAction(options: OptionValues) {
const controllerKeyring = initKeyringPair(controllerSeed);
const controllerAddress = controllerKeyring.address;

const controllerStatus = await getStatus(controllerAddress, api);
const controllerStatus = await getValidatorStatus(controllerAddress, api);

if (!controllerStatus.stash) {
console.error(`Cannot chill, ${controllerAddress} is not staked`);
process.exit(1);
}
const stashStatus = await getStatus(controllerStatus.stash, api);
const stashStatus = await getValidatorStatus(controllerStatus.stash, api);

requireStatus(stashStatus, "validating");

Expand Down
7 changes: 5 additions & 2 deletions scripts/cc-cli/src/commands/status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Command, OptionValues } from "commander";
import { newApi } from "../api";
import { getStatus, printValidatorStatus } from "../utils/validatorStatus";
import {
getValidatorStatus,
printValidatorStatus,
} from "../utils/validatorStatus";
import { parseAddressOrExit, parseBoolean } from "../utils/parsing";
import { getChainStatus, printChainStatus } from "../utils/chainStatus";

Expand Down Expand Up @@ -33,7 +36,7 @@ async function statusAction(options: OptionValues) {

if (showValidatorStatus) {
const validator = parseAddressOrExit(options.validator);
const validatorStatus = await getStatus(validator, api);
const validatorStatus = await getValidatorStatus(validator, api);
console.log(`Validator ${validator}:`);
await printValidatorStatus(validatorStatus, api);
}
Expand Down
7 changes: 3 additions & 4 deletions scripts/cc-cli/src/commands/unbond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import {
initKeyringPair,
} from "../utils/account";
import { getBalance } from "../utils/balance";

import { ApiPromise, BN } from "creditcoin-js";
import { promptContinue } from "../utils/promptContinue";
import { parseAmountOrExit, requiredInput } from "../utils/parsing";
import { getStatus, requireStatus } from "../utils/validatorStatus";
import { getValidatorStatus, requireStatus } from "../utils/validatorStatus";
import { requireEnoughFundsToSend, signSendAndWatch } from "../utils/tx";

export function makeUnbondCommand() {
Expand All @@ -32,14 +31,14 @@ async function unbondAction(options: OptionValues) {
const controllerKeyring = initKeyringPair(controllerSeed);
const controllerAddress = controllerKeyring.address;

const controllerStatus = await getStatus(controllerAddress, api);
const controllerStatus = await getValidatorStatus(controllerAddress, api);
if (!controllerStatus.stash) {
console.error(
`Cannot unbond, ${controllerAddress} is not a controller account`
);
process.exit(1);
}
const stashStatus = await getStatus(controllerStatus.stash, api);
const stashStatus = await getValidatorStatus(controllerStatus.stash, api);
requireStatus(stashStatus, "bonded");

// Check if amount specified exceeds total bonded funds
Expand Down
6 changes: 3 additions & 3 deletions scripts/cc-cli/src/commands/withdrawUnbonded.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command, OptionValues } from "commander";
import { newApi } from "../api";
import { getStatus, requireStatus } from "../utils/validatorStatus";
import { getValidatorStatus, requireStatus } from "../utils/validatorStatus";
import {
getControllerSeedFromEnvOrPrompt,
initKeyringPair,
Expand All @@ -20,7 +20,7 @@ async function withdrawUnbondedAction(options: OptionValues) {
const controllerSeed = await getControllerSeedFromEnvOrPrompt();
const controller = initKeyringPair(controllerSeed);

const controllerStatus = await getStatus(controller.address, api);
const controllerStatus = await getValidatorStatus(controller.address, api);

if (!controllerStatus.stash) {
console.error(
Expand All @@ -29,7 +29,7 @@ async function withdrawUnbondedAction(options: OptionValues) {
process.exit(1);
}

const status = await getStatus(controllerStatus.stash, api);
const status = await getValidatorStatus(controllerStatus.stash, api);
requireStatus(
status,
"canWithdraw",
Expand Down
2 changes: 1 addition & 1 deletion scripts/cc-cli/src/utils/validatorStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function formatDaysHoursMinutes(ms: number) {
return `${daysString}${hoursString}${minutesString}${secString}`;
}

export async function getStatus(address: string, api: ApiPromise) {
export async function getValidatorStatus(address: string, api: ApiPromise) {
const res = await api.derive.staking.account(address);
const totalStaked = readAmount(res.stakingLedger.total.toString());
const bonded = totalStaked.gt(new BN(0));
Expand Down

0 comments on commit 738938e

Please sign in to comment.