diff --git a/scripts/cc-cli/src/commands/chill.ts b/scripts/cc-cli/src/commands/chill.ts index 0c134cd366..7db847faa9 100644 --- a/scripts/cc-cli/src/commands/chill.ts +++ b/scripts/cc-cli/src/commands/chill.ts @@ -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"); @@ -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"); diff --git a/scripts/cc-cli/src/commands/status.ts b/scripts/cc-cli/src/commands/status.ts index dbad8353f8..437b809eb7 100644 --- a/scripts/cc-cli/src/commands/status.ts +++ b/scripts/cc-cli/src/commands/status.ts @@ -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"; @@ -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); } diff --git a/scripts/cc-cli/src/commands/unbond.ts b/scripts/cc-cli/src/commands/unbond.ts index f684519d64..dbf75c043f 100644 --- a/scripts/cc-cli/src/commands/unbond.ts +++ b/scripts/cc-cli/src/commands/unbond.ts @@ -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() { @@ -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 diff --git a/scripts/cc-cli/src/commands/withdrawUnbonded.ts b/scripts/cc-cli/src/commands/withdrawUnbonded.ts index 2820dac0ca..2860b1fc66 100644 --- a/scripts/cc-cli/src/commands/withdrawUnbonded.ts +++ b/scripts/cc-cli/src/commands/withdrawUnbonded.ts @@ -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, @@ -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( @@ -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", diff --git a/scripts/cc-cli/src/utils/validatorStatus.ts b/scripts/cc-cli/src/utils/validatorStatus.ts index 995dd6090b..7bffe1109f 100644 --- a/scripts/cc-cli/src/utils/validatorStatus.ts +++ b/scripts/cc-cli/src/utils/validatorStatus.ts @@ -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));