index.ts 2.9 KB

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