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