Explorar o código

fix CI checks

bwhm %!s(int64=3) %!d(string=hai) anos
pai
achega
a8633805e8
Modificáronse 3 ficheiros con 35 adicións e 30 borrados
  1. 0 2
      cli/src/Api.ts
  2. 32 23
      cli/src/base/StakingCommandBase.ts
  3. 3 5
      cli/src/commands/staking/validate.ts

+ 0 - 2
cli/src/Api.ts

@@ -152,8 +152,6 @@ export default class Api {
     return entries
   }
 
-
-
   protected async blockHash(height: number): Promise<string> {
     const blockHash = await this._api.rpc.chain.getBlockHash(height)
 

+ 32 - 23
cli/src/base/StakingCommandBase.ts

@@ -1,37 +1,37 @@
 import ExitCodes from '../ExitCodes'
-import { AccountId } from "@joystream/types/common"
+import { AccountId } from '@joystream/types/common'
 import { StakingLedger } from '@polkadot/types/interfaces'
-import AccountsCommandBase from "./AccountsCommandBase"
+import AccountsCommandBase from './AccountsCommandBase'
 import { formatBalance } from '@polkadot/util'
 
 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 stakerMap: [AccountId,StakingLedger][] = []
-    controllers.forEach(([key,value]) => {
+    const stakerMap: [AccountId, StakingLedger][] = []
+    controllers.forEach(([key, value]) => {
       const ledger = value.unwrapOr(undefined)
       if (!!ledger && this.isKeyAvailable(key)) {
-        stakerMap.push([key,ledger])
+        stakerMap.push([key, ledger])
       }
     })
     return stakerMap
   }
- 
-
 
   private async getStakingLedgers() {
     const controllers = await this.getApi().allStakingLedgers()
     return controllers
   }
 
-  async getController():Promise<string> {
+  async getController(): Promise<string> {
     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()
   }
 
-  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) {
       this.warn('No controller accounts to choose from!')
       this.exit(ExitCodes.NoAccountFound)
@@ -40,18 +40,24 @@ export default abstract class StakingCommandBase extends AccountsCommandBase {
       message,
       type: 'list',
       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),
-      })), 
+      })),
     })
     return selectedController
   }
 
-  async isController(controllerInput:string) {
+  async isController(controllerInput: string) {
     if (this.isKeyAvailable(controllerInput)) {
       const info = (await this.getApi().isControllerValid(controllerInput)).unwrapOr(undefined)
       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 {
         this.warn('Your account is not a controller!')
         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() {
     const electionStatus = await this.getApi().getEraElectionStatus()
     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)
     }
   }
 
   async getValidatorPrefs(commission: number | undefined): Promise<any> {
-    let validatorPrefs = {'commission': 0}
+    let validatorPrefs = { 'commission': 0 }
     if (!commission) {
       commission = await this.promptForCommission()
     }
     if (commission >= 0 && commission <= 100) {
-      validatorPrefs = {'commission': commission*10**7}
+      validatorPrefs = { 'commission': commission * 10 ** 7 }
     } else {
       this.warn('Invalid commission input!')
       this.exit(ExitCodes.InvalidInput)
     }
     return validatorPrefs
   }
-
-}
+}

+ 3 - 5
cli/src/commands/staking/validate.ts

@@ -1,14 +1,14 @@
 import StakingCommandBase from '../../base/StakingCommandBase'
 import { flags } from '@oclif/command'
 
-
 export default class StakingValidateCommand extends StakingCommandBase {
   static description = 'Start validating. Takes the controller key.'
   static args = [
     {
       name: 'commission',
       required: false,
-      description: 'Set a commission (0-100), which is deducted from all rewards before the remainder is split with nominator',
+      description:
+        'Set a commission (0-100), which is deducted from all rewards before the remainder is split with nominator',
     },
   ]
   static flags = {
@@ -17,7 +17,7 @@ export default class StakingValidateCommand extends StakingCommandBase {
       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
@@ -33,5 +33,3 @@ export default class StakingValidateCommand extends StakingCommandBase {
     await this.sendAndFollowNamedTx(await this.getDecodedPair(controller), 'staking', 'validate', [validatorPrefs])
   }
 }
-    
-