evictWorker.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import WorkingGroupsCommandBase from '../../base/WorkingGroupsCommandBase';
  2. import _ from 'lodash';
  3. import { apiModuleByGroup } from '../../Api';
  4. import { WorkerId } from '@joystream/types/lib/working-group';
  5. import { bool } from '@polkadot/types/primitive';
  6. import { formatBalance } from '@polkadot/util';
  7. import chalk from 'chalk';
  8. import { createParamOptions } from '../../helpers/promptOptions';
  9. export default class WorkingGroupsEvictWorker extends WorkingGroupsCommandBase {
  10. static description = 'Evicts given worker. Requires lead access.';
  11. static args = [
  12. {
  13. name: 'workerId',
  14. required: true,
  15. description: 'Worker ID'
  16. },
  17. ]
  18. static flags = {
  19. ...WorkingGroupsCommandBase.flags,
  20. };
  21. async run() {
  22. const { args } = this.parse(WorkingGroupsEvictWorker);
  23. const account = await this.getRequiredSelectedAccount();
  24. // Lead-only gate
  25. await this.getRequiredLead();
  26. const workerId = parseInt(args.workerId);
  27. // This will also make sure the worker is valid
  28. const groupMember = await this.getWorkerForLeadAction(workerId);
  29. // TODO: Terminate worker text limits? (minMaxStr)
  30. const rationale = await this.promptForParam('Bytes', createParamOptions('rationale'));
  31. const shouldSlash = groupMember.stake
  32. ?
  33. await this.simplePrompt({
  34. message: `Should the worker stake (${formatBalance(groupMember.stake)}) be slashed?`,
  35. type: 'confirm',
  36. default: false
  37. })
  38. : false;
  39. await this.requestAccountDecoding(account);
  40. await this.sendAndFollowExtrinsic(
  41. account,
  42. apiModuleByGroup[this.group],
  43. 'terminateRole',
  44. [
  45. new WorkerId(workerId),
  46. rationale,
  47. new bool(shouldSlash)
  48. ]
  49. );
  50. this.log(chalk.green(`Worker ${chalk.white(workerId)} has been evicted!`));
  51. if (shouldSlash) {
  52. this.log(chalk.green(`Worker stake totalling ${chalk.white(formatBalance(groupMember.stake))} has been slashed!`));
  53. }
  54. }
  55. }