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 Promise; export const getBlacklist = (api: ApiPromise): Promise => api.query.storage.blacklist(); export const getBlacklistSize = (api: ApiPromise): Promise => api.query.storage.currentBlacklistSize(); export const maxStorageBucketsPerBag = (api: ApiPromise): Promise => api.query.storage.storageBucketsPerBagLimit(); export const maxDistributionBucketsPerBag = ( api: ApiPromise ): Promise => api.query.storage.distributionBucketsPerBagLimit(); export const maxStorageBucketObjects = (api: ApiPromise): Promise => api.query.storage.voucherMaxObjectsNumberLimit(); export const maxStorageBucketSize = (api: ApiPromise): Promise => api.query.storage.voucherMaxObjectsSizeLimit(); export const feePerMegabyte = (api: ApiPromise): Promise => api.query.storage.dataObjectPerMegabyteFee(); export const getDynamicBagPolicy = ( api: ApiPromise, type?: DynamicBagType | "Member" | "Channel" | number ): Promise< DynamicBagCreationPolicy | Map > => type ? api.query.storage.dynamicBagCreationPolicies(type) : 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); export const getBags = async (api: ApiPromise): Promise> => api.query.storage.bags.entries(); export const getObject = ( api: ApiPromise, bagId: BagId | { Static: any } | { Dynamic: any } | string | number, objectId: DataObjectId | number ): Promise> => api.query.storage.dataObjectsById(bagId, objectId); export const getBagObjects = ( api: ApiPromise, bagId: BagId | { Static: any } | { Dynamic: any } | string | number ): Promise> => api.query.storage.dataObjectsById.entries(bagId); // 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(); // distribution export const getDistributionFamilyNumber = (api: ApiPromise): Promise => api.query.storage.distributionBucketFamilyNumber(); export const getDistributionFamilyBuckets = ( api: ApiPromise, familyId: DistributionBucketFamilyId | number ): Promise> => api.query.storage.distributionBucketByFamilyIdById.entries( familyId ) as Promise>; 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(); export const getDistributionFamily = async ( api: ApiPromise, familyId: DistributionBucketFamilyId | number ): Promise => (await api.query.storage.distributionBucketFamilyById( familyId )) as DistributionBucketFamily;