import { ApiPromise } from "@polkadot/api"; import type { ITuple } from "@polkadot/types/types"; import { Bag, BagId, Cid, DynamicBagType, DynamicBagCreationPolicy, DataObject, DataObjectId, StorageBucket, StorageBucketId, DistributionBucket, DistributionBucketIndex, DistributionBucketFamily, DistributionBucketFamilyId, } from "@joystream/types/storage"; import { Hash } from "@polkadot/types/interfaces"; export const uploadingBlocked = (api: ApiPromise): Promise => api.query.storage.uploadingBlocked() as any; export const getBlacklist = (api: ApiPromise): Promise => api.query.storage.blacklist() as any; export const getBlacklistSize = (api: ApiPromise): Promise => api.query.storage.currentBlacklistSize() as any; export const maxStorageBucketsPerBag = (api: ApiPromise): Promise => api.query.storage.storageBucketsPerBagLimit() as any; export const maxDistributionBucketsPerBag = ( api: ApiPromise ): Promise => api.query.storage.distributionBucketsPerBagLimit() as any; export const maxStorageBucketObjects = (api: ApiPromise): Promise => api.query.storage.voucherMaxObjectsNumberLimit() as any; export const maxStorageBucketSize = (api: ApiPromise): Promise => api.query.storage.voucherMaxObjectsSizeLimit() as any; export const feePerMegabyte = (api: ApiPromise): Promise => api.query.storage.dataObjectPerMegabyteFee() as any; export const getDynamicBagPolicy = ( api: ApiPromise, type?: DynamicBagType | "Member" | "Channel" | number ): Promise< DynamicBagCreationPolicy | Map > => type ? (api.query.storage.dynamicBagCreationPolicies(type) as any) : api.query.storage.dynamicBagCreationPolicies.entries(); export const getNextDataObject = (api: ApiPromise): Promise => api.query.storage.nextDataObjectId() as Promise; export const getNextStorageBucket = ( api: ApiPromise ): Promise => api.query.storage.nextStorageBucketId() as Promise; export const getNextDistributionFamily = ( api: ApiPromise ): Promise => api.query.storage.nextDistributionBucketFamilyId() as Promise; // video + cover are contained in one bag export const getBag = ( api: ApiPromise, bagId: BagId | { Static: any } | { Dynamic: any } | string | number ): Promise => api.query.storage.bags(bagId) as any; export const getBags = async (api: ApiPromise): Promise> => api.query.storage.bags.entries() as any; export const getObject = ( api: ApiPromise, bagId: BagId | { Static: any } | { Dynamic: any } | string | number, objectId: DataObjectId | number ): Promise> => api.query.storage.dataObjectsById(bagId, objectId) as any; export const getBagObjects = ( api: ApiPromise, bagId: BagId | { Static: any } | { Dynamic: any } | string | number ): Promise> => api.query.storage.dataObjectsById.entries(bagId) as any; // storage export const getStorageBucket = ( api: ApiPromise, bucketId: StorageBucketId | Hash, hash?: Hash ): Promise => (hash ? api.query.storage.storageBucketById.at(hash, bucketId) : api.query.storage.storageBucketById(bucketId)) as Promise; export const getStorageBuckets = ( api: ApiPromise ): Promise> => api.query.storage.storageBucketById.entries().then((entries) => entries.map(([{ args: [id], }, bucket]) => [id, bucket] )) as Promise> // distribution export const getDistributionFamilyNumber = (api: ApiPromise): Promise => api.query.storage.distributionBucketFamilyNumber() as any; export const getDistributionFamilyBuckets = ( api: ApiPromise, familyId: DistributionBucketFamilyId | number ): Promise> => api.query.storage.distributionBucketByFamilyIdById.entries(familyId) as any; export const getDistributionFamilyBucket = ( api: ApiPromise, familyId: DistributionBucketFamilyId | number, bucketIndex: DistributionBucketIndex | number ): Promise => api.query.storage.distributionBucketByFamilyIdById( familyId, bucketIndex ) as Promise; export const getDistributionFamilies = ( api: ApiPromise ): Promise> => api.query.storage.distributionBucketFamilyById.entries() as any; export const getDistributionFamily = async ( api: ApiPromise, familyId: DistributionBucketFamilyId | number ): Promise => (await api.query.storage.distributionBucketFamilyById( familyId )) as DistributionBucketFamily;