bwhm преди 3 години
родител
ревизия
b097e5d78c
променени са 4 файла, в които са добавени 15 реда и са изтрити 21 реда
  1. 3 0
      cli/package.json
  2. 1 1
      cli/src/Api.ts
  3. 4 9
      cli/src/base/StakingCommandBase.ts
  4. 7 11
      cli/src/commands/staking/validate.ts

+ 3 - 0
cli/package.json

@@ -125,6 +125,9 @@
       },
       "forum": {
         "description": "Forum working group activities (moderation, category management)"
+      },
+      "staking": {
+        "description": "Staking and validation commands"
       }
     }
   },

+ 1 - 1
cli/src/Api.ts

@@ -415,7 +415,7 @@ export default class Api {
     return await this.entriesByAccountIds(this._api.query.staking.ledger)
   }
 
-  async isControllerValid(account: string) {
+  async isControllerValid(account: string): Promise<Option<StakingLedger>> {
     return await this._api.query.staking.ledger(account)
   }
 

+ 4 - 9
cli/src/base/StakingCommandBase.ts

@@ -7,14 +7,9 @@ import { formatBalance } from '@polkadot/util'
 export default abstract class StakingCommandBase extends AccountsCommandBase {
   private async availableControllers(): Promise<[AccountId, StakingLedger][]> {
     const controllers = await this.getStakingLedgers()
-    const stakerMap: [AccountId, StakingLedger][] = []
-    controllers.forEach(([key, value]) => {
-      const ledger = value.unwrapOr(undefined)
-      if (!!ledger && this.isKeyAvailable(key)) {
-        stakerMap.push([key, ledger])
-      }
-    })
-    return stakerMap
+    return controllers
+      .filter(([key, value]) => value.isSome && this.isKeyAvailable(key))
+      .map(([key, value]) => [key, value.unwrap()])
   }
 
   private async getStakingLedgers() {
@@ -74,7 +69,7 @@ export default abstract class StakingCommandBase extends AccountsCommandBase {
     return await this.simplePrompt<number>({ message, type: 'number' })
   }
 
-  async electionStatus() {
+  async checkElectionStatus() {
     const electionStatus = await this.getApi().getEraElectionStatus()
     if (electionStatus.isOpen === true) {
       this.warn(

+ 7 - 11
cli/src/commands/staking/validate.ts

@@ -3,25 +3,21 @@ import { flags } from '@oclif/command'
 
 export default class StakingValidateCommand extends StakingCommandBase {
   static description = 'Start validating. Takes the controller key.'
-  static args = [
-    {
-      name: 'commission',
+
+  static flags = {
+    commission: flags.integer({
       required: false,
       description:
         'Set a commission (0-100), which is deducted from all rewards before the remainder is split with nominator',
-    },
-  ]
-  static flags = {
+    }),
     controller: flags.string({
       required: false,
-      description: `The controller key you want to validate with.`,
+      description: 'The controller key you want to validate with.',
     }),
   }
 
   async run(): Promise<void> {
-    let { commission } = this.parse(StakingValidateCommand).args
-    let { controller } = this.parse(StakingValidateCommand).flags
-    await this.electionStatus()
+    let { commission, controller } = this.parse(StakingValidateCommand).flags
     const validatorPrefs = await this.getValidatorPrefs(commission)
 
     if (controller === undefined) {
@@ -29,7 +25,7 @@ export default class StakingValidateCommand extends StakingCommandBase {
     } else {
       await this.isController(controller)
     }
-    await this.electionStatus()
+    await this.checkElectionStatus()
     await this.sendAndFollowNamedTx(await this.getDecodedPair(controller), 'staking', 'validate', [validatorPrefs])
   }
 }