leaveRole.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import WorkingGroupsCommandBase from '../../base/WorkingGroupsCommandBase'
  2. import { apiModuleByGroup } from '../../Api'
  3. import chalk from 'chalk'
  4. import { flags } from '@oclif/command'
  5. export default class WorkingGroupsLeaveRole extends WorkingGroupsCommandBase {
  6. static description = 'Leave the worker or lead role associated with currently selected account.'
  7. static flags = {
  8. ...WorkingGroupsCommandBase.flags,
  9. rationale: flags.string({
  10. name: 'Optional rationale',
  11. required: false,
  12. }),
  13. }
  14. async run(): Promise<void> {
  15. // Worker-only gate
  16. const worker = await this.getRequiredWorkerContext()
  17. const {
  18. flags: { rationale },
  19. } = this.parse(WorkingGroupsLeaveRole)
  20. await this.sendAndFollowNamedTx(
  21. await this.getDecodedPair(worker.roleAccount.toString()),
  22. apiModuleByGroup[this.group],
  23. 'leaveRole',
  24. [worker.workerId, rationale || null]
  25. )
  26. this.log(chalk.green(`Successfully left the role! (worker id: ${chalk.magentaBright(worker.workerId.toString())})`))
  27. }
  28. }