|
@@ -1,37 +1,37 @@
|
|
import ExitCodes from '../ExitCodes'
|
|
import ExitCodes from '../ExitCodes'
|
|
-import { AccountId } from "@joystream/types/common"
|
|
|
|
|
|
+import { AccountId } from '@joystream/types/common'
|
|
import { StakingLedger } from '@polkadot/types/interfaces'
|
|
import { StakingLedger } from '@polkadot/types/interfaces'
|
|
-import AccountsCommandBase from "./AccountsCommandBase"
|
|
|
|
|
|
+import AccountsCommandBase from './AccountsCommandBase'
|
|
import { formatBalance } from '@polkadot/util'
|
|
import { formatBalance } from '@polkadot/util'
|
|
|
|
|
|
export default abstract class StakingCommandBase extends AccountsCommandBase {
|
|
export default abstract class StakingCommandBase extends AccountsCommandBase {
|
|
-
|
|
|
|
- private async availableControllers(): Promise<[AccountId,StakingLedger][]> {
|
|
|
|
|
|
+ private async availableControllers(): Promise<[AccountId, StakingLedger][]> {
|
|
const controllers = await this.getStakingLedgers()
|
|
const controllers = await this.getStakingLedgers()
|
|
- const stakerMap: [AccountId,StakingLedger][] = []
|
|
|
|
- controllers.forEach(([key,value]) => {
|
|
|
|
|
|
+ const stakerMap: [AccountId, StakingLedger][] = []
|
|
|
|
+ controllers.forEach(([key, value]) => {
|
|
const ledger = value.unwrapOr(undefined)
|
|
const ledger = value.unwrapOr(undefined)
|
|
if (!!ledger && this.isKeyAvailable(key)) {
|
|
if (!!ledger && this.isKeyAvailable(key)) {
|
|
- stakerMap.push([key,ledger])
|
|
|
|
|
|
+ stakerMap.push([key, ledger])
|
|
}
|
|
}
|
|
})
|
|
})
|
|
return stakerMap
|
|
return stakerMap
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
private async getStakingLedgers() {
|
|
private async getStakingLedgers() {
|
|
const controllers = await this.getApi().allStakingLedgers()
|
|
const controllers = await this.getApi().allStakingLedgers()
|
|
return controllers
|
|
return controllers
|
|
}
|
|
}
|
|
|
|
|
|
- async getController():Promise<string> {
|
|
|
|
|
|
+ async getController(): Promise<string> {
|
|
const availableControllers = await this.availableControllers()
|
|
const availableControllers = await this.availableControllers()
|
|
- const selectedValidator = await this.promptForController('No controller input',availableControllers)
|
|
|
|
|
|
+ const selectedValidator = await this.promptForController('No controller input', availableControllers)
|
|
return availableControllers[selectedValidator][0].toString()
|
|
return availableControllers[selectedValidator][0].toString()
|
|
}
|
|
}
|
|
|
|
|
|
- async promptForController(message = 'Choose your controller account', stakingAlternatives: [AccountId,StakingLedger][]): Promise<number> {
|
|
|
|
|
|
+ async promptForController(
|
|
|
|
+ message = 'Choose your controller account',
|
|
|
|
+ stakingAlternatives: [AccountId, StakingLedger][]
|
|
|
|
+ ): Promise<number> {
|
|
if (!stakingAlternatives.length) {
|
|
if (!stakingAlternatives.length) {
|
|
this.warn('No controller accounts to choose from!')
|
|
this.warn('No controller accounts to choose from!')
|
|
this.exit(ExitCodes.NoAccountFound)
|
|
this.exit(ExitCodes.NoAccountFound)
|
|
@@ -40,18 +40,24 @@ export default abstract class StakingCommandBase extends AccountsCommandBase {
|
|
message,
|
|
message,
|
|
type: 'list',
|
|
type: 'list',
|
|
choices: stakingAlternatives.map((a) => ({
|
|
choices: stakingAlternatives.map((a) => ({
|
|
- name: `Controller: ${a[0].toString()}, with Stash ${a[1].stash.toString()} with an active stake: ${formatBalance(a[1].active)}`,
|
|
|
|
|
|
+ name: `Controller: ${a[0].toString()}, with Stash ${a[1].stash.toString()} with an active stake: ${formatBalance(
|
|
|
|
+ a[1].active
|
|
|
|
+ )}`,
|
|
value: stakingAlternatives.indexOf(a),
|
|
value: stakingAlternatives.indexOf(a),
|
|
- })),
|
|
|
|
|
|
+ })),
|
|
})
|
|
})
|
|
return selectedController
|
|
return selectedController
|
|
}
|
|
}
|
|
|
|
|
|
- async isController(controllerInput:string) {
|
|
|
|
|
|
+ async isController(controllerInput: string) {
|
|
if (this.isKeyAvailable(controllerInput)) {
|
|
if (this.isKeyAvailable(controllerInput)) {
|
|
const info = (await this.getApi().isControllerValid(controllerInput)).unwrapOr(undefined)
|
|
const info = (await this.getApi().isControllerValid(controllerInput)).unwrapOr(undefined)
|
|
if (!!info) {
|
|
if (!!info) {
|
|
- this.log(`Your controller ${controllerInput} with stash ${info.stash.toString()} is actively staking ${formatBalance(info.active)}`)
|
|
|
|
|
|
+ this.log(
|
|
|
|
+ `Your controller ${controllerInput} with stash ${info.stash.toString()} is actively staking ${formatBalance(
|
|
|
|
+ info.active
|
|
|
|
+ )}`
|
|
|
|
+ )
|
|
} else {
|
|
} else {
|
|
this.warn('Your account is not a controller!')
|
|
this.warn('Your account is not a controller!')
|
|
this.exit(ExitCodes.InvalidInput)
|
|
this.exit(ExitCodes.InvalidInput)
|
|
@@ -62,30 +68,33 @@ export default abstract class StakingCommandBase extends AccountsCommandBase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- async promptForCommission(message = 'Choose how much you reqiure as commission (between 0% and 100%'): Promise<number> {
|
|
|
|
- return await this.simplePrompt<number>({ message, type: 'number'})
|
|
|
|
|
|
+ async promptForCommission(
|
|
|
|
+ message = 'Choose how much you reqiure as commission (between 0% and 100%'
|
|
|
|
+ ): Promise<number> {
|
|
|
|
+ return await this.simplePrompt<number>({ message, type: 'number' })
|
|
}
|
|
}
|
|
|
|
|
|
async electionStatus() {
|
|
async electionStatus() {
|
|
const electionStatus = await this.getApi().getEraElectionStatus()
|
|
const electionStatus = await this.getApi().getEraElectionStatus()
|
|
if (electionStatus.isOpen === true) {
|
|
if (electionStatus.isOpen === true) {
|
|
- this.warn('There is currently an ongoing election for new validator candidates. As such staking operations are not permitted. You need to wait')
|
|
|
|
|
|
+ this.warn(
|
|
|
|
+ 'There is currently an ongoing election for new validator candidates. As such staking operations are not permitted. You need to wait'
|
|
|
|
+ )
|
|
this.exit(ExitCodes.ActionCurrentlyUnavailable)
|
|
this.exit(ExitCodes.ActionCurrentlyUnavailable)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
async getValidatorPrefs(commission: number | undefined): Promise<any> {
|
|
async getValidatorPrefs(commission: number | undefined): Promise<any> {
|
|
- let validatorPrefs = {'commission': 0}
|
|
|
|
|
|
+ let validatorPrefs = { 'commission': 0 }
|
|
if (!commission) {
|
|
if (!commission) {
|
|
commission = await this.promptForCommission()
|
|
commission = await this.promptForCommission()
|
|
}
|
|
}
|
|
if (commission >= 0 && commission <= 100) {
|
|
if (commission >= 0 && commission <= 100) {
|
|
- validatorPrefs = {'commission': commission*10**7}
|
|
|
|
|
|
+ validatorPrefs = { 'commission': commission * 10 ** 7 }
|
|
} else {
|
|
} else {
|
|
this.warn('Invalid commission input!')
|
|
this.warn('Invalid commission input!')
|
|
this.exit(ExitCodes.InvalidInput)
|
|
this.exit(ExitCodes.InvalidInput)
|
|
}
|
|
}
|
|
return validatorPrefs
|
|
return validatorPrefs
|
|
}
|
|
}
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+}
|