import { CacheEvent } from "./types"; import { Mint, MintId } from "@joystream/types/mint"; import { Moment } from "@polkadot/types/interfaces"; 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 ? 100 : 0; return Number(((value2 * 100) / value1 - 100).toFixed(2)); }; export const momentToString = (timestamp: number) => new Date(timestamp).toLocaleDateString("en-US"); export const getTotalMinted = (mint: Mint) => Number(mint.getField("total_minted").toString()); export const eventStats = (blockEventsCache: Map) => { let sections: { [key: string]: { [key: string]: [{ key: number; data: any }] }; } = {}; for (let [key, blockEvents] of blockEventsCache) { blockEvents.map(({ 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, getCouncil, getCouncilAt, getCouncils, getCouncilRound, getCouncilElectionStage, getCouncilTermEnd, getCouncilElectionStatus, getCouncilSize, getCouncilApplicants, getCouncilApplicantStakes, getCouncilCommitments, getCouncilPayoutInterval, getCouncilPayout, getCouncilElectionDurations, getCommitments, getCommitment, getNextWorker, getWorker, getWorkers, getStake, getWorkerReward, getCouncilMint, getGroupMint, getMintsCreated, getMint, 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, getPaidMembershipTermsById, } from "./api"; export { getChannel, getChannelCategory, getCuratorGroup, getPerson, getPlaylist, getSeries, getVideo, getVideoCategory, getNextChannel, getNextChannelCategory, getNextChannelOwnershipTransferRequestId, 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";