evictWorker.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. export default class WorkingGroupsEvictWorker extends WorkingGroupsCommandBase {
  9. static description = 'Evicts given worker. Requires lead access.';
  10. static args = [
  11. {
  12. name: 'workerId',
  13. required: true,
  14. description: 'Worker ID'
  15. },
  16. ]
  17. static flags = {
  18. ...WorkingGroupsCommandBase.flags,
  19. };
  20. async run() {
  21. const { args } = this.parse(WorkingGroupsEvictWorker);
  22. const account = await this.getRequiredSelectedAccount();
  23. // Lead-only gate
  24. await this.getRequiredLead();
  25. const workerId = parseInt(args.workerId);
  26. // This will also make sure the worker is valid
  27. const groupMember = await this.getApi().groupMember(this.group, workerId);
  28. const rationale = await this.promptForParam('Bytes', 'rationale'); // TODO: Terminate worker text limits? (minMaxStr)
  29. const shouldSlash = await this.simplePrompt({
  30. message: `Should the worker stake (${formatBalance(groupMember.stake)}) be slashed?`,
  31. type: 'confirm',
  32. default: false
  33. });
  34. await this.requestAccountDecoding(account);
  35. await this.sendAndFollowExtrinsic(
  36. account,
  37. apiModuleByGroup[this.group],
  38. 'terminateRole',
  39. [
  40. new WorkerId(workerId),
  41. rationale,
  42. new bool(shouldSlash)
  43. ]
  44. );
  45. this.log(chalk.green(`Worker ${chalk.white(workerId)} has been evicted!`));
  46. if (shouldSlash) {
  47. this.log(chalk.green(`Worker stake totalling ${chalk.white(formatBalance(groupMember.stake))} has been slashed!`));
  48. }
  49. }
  50. }