Browse Source

types: update storage types

Mokhtar Naamani 4 years ago
parent
commit
9c267d83d8

File diff suppressed because it is too large
+ 3 - 3
types/augment-codec/all.ts


+ 1 - 0
types/augment-codec/augment-api-consts.ts

@@ -3,6 +3,7 @@
 
 import { Vec } from '@polkadot/types/codec';
 import { u32, u64 } from '@polkadot/types/primitive';
+import { MaxNumber } from './all';
 import { Balance, BalanceOf, BlockNumber, Moment, Perbill, RuntimeDbWeight, Weight } from '@polkadot/types/interfaces/runtime';
 import { SessionIndex } from '@polkadot/types/interfaces/session';
 import { EraIndex } from '@polkadot/types/interfaces/staking';

File diff suppressed because it is too large
+ 0 - 0
types/augment-codec/augment-types.ts


+ 32 - 31
types/augment/all/defs.json

@@ -97,6 +97,8 @@
     "MemoText": "Text",
     "Address": "AccountId",
     "LookupSource": "AccountId",
+    "ChannelId": "u64",
+    "DAOId": "u64",
     "EntryMethod": {
         "_enum": {
             "Paid": "u64",
@@ -489,7 +491,7 @@
         ]
     },
     "DataObject": {
-        "owner": "MemberId",
+        "owner": "StorageObjectOwner",
         "added_at": "BlockAndTime",
         "type_id": "DataObjectTypeId",
         "size": "u64",
@@ -509,6 +511,34 @@
         "active": "bool"
     },
     "DataObjectsMap": "BTreeMap<ContentId,DataObject>",
+    "ContentParameters": {
+        "content_id": "ContentId",
+        "type_id": "DataObjectTypeId",
+        "size": "u64",
+        "ipfs_content_id": "Bytes"
+    },
+    "StorageObjectOwner": {
+        "_enum": {
+            "Member": "MemberId",
+            "AbstractStorageObjectOwner": "AbstractStorageObjectOwner"
+        }
+    },
+    "AbstractStorageObjectOwner": {
+        "_enum": {
+            "Channel": "ChannelId",
+            "DAO": "DAOId",
+            "Council": "Null",
+            "WorkingGroup": "WorkingGroupType"
+        }
+    },
+    "WorkingGroupType": {
+        "_enum": [
+            "ContentDirectory",
+            "Builders",
+            "StorageProviders"
+        ]
+    },
+    "Content": "Vec<ContentParameters>",
     "ProposalId": "u32",
     "ProposalStatus": {
         "_enum": {
@@ -670,34 +700,6 @@
             "Lead": "Null"
         }
     },
-    "DAOId": "u64",
-    "ContentParameters": {
-        "content_id": "ContentId",
-        "type_id": "DataObjectTypeId",
-        "size": "u64",
-        "ipfs_content_id": "Bytes"
-    },
-    "StorageObjectOwner": {
-        "_enum": {
-            "Member": "MemberId",
-            "AbstractStorageObjectOwner": "AbstractStorageObjectOwner"
-        }
-    },
-    "AbstractStorageObjectOwner": {
-        "_enum": {
-            "Channel": "ChannelId",
-            "DAO": "DAOId",
-            "Council": "Null",
-            "WorkingGroup": "WorkingGroupType"
-        }
-    },
-    "WorkingGroupType": {
-        "_enum": [
-            "ContentDirectory",
-            "Builders",
-            "StorageProviders"
-        ]
-    },
     "NewAsset": {
         "_enum": {
             "Upload": "ContentParameters",
@@ -721,7 +723,6 @@
             "Dao": "DAOId"
         }
     },
-    "ChannelId": "u64",
     "ChannelCategoryId": "u64",
     "ChannelCategory": {
         "number_of_channels_in": "u32"
@@ -845,5 +846,5 @@
             "ChangeExistingVideo": "VideoId"
         }
     },
-    "Content": "Vec<ContentParameters>"
+    "MaxNumber": "u32"
 }

+ 4 - 1
types/augment/all/types.ts

@@ -359,7 +359,7 @@ export interface DAOId extends u64 {}
 
 /** @name DataObject */
 export interface DataObject extends Struct {
-  readonly owner: MemberId;
+  readonly owner: StorageObjectOwner;
   readonly added_at: BlockAndTime;
   readonly type_id: DataObjectTypeId;
   readonly liaison: StorageProviderId;
@@ -562,6 +562,9 @@ export interface LiaisonJudgement extends Enum {
 /** @name LookupSource */
 export interface LookupSource extends AccountId {}
 
+/** @name MaxNumber */
+export interface MaxNumber extends u32 {}
+
 /** @name MemberId */
 export interface MemberId extends u64 {}
 

+ 1 - 0
types/augment/augment-api-consts.ts

@@ -3,6 +3,7 @@
 
 import { Vec } from '@polkadot/types/codec';
 import { u32, u64 } from '@polkadot/types/primitive';
+import { MaxNumber } from './all';
 import { Balance, BalanceOf, BlockNumber, Moment, Perbill, RuntimeDbWeight, Weight } from '@polkadot/types/interfaces/runtime';
 import { SessionIndex } from '@polkadot/types/interfaces/session';
 import { EraIndex } from '@polkadot/types/interfaces/staking';

File diff suppressed because it is too large
+ 0 - 0
types/augment/augment-types.ts


+ 5 - 0
types/src/common.ts

@@ -44,6 +44,9 @@ export function JoyBTreeSet<V extends UInt>(valType: Constructor<V>): Constructo
   }
 }
 
+export class ChannelId extends u64 {}
+export class DAOId extends u64 {}
+
 // common types between Forum and Proposal Discussions modules
 export class ThreadId extends u64 {}
 export class PostId extends u64 {}
@@ -146,6 +149,8 @@ export const commonTypes: RegistryTypes = {
   MemoText,
   Address,
   LookupSource,
+  ChannelId,
+  DAOId,
 }
 
 export default commonTypes

+ 4 - 40
types/src/content/index.ts

@@ -1,12 +1,11 @@
 import { Text, Vec, Option, Tuple } from '@polkadot/types'
 import { bool, u64, u32, u128, Null, Bytes } from '@polkadot/types/primitive'
 import { MemberId } from '../members'
-import { JoyStructDecorated, JoyEnum, /* Hash, */ JoyBTreeSet } from '../common'
-import { ContentId, DataObjectTypeId } from '../storage'
+import { JoyStructDecorated, JoyEnum, ChannelId, JoyBTreeSet, DAOId } from '../common'
+import { ContentParameters } from '../storage'
 
 export class CuratorId extends u64 {}
 export class CuratorGroupId extends u64 {}
-export class ChannelId extends u64 {}
 export class ChannelCategoryId extends u64 {}
 export class VideoId extends u64 {}
 export class VideoCategoryId extends u64 {}
@@ -14,7 +13,7 @@ export class PlaylistId extends u64 {}
 export class PersonId extends u64 {}
 export class SeriesId extends u64 {}
 export class ChannelOwnershipTransferRequestId extends u64 {}
-export class DAOId extends u64 {}
+export class MaxNumber extends u32 {}
 
 export class CuratorGroup extends JoyStructDecorated({
   curators: JoyBTreeSet(CuratorId),
@@ -181,53 +180,19 @@ export class PersonActor extends JoyEnum({
   Curator: CuratorId,
 }) {}
 
-export class ContentParameters extends JoyStructDecorated({
-  content_id: ContentId,
-  type_id: DataObjectTypeId,
-  size: u64,
-  ipfs_content_id: Bytes,
-}) {}
-
 export class NewAsset extends JoyEnum({
   Upload: ContentParameters,
   Uri: Text,
 }) {}
 
-// mis-spelled in runtime
-export class WorkingGroupType extends JoyEnum({
-  ContentDirectory: Null,
-  Builders: Null,
-  StorageProviders: Null,
-}) {}
-
-export class AbstractStorageObjectOwner extends JoyEnum({
-  Channel: ChannelId,
-  DAO: DAOId,
-  Council: Null,
-  WorkingGroup: WorkingGroupType,
-}) {}
-
-export class StorageObjectOwner extends JoyEnum({
-  Member: MemberId,
-  AbstractStorageObjectOwner: AbstractStorageObjectOwner,
-}) {}
-
-export class Content extends Vec.with(ContentParameters) {}
-
 export const contentDirectoryTypes = {
   CuratorId,
   CuratorGroupId,
   CuratorGroup,
   ContentActor,
-  DAOId,
-  ContentParameters,
-  StorageObjectOwner,
-  AbstractStorageObjectOwner,
-  WorkingGroupType,
   NewAsset,
   Channel,
   ChannelOwner,
-  ChannelId,
   ChannelCategoryId,
   ChannelCategory,
   ChannelCategoryCreationParameters,
@@ -263,8 +228,7 @@ export const contentDirectoryTypes = {
   SeasonUpdateParameters,
   EpisodeCreationParameters,
   EpisodeUpdateParemters,
-  // type used in data_directory Events
-  Content,
+  MaxNumber,
 }
 
 export default contentDirectoryTypes

+ 41 - 4
types/src/storage.ts

@@ -1,5 +1,5 @@
-import { Option, Vec as Vector, BTreeMap, u64, bool, Text, Null } from '@polkadot/types'
-import { BlockAndTime, JoyEnum, JoyStructDecorated, Hash } from './common'
+import { Option, Vec, BTreeMap, u64, bool, Text, Null, Bytes } from '@polkadot/types'
+import { BlockAndTime, JoyEnum, JoyStructDecorated, Hash, ChannelId, DAOId } from './common'
 import { MemberId } from './members'
 import { StorageProviderId } from './working-group' // this should be in discovery really
 import { randomAsU8a } from '@polkadot/util-crypto'
@@ -29,7 +29,7 @@ export class ContentId extends Hash {
 export class DataObjectTypeId extends u64 {}
 export class DataObjectStorageRelationshipId extends u64 {}
 
-export class VecContentId extends Vector.with(ContentId) {}
+export class VecContentId extends Vec.with(ContentId) {}
 export class OptionVecContentId extends Option.with(VecContentId) {}
 
 export const LiaisonJudgementDef = {
@@ -40,8 +40,40 @@ export const LiaisonJudgementDef = {
 export type LiaisonJudgementKey = keyof typeof LiaisonJudgementDef
 export class LiaisonJudgement extends JoyEnum(LiaisonJudgementDef) {}
 
+export class WorkingGroupType extends JoyEnum({
+  ContentDirectory: Null,
+  Builders: Null,
+  StorageProviders: Null,
+}) {}
+
+export class AbstractStorageObjectOwner extends JoyEnum({
+  Channel: ChannelId,
+  DAO: DAOId,
+  Council: Null,
+  WorkingGroup: WorkingGroupType,
+}) {}
+
+export class StorageObjectOwner extends JoyEnum({
+  Member: MemberId,
+  AbstractStorageObjectOwner: AbstractStorageObjectOwner,
+}) {}
+
+export class ContentParameters extends JoyStructDecorated({
+  content_id: ContentId,
+  type_id: DataObjectTypeId,
+  size: u64,
+  ipfs_content_id: Bytes,
+}) {
+  /** Actually it's 'size', but 'size' is already reserved by a parent class. */
+  get size_in_bytes(): u64 {
+    return this.get('size') as u64
+  }
+}
+
+export class Content extends Vec.with(ContentParameters) {}
+
 export class DataObject extends JoyStructDecorated({
-  owner: MemberId,
+  owner: StorageObjectOwner,
   added_at: BlockAndTime,
   type_id: DataObjectTypeId,
   size: u64,
@@ -77,6 +109,11 @@ export const mediaTypes: RegistryTypes = {
   DataObjectTypeId,
   DataObjectType,
   DataObjectsMap,
+  ContentParameters,
+  StorageObjectOwner,
+  AbstractStorageObjectOwner,
+  WorkingGroupType,
+  Content,
 }
 
 export default mediaTypes

+ 1 - 1
utils/api-scripts/package.json

@@ -9,7 +9,7 @@
     "tsnode-strict": "node -r ts-node/register --unhandled-rejections=strict"
   },
   "dependencies": {
-    "@joystream/types": "^0.14.0",
+    "@joystream/types": "^0.16.0",
     "@polkadot/api": "^1.26.1",
     "@polkadot/types": "^1.26.1",
     "@polkadot/keyring": "^3.0.1",

Some files were not shown because too many files changed in this diff