Quellcode durchsuchen

Giza: content + storage calls

Joystream Stats vor 2 Jahren
Ursprung
Commit
92fc8962e7
3 geänderte Dateien mit 311 neuen und 1 gelöschten Zeilen
  1. 46 1
      api.ts
  2. 127 0
      content.ts
  3. 138 0
      storage.ts

+ 46 - 1
api.ts

@@ -47,7 +47,6 @@ import {
 } from "@joystream/types/recurring-rewards";
 import { WorkerId, Worker } from "@joystream/types/working-group";
 import { ProposalOf, ProposalDetailsOf } from "@joystream/types/augment/types";
-
 import { WorkerOf } from "@joystream/types/augment-codec/all";
 
 export const connectApi = async (url: string): Promise<ApiPromise> => {
@@ -546,3 +545,49 @@ export const getPaidMembershipTermsById = (
   id: PaidTermId | number
 ): Promise<PaidMembershipTerms> =>
   api.query.members.paidMembershipTermsById.at(hash, id);
+
+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";

+ 127 - 0
content.ts

@@ -0,0 +1,127 @@
+import { ApiPromise } from "@polkadot/api";
+import {
+  CuratorGroup,
+  CuratorGroupId,
+  Channel,
+  ChannelCategory,
+  ChannelCategoryId,
+  ChannelOwnershipTransferRequest,
+  ChannelOwnershipTransferRequestId,
+  Person,
+  PersonId,
+  Playlist,
+  PlaylistId,
+  Series,
+  SeriesId,
+  Video,
+  VideoId,
+  VideoCategory,
+  VideoCategoryId,
+} from "@joystream/types/content";
+import { ChannelId } from "@joystream/types/storage";
+import { Hash } from "@polkadot/types/interfaces";
+
+export const getCuratorGroup = (
+  api: ApiPromise,
+  id: CuratorGroupId | number
+): Promise<CuratorGroup> =>
+  api.query.content.curatorGroupById(id) as Promise<CuratorGroup>;
+
+export const getChannel = (
+  api: ApiPromise,
+  id: ChannelId | number
+): Promise<Channel> => api.query.content.channelById(id) as Promise<Channel>;
+
+export const getChannelCategory = (
+  api: ApiPromise,
+  id: ChannelCategoryId | number
+): Promise<ChannelCategory> =>
+  api.query.content.channelCategoryById(id) as Promise<ChannelCategory>;
+
+export const getVideo = (
+  api: ApiPromise,
+  id: VideoId | number
+): Promise<Video> => api.query.content.videoById(id) as Promise<Video>;
+
+export const getVideoCategory = (
+  api: ApiPromise,
+  id: VideoId | number
+): Promise<Video> => api.query.content.videoCategoryById(id) as Promise<Video>;
+
+export const getPerson = (
+  api: ApiPromise,
+  id: PersonId | number
+): Promise<Person> => api.query.content.personById(id) as Promise<Person>;
+
+export const getPlaylist = (
+  api: ApiPromise,
+  id: PlaylistId | number
+): Promise<Playlist> => api.query.content.playlistById(id) as Promise<Playlist>;
+
+export const getSeries = (
+  api: ApiPromise,
+  id: SeriesId | number
+): Promise<Series> => api.query.content.seriesById(id) as Promise<Series>;
+
+export const getNextChannel = (
+  api: ApiPromise,
+  hash?: Hash
+): Promise<ChannelId> =>
+  hash
+    ? (api.query.content.nextChannelId.at(hash) as Promise<ChannelId>)
+    : (api.query.content.nextChannelId() as Promise<ChannelId>);
+
+export const getNextChannelCategory = (
+  api: ApiPromise,
+  hash?: Hash
+): Promise<ChannelCategoryId> =>
+  hash
+    ? api.query.content.nextChannelCategoryId.at(hash)
+    : (api.query.content.nextChannelCategoryId() as Promise<ChannelCategoryId>);
+
+export const getNextChannelOwnershipTransferRequestId = (
+  api: ApiPromise,
+  hash?: Hash
+): Promise<ChannelOwnershipTransferRequestId> =>
+  hash
+    ? api.query.content.nextChannelOwnershipTransferRequestId.at(hash)
+    : (api.query.content.nextChannelOwnershipTransferRequestId() as Promise<ChannelOwnershipTransferRequestId>);
+
+export const getNextCuratorGroup = (
+  api: ApiPromise,
+  hash?: Hash
+): Promise<CuratorGroupId> =>
+  hash
+    ? api.query.content.nextCuratorGroupId.at(hash)
+    : (api.query.content.nextCuratorGroupId() as Promise<CuratorGroupId>);
+
+export const getNextPerson = (api: ApiPromise, hash?: Hash): Promise<number> =>
+  hash
+    ? api.query.content.nextPersonId.at(hash)
+    : api.query.content.nextPersonId();
+
+export const getNextPlaylist = (
+  api: ApiPromise,
+  hash?: Hash
+): Promise<number> =>
+  hash
+    ? api.query.content.nextPlaylistId.at(hash)
+    : api.query.content.nextPlaylistId();
+
+export const getNextSeries = (api: ApiPromise, hash?: Hash): Promise<number> =>
+  hash
+    ? api.query.content.nextSeriesId.at(hash)
+    : api.query.content.nextSeriesId();
+
+export const getNextVideo = (api: ApiPromise, hash?: Hash): Promise<number> =>
+  hash
+    ? api.query.content.nextVideoId.at(hash)
+    : api.query.content.nextVideoId();
+
+export const getNextVideoCategory = (
+  api: ApiPromise,
+  hash?: Hash
+): Promise<number> =>
+  hash
+    ? api.query.content.nextVideoCategoryId.at(hash)
+    : api.query.content.nextVideoCategoryId();

+ 138 - 0
storage.ts

@@ -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;