3
0

index.ts 2.9 KB

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