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