Browse Source

query node - big number removal + dataObject owner fix

ondratra 3 năm trước cách đây
mục cha
commit
2824c90e0e

+ 4 - 6
query-node/generated/graphql-server/src/modules/curator-group/curator-group.model.ts

@@ -1,16 +1,14 @@
-import { BaseModel, BooleanField, NumericField, Model, OneToMany, CustomField, StringField } from 'warthog';
-
-import BN from 'bn.js';
+import { BaseModel, BooleanField, IntField, Model, OneToMany, CustomField, StringField } from 'warthog';
 
 import { Channel } from '../channel/channel.model';
 
 @Model({ api: {} })
 export class CuratorGroup extends BaseModel {
   @CustomField({
-    db: { type: 'numeric', array: true },
-    api: { type: 'numeric', description: `Curators belonging to this group` },
+    db: { type: 'integer', array: true },
+    api: { type: 'integer', description: `Curators belonging to this group` },
   })
-  curatorIds!: BN[];
+  curatorIds!: number[];
 
   @BooleanField({
     description: `Is group active or not`,

+ 5 - 19
query-node/generated/graphql-server/src/modules/data-object/data-object.model.ts

@@ -1,6 +1,4 @@
-import { BaseModel, IntField, NumericField, Model, OneToMany, EnumField, StringField } from 'warthog';
-
-import BN from 'bn.js';
+import { BaseModel, IntField, Model, OneToMany, EnumField, StringField } from 'warthog';
 
 import { Column } from 'typeorm';
 import { Field } from 'type-graphql';
@@ -33,28 +31,16 @@ export class DataObject extends BaseModel {
   })
   typeId!: number;
 
-  @NumericField({
+  @IntField({
     description: `Content size in bytes`,
-
-    transformer: {
-      to: (entityValue: BN) => (entityValue !== undefined ? entityValue.toString(10) : null),
-      from: (dbValue: string) =>
-        dbValue !== undefined && dbValue !== null && dbValue.length > 0 ? new BN(dbValue, 10) : undefined,
-    },
   })
-  size!: BN;
+  size!: number;
 
-  @NumericField({
+  @IntField({
     nullable: true,
     description: `Storage provider id of the liaison`,
-
-    transformer: {
-      to: (entityValue: BN) => (entityValue !== undefined ? entityValue.toString(10) : null),
-      from: (dbValue: string) =>
-        dbValue !== undefined && dbValue !== null && dbValue.length > 0 ? new BN(dbValue, 10) : undefined,
-    },
   })
-  liaisonId?: BN;
+  liaisonId?: number;
 
   @EnumField('LiaisonJudgement', LiaisonJudgement, {
     description: `Storage provider as liaison judgment`,

+ 3 - 11
query-node/generated/graphql-server/src/modules/membership/membership.model.ts

@@ -1,6 +1,4 @@
-import { BaseModel, IntField, NumericField, Model, OneToMany, EnumField, StringField } from 'warthog';
-
-import BN from 'bn.js';
+import { BaseModel, IntField, Model, OneToMany, EnumField, StringField } from 'warthog';
 
 import { Channel } from '../channel/channel.model';
 
@@ -47,17 +45,11 @@ export class Membership extends BaseModel {
   })
   entry!: MembershipEntryMethod;
 
-  @NumericField({
+  @IntField({
     nullable: true,
     description: `The type of subscription the member has purchased if any.`,
-
-    transformer: {
-      to: (entityValue: BN) => (entityValue !== undefined ? entityValue.toString(10) : null),
-      from: (dbValue: string) =>
-        dbValue !== undefined && dbValue !== null && dbValue.length > 0 ? new BN(dbValue, 10) : undefined,
-    },
   })
-  subscription?: BN;
+  subscription?: number;
 
   @OneToMany(() => Channel, (param: Channel) => param.ownerMember, { cascade: ["insert", "update"] })
   channels?: Channel[];

+ 6 - 8
query-node/generated/graphql-server/src/modules/variants/variants.model.ts

@@ -11,18 +11,16 @@ import {
   StringField,
 } from 'warthog';
 
-import BN from 'bn.js';
-
 import { ObjectType, Field, createUnionType } from 'type-graphql';
 
 @ObjectType()
 export class DataObjectOwnerChannel {
   public isTypeOf: string = 'DataObjectOwnerChannel';
 
-  @NumericField({
+  @IntField({
     description: `Channel identifier`,
   })
-  channel!: BN;
+  channel!: number;
 
   @IntField({
     nullable: true,
@@ -44,19 +42,19 @@ export class DataObjectOwnerCouncil {
 export class DataObjectOwnerDao {
   public isTypeOf: string = 'DataObjectOwnerDao';
 
-  @NumericField({
+  @IntField({
     description: `DAO identifier`,
   })
-  dao!: BN;
+  dao!: number;
 }
 @ObjectType()
 export class DataObjectOwnerMember {
   public isTypeOf: string = 'DataObjectOwnerMember';
 
-  @NumericField({
+  @IntField({
     description: `Member identifier`,
   })
-  member!: BN;
+  member!: number;
 
   @IntField({
     nullable: true,

+ 3 - 11
query-node/generated/graphql-server/src/modules/video-media-metadata/video-media-metadata.model.ts

@@ -1,6 +1,4 @@
-import { BaseModel, IntField, NumericField, Model, ManyToOne, OneToOne, OneToOneJoin, StringField } from 'warthog';
-
-import BN from 'bn.js';
+import { BaseModel, IntField, Model, ManyToOne, OneToOne, OneToOneJoin, StringField } from 'warthog';
 
 import { VideoMediaEncoding } from '../video-media-encoding/video-media-encoding.model';
 import { Video } from '../video/video.model';
@@ -26,17 +24,11 @@ export class VideoMediaMetadata extends BaseModel {
   })
   pixelHeight?: number;
 
-  @NumericField({
+  @IntField({
     nullable: true,
     description: `Video media size in bytes`,
-
-    transformer: {
-      to: (entityValue: BN) => (entityValue !== undefined ? entityValue.toString(10) : null),
-      from: (dbValue: string) =>
-        dbValue !== undefined && dbValue !== null && dbValue.length > 0 ? new BN(dbValue, 10) : undefined,
-    },
   })
-  size?: BN;
+  size?: number;
 
   @OneToOne(() => Video, (param: Video) => param.mediaMetadata, { nullable: true, cascade: ["insert", "update"] })
   video?: Video;

+ 1 - 2
query-node/mappings/src/common.ts

@@ -1,4 +1,3 @@
-import BN from 'bn.js'
 import { SubstrateEvent } from '@dzlzv/hydra-common'
 import { DatabaseManager } from '@dzlzv/hydra-db-utils'
 import { u64 } from '@polkadot/types/primitive';
@@ -42,7 +41,7 @@ export async function prepareDataObject(
     createdInBlock: blockNumber,
     typeId: contentParameters.type_id.toNumber(),
     // `size` is masked by `size` special name in `Struct` so there needs to be `.get('size') as unknown as u64` to retrieve proper value
-    size: (contentParameters.get('size') as unknown as u64).toBn(),
+    size: (contentParameters.get('size') as unknown as u64).toNumber(),
     liaisonJudgement: LiaisonJudgement.PENDING, // judgement is pending at start; liaison id is set when content is accepted/rejected
     ipfsContentId: contentParameters.ipfs_content_id.toHex(),
     joystreamContentId: contentParameters.content_id.toHex(),

+ 3 - 3
query-node/mappings/src/content/channel.ts

@@ -26,7 +26,7 @@ import {
 import {
   AssetAvailability,
 } from 'query-node'
-import BN from 'bn.js'
+
 // eslint-disable-next-line @typescript-eslint/naming-convention
 export async function content_ChannelCreated(db: DatabaseManager, event: SubstrateEvent): Promise<void> {
   // read event data
@@ -40,7 +40,7 @@ export async function content_ChannelCreated(db: DatabaseManager, event: Substra
       db,
       blockNumber: event.blockNumber,
       assets: channelCreationParameters.assets,
-      contentOwner: convertContentActorToOwner(contentActor, channelId.toBn()),
+      contentOwner: convertContentActorToOwner(contentActor, channelId.toNumber()),
     }
   )
 
@@ -105,7 +105,7 @@ export async function content_ChannelUpdated(
         db,
         blockNumber: event.blockNumber,
         assets: channelUpdateParameters.assets.unwrapOr([]),
-        contentOwner: convertContentActorToOwner(contentActor, channelId.toBn()),
+        contentOwner: convertContentActorToOwner(contentActor, channelId.toNumber()),
       }
     )
 

+ 2 - 2
query-node/mappings/src/content/curatorGroup.ts

@@ -81,7 +81,7 @@ export async function content_CuratorAdded(
   }
 
   // update curator group
-  curatorGroup.curatorIds.push(curatorId)
+  curatorGroup.curatorIds.push(curatorId.toNumber())
 
   // set last update time
   curatorGroup.updatedAt = new Date(fixBlockTimestamp(event.blockTimestamp).toNumber())
@@ -108,7 +108,7 @@ export async function content_CuratorRemoved(
     return inconsistentState('Non-existing curator group removal requested', curatorGroupId)
   }
 
-  const curatorIndex = curatorGroup.curatorIds.indexOf(curatorId)
+  const curatorIndex = curatorGroup.curatorIds.indexOf(curatorId.toNumber())
 
   // ensure curator group exists
   if (curatorIndex < 0) {

+ 6 - 6
query-node/mappings/src/content/utils.ts

@@ -10,7 +10,6 @@ import { SubstrateEvent } from '@dzlzv/hydra-common'
 import { DatabaseManager } from '@dzlzv/hydra-db-utils'
 import { Bytes } from '@polkadot/types'
 import ISO6391 from 'iso-639-1';
-import BN from 'bn.js'
 import { u64 } from '@polkadot/types/primitive';
 import { FindConditions } from 'typeorm'
 
@@ -247,9 +246,9 @@ export async function readProtobufWithAssets<T extends Channel | Video>(
   throw `Not implemented metadata type`
 }
 
-export function convertContentActorToOwner(contentActor: ContentActor, channelId: BN): typeof DataObjectOwner {
+export function convertContentActorToOwner(contentActor: ContentActor, channelId: number): typeof DataObjectOwner {
   const owner = new DataObjectOwnerChannel()
-  //owner.channel = channelId // TODO: make this work; it causes error `TypeError, message: attempted to use private field on non-instance`
+  owner.channel = channelId
 
   return owner
 
@@ -373,7 +372,7 @@ function integrateAsset<T>(propertyName: string, result: Object, asset: AssetSto
   result[nameDataObject] = asset
 }
 
-async function extractVideoSize(assets: NewAsset[], assetIndex: number | undefined): Promise<BN | undefined> {
+async function extractVideoSize(assets: NewAsset[], assetIndex: number | undefined): Promise<number | undefined> {
   // escape if no asset is required
   if (assetIndex === undefined) {
     return undefined
@@ -396,7 +395,8 @@ async function extractVideoSize(assets: NewAsset[], assetIndex: number | undefin
   // extract video size
   const contentParameters: ContentParameters = rawAsset.asUpload
   // `size` is masked by `size` special name in struct that's why there needs to be `.get('size') as u64`
-  const videoSize = (contentParameters.get('size') as unknown as u64).toBn()
+  const videoSize = (contentParameters.get('size') as unknown as u64).toNumber()
+
 
   return videoSize
 }
@@ -449,7 +449,7 @@ async function prepareLicense(licenseProtobuf: LicenseMetadata.AsObject): Promis
   return license
 }
 
-async function prepareVideoMetadata(videoProtobuf: VideoMetadata.AsObject, videoSize: BN | undefined): Promise<VideoMediaMetadata> {
+async function prepareVideoMetadata(videoProtobuf: VideoMetadata.AsObject, videoSize: number | undefined): Promise<VideoMediaMetadata> {
   // create new encoding info
   const encoding = new VideoMediaEncoding(videoProtobuf.mediaType)
 

+ 3 - 3
query-node/mappings/src/content/video.ts

@@ -1,7 +1,7 @@
+import BN from 'bn.js'
 import { fixBlockTimestamp } from '../eventFix'
 import { SubstrateEvent } from '@dzlzv/hydra-common'
 import { DatabaseManager } from '@dzlzv/hydra-db-utils'
-import BN from 'bn.js'
 import { FindConditions, In } from 'typeorm'
 
 import {
@@ -170,7 +170,7 @@ export async function content_VideoCreated(
       db,
       blockNumber: event.blockNumber,
       assets: videoCreationParameters.assets,
-      contentOwner: convertContentActorToOwner(contentActor, channelId.toBn()),
+      contentOwner: convertContentActorToOwner(contentActor, channelId.toNumber()),
     }
   )
 
@@ -244,7 +244,7 @@ export async function content_VideoUpdated(
         db,
         blockNumber: event.blockNumber,
         assets: videoUpdateParameters.assets.unwrapOr([]),
-        contentOwner: convertContentActorToOwner(contentActor, new BN(video.channel.id)),
+        contentOwner: convertContentActorToOwner(contentActor, (new BN(video.channel.id)).toNumber()),
       }
     )
 

+ 4 - 4
query-node/mappings/src/storage.ts

@@ -79,7 +79,7 @@ export async function data_directory_ContentAccepted(db: DatabaseManager, event:
   }
 
   // update object
-  dataObject.liaisonId = storageProviderId
+  dataObject.liaisonId = storageProviderId.toNumber()
   dataObject.liaisonJudgement = LiaisonJudgement.ACCEPTED
 
   // set last update time
@@ -97,21 +97,21 @@ export async function data_directory_ContentAccepted(db: DatabaseManager, event:
 function convertStorageObjectOwner(objectOwner: StorageObjectOwner): typeof DataObjectOwner {
   if (objectOwner.isMember) {
     const owner = new DataObjectOwnerMember()
-    owner.member = objectOwner.asMember.toBn()
+    owner.member = objectOwner.asMember.toNumber()
 
     return owner
   }
 
   if (objectOwner.isChannel) {
     const owner = new DataObjectOwnerChannel()
-    owner.channel = objectOwner.asChannel.toBn()
+    owner.channel = objectOwner.asChannel.toNumber()
 
     return owner
   }
 
   if (objectOwner.isDao) {
     const owner = new DataObjectOwnerDao()
-    owner.dao = objectOwner.asDao.toBn()
+    owner.dao = objectOwner.asDao.toNumber()
 
     return owner
   }

+ 10 - 10
query-node/schema.graphql

@@ -37,7 +37,7 @@ type Membership @entity {
   entry: MembershipEntryMethod!
 
   "The type of subscription the member has purchased if any."
-  subscription: BigInt
+  subscription: Int
 
   channels: [Channel!]! @derivedFrom(field: "ownerMember")
 }
@@ -87,10 +87,10 @@ type DataObject @entity {
   typeId: Int!
 
   "Content size in bytes"
-  size: BigInt!
+  size: Int!
 
   "Storage provider id of the liaison"
-  liaisonId: BigInt # liaison is unset until storage provider accepts or rejects the content
+  liaisonId: Int # liaison is unset until storage provider accepts or rejects the content
 
   "Storage provider as liaison judgment"
   liaisonJudgement: LiaisonJudgement!
@@ -111,12 +111,12 @@ union DataObjectOwner = DataObjectOwnerMember
 
 "Asset owned by a member"
 type DataObjectOwnerMember @variant {
-  # use `BigInt` instead of `Membership` before variant relations are featured in Hydra
+  # use `Int` instead of `Membership` before variant relations are featured in Hydra
   # TODO: setup proper relations
   #"Member identifier"
   #memberId: Membership!
   "Member identifier"
-  member: BigInt # TODO: make this mandatory again (see DataObject mapping for more info)
+  member: Int!
 
   "Variant needs to have at least one property. This value is not used."
   dummy: Int
@@ -124,11 +124,11 @@ type DataObjectOwnerMember @variant {
 
 "Asset owned by a channel"
 type DataObjectOwnerChannel @variant {
-  # use `BigInt` instead of `Channel` before variant relations are featured in Hydra
+  # use `Int` instead of `Channel` before variant relations are featured in Hydra
   #"Channel identifier"
   #channel: Channel!
   "Channel identifier"
-  channel: BigInt!
+  channel: Int!
 
   "Variant needs to have at least one property. This value is not used."
   dummy: Int
@@ -137,7 +137,7 @@ type DataObjectOwnerChannel @variant {
 "Asset owned by a DAO"
 type DataObjectOwnerDao @variant {
   "DAO identifier"
-  dao: BigInt!
+  dao: Int!
 }
 
 "Asset owned by the Council"
@@ -232,7 +232,7 @@ type CuratorGroup @entity {
   id: ID!
 
   "Curators belonging to this group"
-  curatorIds: [BigInt!]!
+  curatorIds: [Int!]!
 
   "Is group active or not"
   isActive: Boolean!
@@ -347,7 +347,7 @@ type VideoMediaMetadata @entity {
   pixelHeight: Int
 
   "Video media size in bytes"
-  size: BigInt
+  size: Int
 
   video: Video @derivedFrom(field: "mediaMetadata")