import { CacheEvent } from "./types"; export const sum = (a: number[]) => a.reduce((s: number, i: number) => s + i, 0); export const getPercent = (value1: number, value2: number): number => { if (value1 === 0) return value2 > 0 ? Infinity : 0; return Number(((value2 * 100) / value1 - 100).toFixed(2)); }; export const momentToString = (timestamp: number) => new Date(timestamp).toLocaleDateString("en-US"); export const eventStats = (blockEventsCache: Map) => { let sections: { [key: string]: { [key: string]: [{ key: number; data: any }] }; } = {}; for (let [key, blockEvents] of blockEventsCache) { blockEvents.forEach(({ section, method, data }) => { if (!sections[section]) sections[section] = {}; if (sections[section][method]) sections[section][method].push({ key, data }); else sections[section][method] = [{ key, data }]; }); } console.log(`Events:`); Object.keys(sections).map((section: string) => Object.keys(sections[section]).map((method: string) => console.log(` ${section}.${method}: ${sections[section][method].length}`) ) ); }; export { connectApi, getBlock, getBlockHash, getHead, getBestHash, getTimestamp, getIssuance, getEvents, getEra, getEraStake, getCouncils, getCouncilRound, getCouncilStage, getCouncilElectionStage, getCouncilTermEnd, getCouncilElectionStatus, getCouncilSize, getCouncilApplicants, getCouncilCommitments, getCouncilPayoutInterval, getCouncilPayout, getCouncilElectionDurations, getNextWorker, getWorker, getWorkers, getStake, getAccounts, getAccount, getNextMember, getMember, getMemberIdByAccount, getMemberHandle, getMemberHandleByAccount, getNextPost, getNextThread, getNextCategory, getCategory, getThread, getPost, getActiveProposals, getProposalCount, getProposalInfo, getProposalDetails, getProposalType, getProposal, getProposalVotes, getProposalPost, getProposalPosts, getProposalPostCount, getProposalThreadCount, getValidatorCount, getValidators, } from "./api"; export { getChannel, getChannelCategory, getCuratorGroup, getVideo, getVideoCategory, getNextChannel, getNextChannelCategory, getNextCuratorGroup, getNextPerson, getNextPlaylist, getNextSeries, getNextVideo, getNextVideoCategory, } from "./content"; export { feePerMegabyte, maxStorageBucketsPerBag, maxDistributionBucketsPerBag, maxStorageBucketObjects, maxStorageBucketSize, uploadingBlocked, getBlacklist, getBlacklistSize, getDynamicBagPolicy, getNextDataObject, getNextStorageBucket, getNextDistributionFamily, getBag, getBags, getObject, getBagObjects, getStorageBucket, getStorageBuckets, getDistributionFamily, getDistributionFamilies, getDistributionFamilyNumber, getDistributionFamilyBucket, getDistributionFamilyBuckets, } from "./storage";