|
@@ -1,6 +1,8 @@
|
|
import { Enum, Struct, Option, Vec as Vector, H256 } from '@polkadot/types';
|
|
import { Enum, Struct, Option, Vec as Vector, H256 } from '@polkadot/types';
|
|
-import { getTypeRegistry, u32, u64, bool, Text, GenericAccountId } from '@polkadot/types';
|
|
|
|
-import { BlockNumber, Moment, AccountId } from '@polkadot/types/interfaces';
|
|
|
|
|
|
+import { getTypeRegistry, u64, bool, Text } from '@polkadot/types';
|
|
|
|
+import { BlockAndTime } from './common';
|
|
|
|
+import { MemberId } from './members';
|
|
|
|
+import { StorageProviderId } from './bureaucracy'; // this should be in discovery really
|
|
|
|
|
|
import { randomAsU8a } from '@polkadot/util-crypto';
|
|
import { randomAsU8a } from '@polkadot/util-crypto';
|
|
import { encodeAddress, decodeAddress } from '@polkadot/keyring';
|
|
import { encodeAddress, decodeAddress } from '@polkadot/keyring';
|
|
@@ -28,52 +30,9 @@ export class ContentId extends H256 {
|
|
|
|
|
|
export class DataObjectTypeId extends u64 {}
|
|
export class DataObjectTypeId extends u64 {}
|
|
export class DataObjectStorageRelationshipId extends u64 {}
|
|
export class DataObjectStorageRelationshipId extends u64 {}
|
|
-export class SchemaId extends u64 {}
|
|
|
|
-export class DownloadSessionId extends u64 {}
|
|
|
|
-
|
|
|
|
-export type BlockAndTimeType = {
|
|
|
|
- block: BlockNumber,
|
|
|
|
- time: Moment
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-export class BlockAndTime extends Struct {
|
|
|
|
- constructor (value?: BlockAndTimeType) {
|
|
|
|
- super({
|
|
|
|
- block: u32, // BlockNumber
|
|
|
|
- time: u64, // Moment
|
|
|
|
- }, value);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- get block (): BlockNumber {
|
|
|
|
- return this.get('block') as BlockNumber;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- get time (): Moment {
|
|
|
|
- return this.get('time') as Moment;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- static newEmpty (): BlockAndTime {
|
|
|
|
- return new BlockAndTime({} as BlockAndTime);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// TODO rename to Draft to Unlisted
|
|
|
|
-export type ContentVisibilityKey = 'Draft' | 'Public';
|
|
|
|
-
|
|
|
|
-export class ContentVisibility extends Enum {
|
|
|
|
- constructor (value?: ContentVisibilityKey) {
|
|
|
|
- super([
|
|
|
|
- 'Draft',
|
|
|
|
- 'Public'
|
|
|
|
- ], value);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
|
|
export class VecContentId extends Vector.with(ContentId) {}
|
|
export class VecContentId extends Vector.with(ContentId) {}
|
|
-
|
|
|
|
export class OptionVecContentId extends Option.with(VecContentId) {}
|
|
export class OptionVecContentId extends Option.with(VecContentId) {}
|
|
-export class OptionSchemaId extends Option.with(SchemaId) {}
|
|
|
|
-export class OptionContentVisibility extends Option.with(ContentVisibility) {}
|
|
|
|
export type LiaisonJudgementKey = 'Pending' | 'Accepted' | 'Rejected';
|
|
export type LiaisonJudgementKey = 'Pending' | 'Accepted' | 'Rejected';
|
|
|
|
|
|
export class LiaisonJudgement extends Enum {
|
|
export class LiaisonJudgement extends Enum {
|
|
@@ -89,18 +48,18 @@ export class LiaisonJudgement extends Enum {
|
|
export class DataObject extends Struct {
|
|
export class DataObject extends Struct {
|
|
constructor (value?: any) {
|
|
constructor (value?: any) {
|
|
super({
|
|
super({
|
|
- owner: GenericAccountId,
|
|
|
|
|
|
+ owner: MemberId,
|
|
added_at: BlockAndTime,
|
|
added_at: BlockAndTime,
|
|
type_id: DataObjectTypeId,
|
|
type_id: DataObjectTypeId,
|
|
size: u64,
|
|
size: u64,
|
|
- liaison: GenericAccountId,
|
|
|
|
|
|
+ liaison: StorageProviderId,
|
|
liaison_judgement: LiaisonJudgement,
|
|
liaison_judgement: LiaisonJudgement,
|
|
ipfs_content_id: Text,
|
|
ipfs_content_id: Text,
|
|
}, value);
|
|
}, value);
|
|
}
|
|
}
|
|
|
|
|
|
- get owner (): AccountId {
|
|
|
|
- return this.get('owner') as AccountId;
|
|
|
|
|
|
+ get owner (): MemberId {
|
|
|
|
+ return this.get('owner') as MemberId;
|
|
}
|
|
}
|
|
|
|
|
|
get added_at (): BlockAndTime {
|
|
get added_at (): BlockAndTime {
|
|
@@ -116,8 +75,8 @@ export class DataObject extends Struct {
|
|
return this.get('size') as u64;
|
|
return this.get('size') as u64;
|
|
}
|
|
}
|
|
|
|
|
|
- get liaison (): AccountId {
|
|
|
|
- return this.get('liaison') as AccountId;
|
|
|
|
|
|
+ get liaison (): StorageProviderId {
|
|
|
|
+ return this.get('liaison') as StorageProviderId;
|
|
}
|
|
}
|
|
|
|
|
|
get liaison_judgement (): LiaisonJudgement {
|
|
get liaison_judgement (): LiaisonJudgement {
|
|
@@ -133,7 +92,7 @@ export class DataObjectStorageRelationship extends Struct {
|
|
constructor (value?: any) {
|
|
constructor (value?: any) {
|
|
super({
|
|
super({
|
|
content_id: ContentId,
|
|
content_id: ContentId,
|
|
- storage_provider: GenericAccountId,
|
|
|
|
|
|
+ storage_provider: StorageProviderId,
|
|
ready: bool
|
|
ready: bool
|
|
}, value);
|
|
}, value);
|
|
}
|
|
}
|
|
@@ -142,8 +101,8 @@ export class DataObjectStorageRelationship extends Struct {
|
|
return this.get('content_id') as ContentId;
|
|
return this.get('content_id') as ContentId;
|
|
}
|
|
}
|
|
|
|
|
|
- get storage_provider (): AccountId {
|
|
|
|
- return this.get('storage_provider') as AccountId;
|
|
|
|
|
|
+ get storage_provider (): StorageProviderId {
|
|
|
|
+ return this.get('storage_provider') as StorageProviderId;
|
|
}
|
|
}
|
|
|
|
|
|
get ready (): bool {
|
|
get ready (): bool {
|
|
@@ -168,76 +127,18 @@ export class DataObjectType extends Struct {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-export type DownloadStateKey = 'Started' | 'Ended';
|
|
|
|
-
|
|
|
|
-export class DownloadState extends Enum {
|
|
|
|
- constructor (value?: DownloadStateKey) {
|
|
|
|
- super([
|
|
|
|
- 'Started',
|
|
|
|
- 'Ended'
|
|
|
|
- ], value);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export class DownloadSession extends Struct {
|
|
|
|
- constructor (value?: any) {
|
|
|
|
- super({
|
|
|
|
- content_id: ContentId,
|
|
|
|
- consumer: GenericAccountId,
|
|
|
|
- distributor: GenericAccountId,
|
|
|
|
- initiated_at_block: u32, // BlockNumber,
|
|
|
|
- initiated_at_time: u64, // Moment
|
|
|
|
- state: DownloadState,
|
|
|
|
- transmitted_bytes: u64
|
|
|
|
- }, value);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- get content_id (): ContentId {
|
|
|
|
- return this.get('content_id') as ContentId;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- get consumer (): AccountId {
|
|
|
|
- return this.get('consumer') as AccountId;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- get distributor (): AccountId {
|
|
|
|
- return this.get('distributor') as AccountId;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- get initiated_at_block (): BlockNumber {
|
|
|
|
- return this.get('initiated_at_block') as BlockNumber;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- get initiated_at_time (): Moment {
|
|
|
|
- return this.get('initiated_at_time') as Moment;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- get state (): DownloadState {
|
|
|
|
- return this.get('state') as DownloadState;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- get transmitted_bytes (): u64 {
|
|
|
|
- return this.get('transmitted_bytes') as u64;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
export function registerMediaTypes () {
|
|
export function registerMediaTypes () {
|
|
try {
|
|
try {
|
|
getTypeRegistry().register({
|
|
getTypeRegistry().register({
|
|
'::ContentId': ContentId,
|
|
'::ContentId': ContentId,
|
|
'::DataObjectTypeId': DataObjectTypeId,
|
|
'::DataObjectTypeId': DataObjectTypeId,
|
|
- // SchemaId, // This isn't required? (its what caused issue with type mismatch in permissions module!)
|
|
|
|
ContentId,
|
|
ContentId,
|
|
- ContentVisibility,
|
|
|
|
LiaisonJudgement,
|
|
LiaisonJudgement,
|
|
DataObject,
|
|
DataObject,
|
|
DataObjectStorageRelationshipId,
|
|
DataObjectStorageRelationshipId,
|
|
DataObjectStorageRelationship,
|
|
DataObjectStorageRelationship,
|
|
DataObjectTypeId,
|
|
DataObjectTypeId,
|
|
DataObjectType,
|
|
DataObjectType,
|
|
- DownloadState,
|
|
|
|
- DownloadSessionId,
|
|
|
|
- DownloadSession
|
|
|
|
});
|
|
});
|
|
} catch (err) {
|
|
} catch (err) {
|
|
console.error('Failed to register custom types of media module', err);
|
|
console.error('Failed to register custom types of media module', err);
|