info.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { ElectionStage } from '@joystream/types';
  2. import { formatNumber, formatBalance } from '@polkadot/util';
  3. import { BlockNumber } from '@polkadot/types/interfaces';
  4. import { CouncilInfoObj, NameValueObj } from '../../Types';
  5. import { displayHeader, displayNameValueTable } from '../../helpers/display';
  6. import ApiCommandBase from '../../base/ApiCommandBase';
  7. export default class CouncilInfo extends ApiCommandBase {
  8. static description = 'Get current council and council elections information';
  9. displayInfo(infoObj: CouncilInfoObj) {
  10. const { activeCouncil = [], round, stage } = infoObj;
  11. displayHeader('Council');
  12. const councilRows: NameValueObj[] = [
  13. { name: 'Elected:', value: activeCouncil.length ? 'YES' : 'NO' },
  14. { name: 'Members:', value: activeCouncil.length.toString() },
  15. { name: 'Term ends at block:', value: `#${formatNumber(infoObj.termEndsAt) }` },
  16. ];
  17. displayNameValueTable(councilRows);
  18. displayHeader('Election');
  19. let electionTableRows: NameValueObj[] = [
  20. { name: 'Running:', value: stage && stage.isSome ? 'YES' : 'NO' },
  21. { name: 'Election round:', value: formatNumber(round) }
  22. ];
  23. if (stage && stage.isSome) {
  24. const stageValue = <ElectionStage> stage.value;
  25. const stageName: string = stageValue.type;
  26. const stageEndsAt = <BlockNumber> stageValue.value;
  27. electionTableRows.push({ name: 'Stage:', value: stageName });
  28. electionTableRows.push({ name: 'Stage ends at block:', value: `#${stageEndsAt}` });
  29. }
  30. displayNameValueTable(electionTableRows);
  31. displayHeader('Configuration');
  32. const isAutoStart = (infoObj.autoStart || false).valueOf();
  33. const configTableRows: NameValueObj[] = [
  34. { name: 'Auto-start elections:', value: isAutoStart ? 'YES' : 'NO' },
  35. { name: 'New term duration:', value: formatNumber(infoObj.newTermDuration) },
  36. { name: 'Candidacy limit:', value: formatNumber(infoObj.candidacyLimit) },
  37. { name: 'Council size:', value: formatNumber(infoObj.councilSize) },
  38. { name: 'Min. council stake:', value: formatBalance(infoObj.minCouncilStake) },
  39. { name: 'Min. voting stake:', value: formatBalance(infoObj.minVotingStake) },
  40. { name: 'Announcing period:', value: `${ formatNumber(infoObj.announcingPeriod) } blocks` },
  41. { name: 'Voting period:', value: `${ formatNumber(infoObj.votingPeriod) } blocks` },
  42. { name: 'Revealing period:', value: `${ formatNumber(infoObj.revealingPeriod) } blocks` }
  43. ];
  44. displayNameValueTable(configTableRows);
  45. }
  46. async run() {
  47. const infoObj = await this.getApi().getCouncilInfo();
  48. this.displayInfo(infoObj);
  49. }
  50. }