3
0

index.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { CacheEvent } from "./types";
  2. import { Mint, MintId } from "@joystream/types/mint";
  3. import { Moment } from "@polkadot/types/interfaces";
  4. export const sum = (a: number[]) =>
  5. a.reduce((s: number, i: number) => s + i, 0);
  6. export const getPercent = (value1: number, value2: number): number => {
  7. if (value1 === 0) return value2 > 0 ? Infinity : 0;
  8. return Number(((value2 * 100) / value1 - 100).toFixed(2));
  9. };
  10. export const momentToString = (timestamp: number) =>
  11. new Date(timestamp).toLocaleDateString("en-US");
  12. export const getTotalMinted = (mint: Mint) =>
  13. Number(mint.getField("total_minted").toString());
  14. export const eventStats = (blockEventsCache: Map<number, CacheEvent[]>) => {
  15. let sections: {
  16. [key: string]: { [key: string]: [{ key: number; data: any }] };
  17. } = {};
  18. for (let [key, blockEvents] of blockEventsCache) {
  19. blockEvents.map(({ section, method, data }) => {
  20. if (!sections[section]) sections[section] = {};
  21. if (sections[section][method])
  22. sections[section][method].push({ key, data });
  23. else sections[section][method] = [{ key, data }];
  24. });
  25. }
  26. console.log(`Events:`);
  27. Object.keys(sections).map((section: string) =>
  28. Object.keys(sections[section]).map((method: string) =>
  29. console.log(` ${section}.${method}: ${sections[section][method].length}`)
  30. )
  31. );
  32. };
  33. export {
  34. connectApi,
  35. getBlock,
  36. getBlockHash,
  37. getHead,
  38. getBestHash,
  39. getTimestamp,
  40. getIssuance,
  41. getEvents,
  42. getEra,
  43. getEraStake,
  44. getCouncil,
  45. getCouncilAt,
  46. getCouncils,
  47. getCouncilRound,
  48. getCouncilElectionStage,
  49. getCouncilTermEnd,
  50. getCouncilElectionStatus,
  51. getCouncilSize,
  52. getCouncilApplicants,
  53. getCouncilApplicantStakes,
  54. getCouncilCommitments,
  55. getCouncilPayoutInterval,
  56. getCouncilPayout,
  57. getCouncilElectionDurations,
  58. getCommitments,
  59. getCommitment,
  60. getNextWorker,
  61. getWorker,
  62. getWorkers,
  63. getStake,
  64. getWorkerReward,
  65. getCouncilMint,
  66. getGroupMint,
  67. getMintsCreated,
  68. getMint,
  69. getAccounts,
  70. getAccount,
  71. getNextMember,
  72. getMember,
  73. getMemberIdByAccount,
  74. getMemberHandle,
  75. getMemberHandleByAccount,
  76. getNextPost,
  77. getNextThread,
  78. getNextCategory,
  79. getCategory,
  80. getThread,
  81. getPost,
  82. getActiveProposals,
  83. getProposalCount,
  84. getProposalInfo,
  85. getProposalDetails,
  86. getProposalType,
  87. getProposal,
  88. getProposalVotes,
  89. getProposalPost,
  90. getProposalPosts,
  91. getProposalPostCount,
  92. getProposalThreadCount,
  93. getValidatorCount,
  94. getValidators,
  95. getPaidMembershipTermsById,
  96. } from "./api";
  97. export {
  98. getChannel,
  99. getChannelCategory,
  100. getCuratorGroup,
  101. getPerson,
  102. getPlaylist,
  103. getSeries,
  104. getVideo,
  105. getVideoCategory,
  106. getNextChannel,
  107. getNextChannelCategory,
  108. getNextChannelOwnershipTransferRequestId,
  109. getNextCuratorGroup,
  110. getNextPerson,
  111. getNextPlaylist,
  112. getNextSeries,
  113. getNextVideo,
  114. getNextVideoCategory,
  115. } from "./content";
  116. export {
  117. feePerMegabyte,
  118. maxStorageBucketsPerBag,
  119. maxDistributionBucketsPerBag,
  120. maxStorageBucketObjects,
  121. maxStorageBucketSize,
  122. uploadingBlocked,
  123. getBlacklist,
  124. getBlacklistSize,
  125. getDynamicBagPolicy,
  126. getNextDataObject,
  127. getNextStorageBucket,
  128. getNextDistributionFamily,
  129. getBag,
  130. getBags,
  131. getObject,
  132. getBagObjects,
  133. getStorageBucket,
  134. getStorageBuckets,
  135. getDistributionFamily,
  136. getDistributionFamilies,
  137. getDistributionFamilyNumber,
  138. getDistributionFamilyBucket,
  139. getDistributionFamilyBuckets,
  140. } from "./storage";