From 8b1a7a858433678acd5281ff6f0eb3bc3271a0a5 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 22 Nov 2019 13:38:20 +0100 Subject: [PATCH] Move Metadata to interfaces (#1598) * Move Metadata to interfaces * Align imports * Suppress errors * Remove TS overrides, createTypeUnsafe returns Codec * Add type unwrap * Fixup doc generation * Remove V8 references --- .../storage/fromMetadata/createFunction.ts | 8 +- .../Decorated/storage/fromMetadata/index.ts | 2 +- .../storage/fromMetadata/substrate.ts | 6 +- .../src/Metadata/MetadataVersioned.ts | 25 +- .../metadata/src/Metadata/util/testUtil.ts | 4 +- .../metadata/src/Metadata/util/toCallsOnly.ts | 9 +- packages/metadata/src/Metadata/v1/toV2.ts | 6 +- packages/metadata/src/Metadata/v2/Metadata.ts | 86 ----- packages/metadata/src/Metadata/v2/Storage.ts | 115 ------- packages/metadata/src/Metadata/v2/index.ts | 11 - packages/metadata/src/Metadata/v2/toV3.ts | 6 +- packages/metadata/src/Metadata/v3/Metadata.ts | 86 ----- packages/metadata/src/Metadata/v3/Storage.ts | 132 -------- packages/metadata/src/Metadata/v3/index.ts | 11 - packages/metadata/src/Metadata/v3/toV4.ts | 23 +- packages/metadata/src/Metadata/v4/Metadata.ts | 85 ----- packages/metadata/src/Metadata/v4/Storage.ts | 132 -------- packages/metadata/src/Metadata/v4/index.ts | 11 - packages/metadata/src/Metadata/v4/toV5.ts | 22 +- packages/metadata/src/Metadata/v5/Metadata.ts | 85 ----- packages/metadata/src/Metadata/v5/Storage.ts | 132 -------- packages/metadata/src/Metadata/v5/index.ts | 11 - packages/metadata/src/Metadata/v5/toV6.ts | 9 +- packages/metadata/src/Metadata/v6/Metadata.ts | 93 ------ packages/metadata/src/Metadata/v6/Storage.ts | 12 - packages/metadata/src/Metadata/v6/index.ts | 11 - packages/metadata/src/Metadata/v6/toV7.ts | 12 +- packages/metadata/src/Metadata/v7/Metadata.ts | 85 ----- packages/metadata/src/Metadata/v7/Storage.ts | 41 --- packages/metadata/src/Metadata/v7/index.ts | 11 - packages/metadata/src/Metadata/v7/toV8.ts | 9 +- packages/metadata/src/Metadata/v8/Metadata.ts | 109 ------- packages/metadata/src/Metadata/v8/Storage.ts | 5 - packages/metadata/src/Metadata/v8/index.ts | 11 - packages/types/src/codec/create/createType.ts | 6 +- packages/types/src/interfaceRegistry.ts | 104 +++++- .../src/interfaces/metadata/definitions.ts | 144 ++++++++- .../types/src/interfaces/metadata/types.ts | 301 ++++++++++++++++++ packages/types/src/primitive/StorageKey.ts | 10 +- packages/types/src/scripts/MetadataMd.ts | 41 ++- .../types/src/scripts/generateTypes/consts.ts | 5 +- .../types/src/scripts/generateTypes/query.ts | 13 +- 42 files changed, 644 insertions(+), 1396 deletions(-) delete mode 100644 packages/metadata/src/Metadata/v2/Metadata.ts delete mode 100644 packages/metadata/src/Metadata/v2/Storage.ts delete mode 100644 packages/metadata/src/Metadata/v2/index.ts delete mode 100644 packages/metadata/src/Metadata/v3/Metadata.ts delete mode 100644 packages/metadata/src/Metadata/v3/Storage.ts delete mode 100644 packages/metadata/src/Metadata/v3/index.ts delete mode 100644 packages/metadata/src/Metadata/v4/Metadata.ts delete mode 100644 packages/metadata/src/Metadata/v4/Storage.ts delete mode 100644 packages/metadata/src/Metadata/v4/index.ts delete mode 100644 packages/metadata/src/Metadata/v5/Metadata.ts delete mode 100644 packages/metadata/src/Metadata/v5/Storage.ts delete mode 100644 packages/metadata/src/Metadata/v5/index.ts delete mode 100644 packages/metadata/src/Metadata/v6/Metadata.ts delete mode 100644 packages/metadata/src/Metadata/v6/Storage.ts delete mode 100644 packages/metadata/src/Metadata/v6/index.ts delete mode 100644 packages/metadata/src/Metadata/v7/Metadata.ts delete mode 100644 packages/metadata/src/Metadata/v7/Storage.ts delete mode 100644 packages/metadata/src/Metadata/v7/index.ts delete mode 100644 packages/metadata/src/Metadata/v8/Metadata.ts delete mode 100644 packages/metadata/src/Metadata/v8/Storage.ts delete mode 100644 packages/metadata/src/Metadata/v8/index.ts diff --git a/packages/metadata/src/Decorated/storage/fromMetadata/createFunction.ts b/packages/metadata/src/Decorated/storage/fromMetadata/createFunction.ts index 9f8241408e..c73f1553a1 100644 --- a/packages/metadata/src/Decorated/storage/fromMetadata/createFunction.ts +++ b/packages/metadata/src/Decorated/storage/fromMetadata/createFunction.ts @@ -2,6 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata'; import { Codec, Registry } from '@polkadot/types/types'; import BN from 'bn.js'; @@ -9,7 +10,6 @@ import { Compact, U8a, createType, createTypeUnsafe } from '@polkadot/types/code import { StorageEntry } from '@polkadot/types/primitive/StorageKey'; import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util'; -import { StorageEntryMetadata, StorageEntryType } from '../../../Metadata/v8/Storage'; import getHasher, { HasherFunction } from './getHasher'; export interface CreateItemOptions { @@ -18,7 +18,7 @@ export interface CreateItemOptions { } export interface CreateItemFn { - meta: StorageEntryMetadata; + meta: StorageEntryMetadataLatest; method: string; prefix: string; section: string; @@ -118,10 +118,10 @@ function extendLinkedMap (registry: Registry, { meta: { documentation, name, typ // metadata with a fallback value using the type of the key, the normal // meta fallback only applies to actual entry values, create one for head - headFn.meta = new StorageEntryMetadata(registry, { + headFn.meta = createType(registry, 'StorageEntryMetadataLatest', { name, modifier: createType(registry, 'StorageEntryModifierLatest', 1), // required - type: new StorageEntryType(registry, createType(registry, 'PlainTypeLatest', type.asMap.key), 0), + type: createType(registry, 'StorageEntryTypeLatest', createType(registry, 'PlainTypeLatest', type.asMap.key), 0), fallback: createType(registry, 'Bytes', createTypeUnsafe(registry, type.asMap.key.toString()).toHex()), documentation }); diff --git a/packages/metadata/src/Decorated/storage/fromMetadata/index.ts b/packages/metadata/src/Decorated/storage/fromMetadata/index.ts index 8bf5ba8b31..fddf8e20d5 100644 --- a/packages/metadata/src/Decorated/storage/fromMetadata/index.ts +++ b/packages/metadata/src/Decorated/storage/fromMetadata/index.ts @@ -31,7 +31,7 @@ export default function fromMetadata (registry: Registry, metadata: Metadata): S result[section] = unwrapped.items.reduce((newModule, meta): ModuleStorage => { const method = meta.name.toString(); - newModule[stringLowerFirst(method)] = createFunction(metadata.registry, { + newModule[stringLowerFirst(method)] = createFunction(registry, { meta, method, prefix, diff --git a/packages/metadata/src/Decorated/storage/fromMetadata/substrate.ts b/packages/metadata/src/Decorated/storage/fromMetadata/substrate.ts index cb4fba66c6..0de2d88bff 100644 --- a/packages/metadata/src/Decorated/storage/fromMetadata/substrate.ts +++ b/packages/metadata/src/Decorated/storage/fromMetadata/substrate.ts @@ -2,11 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; import { StorageEntry } from '@polkadot/types/primitive/StorageKey'; import { createType } from '@polkadot/types/codec'; -import { StorageEntryMetadata, StorageEntryType } from '../../../Metadata/v8/Storage'; import createFunction from './createFunction'; @@ -22,9 +22,9 @@ function createRuntimeFunction (method: string, key: string, { documentation, ty meta: { documentation: createType(registry, 'Vec', [documentation]), modifier: createType(registry, 'StorageEntryModifierLatest', 1), // required - type: new StorageEntryType(registry, type, 0), + type: createType(registry, 'StorageEntryTypeLatest', type, 0), toJSON: (): any => key - } as unknown as StorageEntryMetadata, + } as unknown as StorageEntryMetadataLatest, method, prefix: 'Substrate', section: 'substrate' diff --git a/packages/metadata/src/Metadata/MetadataVersioned.ts b/packages/metadata/src/Metadata/MetadataVersioned.ts index 91bc5a578e..aa2b3cddd7 100644 --- a/packages/metadata/src/Metadata/MetadataVersioned.ts +++ b/packages/metadata/src/Metadata/MetadataVersioned.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { MetadataV0, MetadataV1 } from '@polkadot/types/interfaces/metadata'; +import { MetadataLatest, MetadataV0, MetadataV1, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8 } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; import { assert } from '@polkadot/util'; @@ -11,13 +11,6 @@ import Enum from '@polkadot/types/codec/Enum'; import Struct from '@polkadot/types/codec/Struct'; import MagicNumber from './MagicNumber'; -import MetadataV2 from './v2'; -import MetadataV3 from './v3'; -import MetadataV4 from './v4'; -import MetadataV5 from './v5'; -import MetadataV6 from './v6'; -import MetadataV7 from './v7'; -import MetadataV8 from './v8'; import v0ToV1 from './v0/toV1'; import v1ToV2 from './v1/toV2'; import v2ToV3 from './v2/toV3'; @@ -37,13 +30,13 @@ class MetadataEnum extends Enum { super(registry, { V0: 'MetadataV0', // once rolled-out, can replace this with MetadataDeprecated V1: 'MetadataV1', // once rolled-out, can replace this with MetadataDeprecated - V2: MetadataV2, // once rolled-out, can replace this with MetadataDeprecated - V3: MetadataV3, // once rolled-out, can replace this with MetadataDeprecated - V4: MetadataV4, // once rolled-out, can replace this with MetadataDeprecated - V5: MetadataV5, // once rolled-out, can replace this with MetadataDeprecated - V6: MetadataV6, // once rolled-out, can replace this with MetadataDeprecated - V7: MetadataV7, // once rolled-out, can replace this with MetadataDeprecated - V8: MetadataV8 + V2: 'MetadataV2', // once rolled-out, can replace this with MetadataDeprecated + V3: 'MetadataV3', // once rolled-out, can replace this with MetadataDeprecated + V4: 'MetadataV4', // once rolled-out, can replace this with MetadataDeprecated + V5: 'MetadataV5', // once rolled-out, can replace this with MetadataDeprecated + V6: 'MetadataV6', // once rolled-out, can replace this with MetadataDeprecated + V7: 'MetadataV7', // once rolled-out, can replace this with MetadataDeprecated + V8: 'MetadataV8' }, value, index); } @@ -315,7 +308,7 @@ export default class MetadataVersioned extends Struct { /** * @description Returns the wrapped values as a latest version object */ - public get asLatest (): MetadataV8 { + public get asLatest (): MetadataLatest { return this.asV8; } diff --git a/packages/metadata/src/Metadata/util/testUtil.ts b/packages/metadata/src/Metadata/util/testUtil.ts index 33c1e32b00..62f81ef9e8 100644 --- a/packages/metadata/src/Metadata/util/testUtil.ts +++ b/packages/metadata/src/Metadata/util/testUtil.ts @@ -38,12 +38,12 @@ export function decodeLatestSubstrate (registry: Registry export function toLatest (registry: Registry, version: number, rpcData: string): void { it(`converts v${version} to v8`, (): void => { const metadata = new Metadata(registry, rpcData)[`asV${version}` as keyof Metadata]; - const metadataV8 = new Metadata(registry, rpcData).asLatest; + const metadataLatest = new Metadata(registry, rpcData).asLatest; expect( getUniqTypes(registry, metadata as unknown as MetadataInterface, true) ).toEqual( - getUniqTypes(registry, metadataV8, true) + getUniqTypes(registry, metadataLatest, true) ); }); } diff --git a/packages/metadata/src/Metadata/util/toCallsOnly.ts b/packages/metadata/src/Metadata/util/toCallsOnly.ts index f7f4bcdc4b..93c0b87e23 100644 --- a/packages/metadata/src/Metadata/util/toCallsOnly.ts +++ b/packages/metadata/src/Metadata/util/toCallsOnly.ts @@ -2,15 +2,16 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { MetadataLatest } from '@polkadot/types/interfaces/metadata'; import { AnyJsonObject, Registry } from '@polkadot/types/types'; -import MetadataV8 from '../v8'; +import { createType } from '@polkadot/types'; /** - * @description Convert from MetadataV8 to a stripped representation of MetadataV8 + * @description Convert from MetadataLatest to a stripped representation of MetadataLatest */ -export default function toCallsOnly (registry: Registry, { modules }: MetadataV8): AnyJsonObject | string { - return new MetadataV8(registry, { +export default function toCallsOnly (registry: Registry, { modules }: MetadataLatest): AnyJsonObject | string { + return createType(registry, 'MetadataLatest', { // FIXME, this needs typing, not any modules: modules.map(({ calls, name }): any => ({ name, diff --git a/packages/metadata/src/Metadata/v1/toV2.ts b/packages/metadata/src/Metadata/v1/toV2.ts index 0b2a6b9551..d7eceefc3f 100644 --- a/packages/metadata/src/Metadata/v1/toV2.ts +++ b/packages/metadata/src/Metadata/v1/toV2.ts @@ -2,11 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { MetadataV1 } from '@polkadot/types/interfaces/metadata'; +import { MetadataV1, MetadataV2 } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; -import MetadataV2 from '../v2'; +import { createType } from '@polkadot/types'; export default function toV2 (registry: Registry, metadataV1: MetadataV1): MetadataV2 { - return new MetadataV2(registry, metadataV1); + return createType(registry, 'MetadataV2', metadataV1); } diff --git a/packages/metadata/src/Metadata/v2/Metadata.ts b/packages/metadata/src/Metadata/v2/Metadata.ts deleted file mode 100644 index ab8a6a28e5..0000000000 --- a/packages/metadata/src/Metadata/v2/Metadata.ts +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { EventMetadataV2, FunctionMetadataV2 } from '@polkadot/types/interfaces/metadata'; -import { Registry } from '@polkadot/types/types'; -import { MetadataInterface } from '../types'; - -import Option from '@polkadot/types/codec/Option'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Text from '@polkadot/types/primitive/Text'; - -import { StorageFunctionMetadata } from './Storage'; - -/** - * @name ModuleMetadataV2 - * @description - * The definition of a module in the system - */ -export class ModuleMetadataV2 extends Struct { - constructor (registry: Registry, value?: any) { - super(registry, { - name: 'Text', - prefix: 'Text', - storage: Option.with(Vec.with(StorageFunctionMetadata)), - calls: Option.with('Vec'), - events: Option.with('Vec') - }, value); - } - - /** - * @description the module calls - */ - public get calls (): Option> { - return this.get('calls') as Option>; - } - - /** - * @description the module events - */ - public get events (): Option> { - return this.get('events') as Option>; - } - - /** - * @description the module name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description the module prefix - */ - public get prefix (): Text { - return this.get('prefix') as Text; - } - - /** - * @description the associated module storage - */ - public get storage (): Option> { - return this.get('storage') as Option>; - } -} - -/** - * @name MetadataV2 - * @description - * The runtime metadata as a decoded structure - */ -export default class MetadataV2 extends Struct implements MetadataInterface { - constructor (registry: Registry, value?: any) { - super(registry, { - modules: Vec.with(ModuleMetadataV2) - }, value); - } - - /** - * @description The associated modules for this structure - */ - public get modules (): Vec { - return this.get('modules') as Vec; - } -} diff --git a/packages/metadata/src/Metadata/v2/Storage.ts b/packages/metadata/src/Metadata/v2/Storage.ts deleted file mode 100644 index a9f0289046..0000000000 --- a/packages/metadata/src/Metadata/v2/Storage.ts +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { MapTypeV2, PlainTypeV2, StorageFunctionModifierV2 } from '@polkadot/types/interfaces/metadata'; -import { AnyNumber, Registry } from '@polkadot/types/types'; - -import { assert } from '@polkadot/util'; - -import Enum from '@polkadot/types/codec/Enum'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Bytes from '@polkadot/types/primitive/Bytes'; -import Text from '@polkadot/types/primitive/Text'; - -export class StorageFunctionType extends Enum { - constructor (registry: Registry, value?: any, index?: number) { - super(registry, { - Plain: 'PlainTypeV2', - Map: 'MapTypeV2' - }, value, index); - } - - /** - * @description The value as a mapped value - */ - public get asMap (): MapTypeV2 { - assert(this.isMap, `Cannot convert '${this.type}' via asMap`); - - return this.value as MapTypeV2; - } - - /** - * @description The value as a [[Type]] value - */ - public get asPlain (): PlainTypeV2 { - assert(this.isPlain, `Cannot convert '${this.type}' via asPlain`); - - return this.value as PlainTypeV2; - } - - /** - * @description `true` if the storage entry is a map - */ - public get isMap (): boolean { - return this.toNumber() === 1; - } - - /** - * @description `true` if the storage entry is a plain type - */ - public get isPlain (): boolean { - return this.toNumber() === 0; - } -} - -export interface StorageFunctionMetadataValue { - name: string | Text; - modifier: StorageFunctionModifierV2 | AnyNumber; - type: StorageFunctionType; - fallback: Bytes; - documentation: Vec | string[]; -} - -/** - * @name ModuleMetadata - * @description - * The definition of a storage function - */ -export class StorageFunctionMetadata extends Struct { - constructor (registry: Registry, value?: StorageFunctionMetadataValue | Uint8Array) { - super(registry, { - name: 'Text', - modifier: 'StorageFunctionModifierV2', - type: StorageFunctionType, - fallback: 'Bytes', - documentation: 'Vec' - }, value); - } - - /** - * @description The [[Text]] documentation - */ - public get documentation (): Vec { - return this.get('documentation') as Vec; - } - - /** - * @description The [[Bytes]] fallback default - */ - public get fallback (): Bytes { - return this.get('fallback') as Bytes; - } - - /** - * @description The [[StorageFunctionModifierV2]] for arguments - */ - public get modifier (): StorageFunctionModifierV2 { - return this.get('modifier') as StorageFunctionModifierV2; - } - - /** - * @description The call name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description The [[StorageFunctionType]] - */ - public get type (): StorageFunctionType { - return this.get('type') as StorageFunctionType; - } -} diff --git a/packages/metadata/src/Metadata/v2/index.ts b/packages/metadata/src/Metadata/v2/index.ts deleted file mode 100644 index fe6c567027..0000000000 --- a/packages/metadata/src/Metadata/v2/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import MetadataV2, { ModuleMetadataV2 } from './Metadata'; - -export default MetadataV2; - -export { - ModuleMetadataV2 -}; diff --git a/packages/metadata/src/Metadata/v2/toV3.ts b/packages/metadata/src/Metadata/v2/toV3.ts index d00b7f0701..30238ba81d 100644 --- a/packages/metadata/src/Metadata/v2/toV3.ts +++ b/packages/metadata/src/Metadata/v2/toV3.ts @@ -2,11 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { MetadataV2, MetadataV3 } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; -import MetadataV2 from './Metadata'; -import MetadataV3 from '../v3'; +import { createType } from '@polkadot/types'; export default function toV3 (registry: Registry, metadataV2: MetadataV2): MetadataV3 { - return new MetadataV3(registry, metadataV2); + return createType(registry, 'MetadataV3', metadataV2); } diff --git a/packages/metadata/src/Metadata/v3/Metadata.ts b/packages/metadata/src/Metadata/v3/Metadata.ts deleted file mode 100644 index ef5c3e7412..0000000000 --- a/packages/metadata/src/Metadata/v3/Metadata.ts +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { EventMetadataV3, FunctionMetadataV3 } from '@polkadot/types/interfaces/metadata'; -import { Registry } from '@polkadot/types/types'; -import { MetadataInterface } from '../types'; - -import Option from '@polkadot/types/codec/Option'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Text from '@polkadot/types/primitive/Text'; - -import { StorageFunctionMetadata } from './Storage'; - -/** - * @name ModuleMetadataV3 - * @description - * The definition of a module in the system - */ -export class ModuleMetadataV3 extends Struct { - constructor (registry: Registry, value?: any) { - super(registry, { - name: 'Text', - prefix: 'Text', - storage: Option.with(Vec.with(StorageFunctionMetadata)), - calls: Option.with('Vec'), - events: Option.with('Vec') - }, value); - } - - /** - * @description the module calls - */ - public get calls (): Option> { - return this.get('calls') as Option>; - } - - /** - * @description the module events - */ - public get events (): Option> { - return this.get('events') as Option>; - } - - /** - * @description the module name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description the module prefix - */ - public get prefix (): Text { - return this.get('prefix') as Text; - } - - /** - * @description the associated module storage - */ - public get storage (): Option> { - return this.get('storage') as Option>; - } -} - -/** - * @name MetadataV3 - * @description - * The runtime metadata as a decoded structure - */ -export default class MetadataV3 extends Struct implements MetadataInterface { - constructor (registry: Registry, value?: any) { - super(registry, { - modules: Vec.with(ModuleMetadataV3) - }, value); - } - - /** - * @description The associated modules for this structure - */ - public get modules (): Vec { - return this.get('modules') as Vec; - } -} diff --git a/packages/metadata/src/Metadata/v3/Storage.ts b/packages/metadata/src/Metadata/v3/Storage.ts deleted file mode 100644 index 039f870659..0000000000 --- a/packages/metadata/src/Metadata/v3/Storage.ts +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { DoubleMapTypeV3, MapTypeV3, PlainTypeV3, StorageFunctionModifierV3 } from '@polkadot/types/interfaces/metadata'; -import { AnyNumber, Registry } from '@polkadot/types/types'; - -import { assert } from '@polkadot/util'; - -import Enum from '@polkadot/types/codec/Enum'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Bytes from '@polkadot/types/primitive/Bytes'; -import Text from '@polkadot/types/primitive/Text'; - -export class StorageFunctionType extends Enum { - constructor (registry: Registry, value?: any, index?: number) { - super(registry, { - Plain: 'PlainTypeV3', - Map: 'MapTypeV3', - DoubleMap: 'DoubleMapTypeV3' - }, value, index); - } - - /** - * @description The value as a mapped value - */ - public get asDoubleMap (): DoubleMapTypeV3 { - assert(this.isDoubleMap, `Cannot convert '${this.type}' via asDoubleMap`); - - return this.value as DoubleMapTypeV3; - } - - /** - * @description The value as a mapped value - */ - public get asMap (): MapTypeV3 { - assert(this.isMap, `Cannot convert '${this.type}' via asMap`); - - return this.value as MapTypeV3; - } - - /** - * @description The value as a [[Type]] value - */ - public get asPlain (): PlainTypeV3 { - assert(this.isPlain, `Cannot convert '${this.type}' via asPlain`); - - return this.value as PlainTypeV3; - } - - /** - * @description `true` if the storage entry is a doublemap - */ - public get isDoubleMap (): boolean { - return this.toNumber() === 2; - } - - /** - * @description `true` if the storage entry is a map - */ - public get isMap (): boolean { - return this.toNumber() === 1; - } - - /** - * @description `true` if the storage entry is a plain type - */ - public get isPlain (): boolean { - return this.toNumber() === 0; - } -} - -export interface StorageFunctionMetadataValue { - name: string | Text; - modifier: StorageFunctionModifierV3 | AnyNumber; - type: StorageFunctionType; - fallback: Bytes; - documentation: Vec | string[]; -} - -/** - * @name StorageFunctionMetadata - * @description - * The definition of a storage function - */ -export class StorageFunctionMetadata extends Struct { - constructor (registry: Registry, value?: StorageFunctionMetadataValue | Uint8Array) { - super(registry, { - name: 'Text', - modifier: 'StorageFunctionModifierV3', - type: StorageFunctionType, - fallback: 'Bytes', - documentation: 'Vec' - }, value); - } - - /** - * @description The [[Text]] documentation - */ - public get documentation (): Vec { - return this.get('documentation') as Vec; - } - - /** - * @description The [[Bytes]] fallback default - */ - public get fallback (): Bytes { - return this.get('fallback') as Bytes; - } - - /** - * @description The [[StorageFunctionModifierV3]] for arguments - */ - public get modifier (): StorageFunctionModifierV3 { - return this.get('modifier') as StorageFunctionModifierV3; - } - - /** - * @description The call name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description The [[StorageFunctionType]] - */ - public get type (): StorageFunctionType { - return this.get('type') as StorageFunctionType; - } -} diff --git a/packages/metadata/src/Metadata/v3/index.ts b/packages/metadata/src/Metadata/v3/index.ts deleted file mode 100644 index 60a889cbf9..0000000000 --- a/packages/metadata/src/Metadata/v3/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import MetadataV3, { ModuleMetadataV3 } from './Metadata'; - -export default MetadataV3; - -export { - ModuleMetadataV3 -}; diff --git a/packages/metadata/src/Metadata/v3/toV4.ts b/packages/metadata/src/Metadata/v3/toV4.ts index 6eb8eb69ea..e6de89a6a7 100644 --- a/packages/metadata/src/Metadata/v3/toV4.ts +++ b/packages/metadata/src/Metadata/v3/toV4.ts @@ -2,21 +2,16 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { MetadataV3, MetadataV4, ModuleMetadataV4, StorageFunctionMetadataV3, StorageFunctionMetadataV4 } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; import StorageHasher from '@polkadot/types/primitive/StorageHasher'; -import { createType, Option, Vec } from '@polkadot/types/codec'; - -import MetadataV3 from './Metadata'; -import MetadataV4 from '../v4'; -import { ModuleMetadataV4 } from '../v4/Metadata'; -import { StorageFunctionMetadata, StorageFunctionType } from '../v4/Storage'; -import { StorageFunctionMetadata as StorageFunctionMetadataV3 } from './Storage'; +import { createType, Option } from '@polkadot/types/codec'; /** * Convert V3 StorageFunction to V4 StorageFunction */ -function toV4StorageFunction (registry: Registry, storageFn: StorageFunctionMetadataV3): StorageFunctionMetadata { +function toV4StorageFunction (registry: Registry, storageFn: StorageFunctionMetadataV3): StorageFunctionMetadataV4 { const { documentation, fallback, modifier, name, type } = storageFn; // Convert the old type to the new type: there is one new field @@ -39,12 +34,12 @@ function toV4StorageFunction (registry: Registry, storageFn: StorageFunctionMeta key2Hasher: type.asDoubleMap.key2Hasher }), 2]; - return new StorageFunctionMetadata(registry, { + return createType(registry, 'StorageFunctionMetadataV4', { documentation, fallback, name, modifier, - type: new StorageFunctionType(registry, newType, index) + type: createType(registry, 'StorageFunctionTypeV4', newType, index) }); } @@ -53,9 +48,9 @@ function toV4StorageFunction (registry: Registry, storageFn: StorageFunctionMeta * See https://github.com/paritytech/substrate/pull/2268 for details */ export default function toV4 (registry: Registry, { modules }: MetadataV3): MetadataV4 { - return new MetadataV4(registry, { + return createType(registry, 'MetadataV4', { modules: modules.map(({ calls, events, name, prefix, storage }): ModuleMetadataV4 => - new ModuleMetadataV4(registry, { + createType(registry, 'ModuleMetadataV4', { calls, events, name, @@ -63,8 +58,8 @@ export default function toV4 (registry: Registry, { modules }: MetadataV3): Meta storage: storage.isSome ? new Option( registry, - Vec.with(StorageFunctionMetadata), - storage.unwrap().map((v): StorageFunctionMetadata => toV4StorageFunction(registry, v)) + 'Vec', + storage.unwrap().map((v): StorageFunctionMetadataV4 => toV4StorageFunction(registry, v)) ) : undefined }) diff --git a/packages/metadata/src/Metadata/v4/Metadata.ts b/packages/metadata/src/Metadata/v4/Metadata.ts deleted file mode 100644 index 0e41dc2d0c..0000000000 --- a/packages/metadata/src/Metadata/v4/Metadata.ts +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { EventMetadataV4, FunctionMetadataV4 } from '@polkadot/types/interfaces/metadata'; -import { Registry } from '@polkadot/types/types'; -import { MetadataInterface } from '../types'; - -import Option from '@polkadot/types/codec/Option'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Text from '@polkadot/types/primitive/Text'; -import { StorageFunctionMetadata } from './Storage'; - -/** - * @name ModuleMetadataV4 - * @description - * The definition of a module in the system - */ -export class ModuleMetadataV4 extends Struct { - constructor (registry: Registry, value?: any) { - super(registry, { - name: 'Text', - prefix: 'Text', - storage: Option.with(Vec.with(StorageFunctionMetadata)), - calls: Option.with('Vec'), - events: Option.with('Vec') - }, value); - } - - /** - * @description the module calls - */ - public get calls (): Option> { - return this.get('calls') as Option>; - } - - /** - * @description the module events - */ - public get events (): Option> { - return this.get('events') as Option>; - } - - /** - * @description the module name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description the module prefix - */ - public get prefix (): Text { - return this.get('prefix') as Text; - } - - /** - * @description the associated module storage - */ - public get storage (): Option> { - return this.get('storage') as Option>; - } -} - -/** - * @name MetadataV4 - * @description - * The runtime metadata as a decoded structure - */ -export default class MetadataV4 extends Struct implements MetadataInterface { - constructor (registry: Registry, value?: any) { - super(registry, { - modules: Vec.with(ModuleMetadataV4) - }, value); - } - - /** - * @description The associated modules for this structure - */ - public get modules (): Vec { - return this.get('modules') as Vec; - } -} diff --git a/packages/metadata/src/Metadata/v4/Storage.ts b/packages/metadata/src/Metadata/v4/Storage.ts deleted file mode 100644 index 4f7e5fc69b..0000000000 --- a/packages/metadata/src/Metadata/v4/Storage.ts +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { DoubleMapTypeV4, MapTypeV4, PlainTypeV4, StorageFunctionModifierV4 } from '@polkadot/types/interfaces/metadata'; -import { AnyNumber, Registry } from '@polkadot/types/types'; - -import { assert } from '@polkadot/util'; - -import Enum from '@polkadot/types/codec/Enum'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Bytes from '@polkadot/types/primitive/Bytes'; -import Text from '@polkadot/types/primitive/Text'; - -export class StorageFunctionType extends Enum { - constructor (registry: Registry, value?: any, index?: number) { - super(registry, { - Plain: 'PlainTypeV4', - Map: 'MapTypeV4', - DoubleMap: 'DoubleMapTypeV4' - }, value, index); - } - - /** - * @description The value as a mapped value - */ - public get asDoubleMap (): DoubleMapTypeV4 { - assert(this.isDoubleMap, `Cannot convert '${this.type}' via asDoubleMap`); - - return this.value as DoubleMapTypeV4; - } - - /** - * @description The value as a mapped value - */ - public get asMap (): MapTypeV4 { - assert(this.isMap, `Cannot convert '${this.type}' via asMap`); - - return this.value as MapTypeV4; - } - - /** - * @description The value as a [[Type]] value - */ - public get asPlain (): PlainTypeV4 { - assert(this.isPlain, `Cannot convert '${this.type}' via asPlain`); - - return this.value as PlainTypeV4; - } - - /** - * @description `true` if the storage entry is a doublemap - */ - public get isDoubleMap (): boolean { - return this.toNumber() === 2; - } - - /** - * @description `true` if the storage entry is a map - */ - public get isMap (): boolean { - return this.toNumber() === 1; - } - - /** - * @description `true` if the storage entry is a plain type - */ - public get isPlain (): boolean { - return this.toNumber() === 0; - } -} - -export interface StorageFunctionMetadataValue { - name: string | Text; - modifier: StorageFunctionModifierV4 | AnyNumber; - type: StorageFunctionType; - fallback: Bytes; - documentation: Vec | string[]; -} - -/** - * @name StorageFunctionMetadata - * @description - * The definition of a storage function - */ -export class StorageFunctionMetadata extends Struct { - constructor (registry: Registry, value?: StorageFunctionMetadataValue | Uint8Array) { - super(registry, { - name: 'Text', - modifier: 'StorageFunctionModifierV4', - type: StorageFunctionType, - fallback: 'Bytes', - documentation: 'Vec' - }, value); - } - - /** - * @description The default value of the storage function - */ - public get fallback (): Bytes { - return this.get('fallback') as Bytes; - } - - /** - * @description The [[Text]] documentation - */ - public get documentation (): Vec { - return this.get('documentation') as Vec; - } - - /** - * @description The key name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description The modifier - */ - public get modifier (): StorageFunctionModifierV4 { - return this.get('modifier') as StorageFunctionModifierV4; - } - - /** - * @description The [[StorageFunctionType]] - */ - public get type (): StorageFunctionType { - return this.get('type') as StorageFunctionType; - } -} diff --git a/packages/metadata/src/Metadata/v4/index.ts b/packages/metadata/src/Metadata/v4/index.ts deleted file mode 100644 index 4405fc5f83..0000000000 --- a/packages/metadata/src/Metadata/v4/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import MetadataV4, { ModuleMetadataV4 } from './Metadata'; - -export default MetadataV4; - -export { - ModuleMetadataV4 -}; diff --git a/packages/metadata/src/Metadata/v4/toV5.ts b/packages/metadata/src/Metadata/v4/toV5.ts index 0ce789601d..2f446cad79 100644 --- a/packages/metadata/src/Metadata/v4/toV5.ts +++ b/packages/metadata/src/Metadata/v4/toV5.ts @@ -2,18 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { MetadataV4, MetadataV5, ModuleMetadataV5, StorageFunctionMetadataV4, StorageFunctionMetadataV5 } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; import { assert } from '@polkadot/util'; -import { createType, Option, Vec } from '@polkadot/types/codec'; +import { createType, Option } from '@polkadot/types/codec'; import StorageHasher from '@polkadot/types/primitive/StorageHasher'; import Text from '@polkadot/types/primitive/Text'; -import MetadataV4 from './Metadata'; -import MetadataV5 from '../v5'; -import { ModuleMetadataV5 } from '../v5/Metadata'; -import { StorageFunctionMetadata, StorageFunctionType } from '../v5/Storage'; -import { StorageFunctionMetadata as StorageFunctionMetadataV4 } from './Storage'; const hasherMap: Map = new Map([ ['blake2_128', 'Blake2_128'], @@ -34,7 +30,7 @@ function toStorageHasher (registry: Registry, text: Text): StorageHasher { /** * Convert V4 StorageFunction to V5 StorageFunction */ -function toV5StorageFunction (registry: Registry, storageFn: StorageFunctionMetadataV4): StorageFunctionMetadata { +function toV5StorageFunction (registry: Registry, storageFn: StorageFunctionMetadataV4): StorageFunctionMetadataV5 { const { documentation, fallback, modifier, name, type } = storageFn; const [newType, index] = type.isPlain ? [type.asPlain, 0] @@ -48,12 +44,12 @@ function toV5StorageFunction (registry: Registry, storageFn: StorageFunctionMeta key2Hasher: toStorageHasher(registry, type.asDoubleMap.key2Hasher) }), 2]; - return new StorageFunctionMetadata(registry, { + return createType(registry, 'StorageFunctionMetadataV5', { documentation, fallback, name, modifier, - type: new StorageFunctionType(registry, newType, index) + type: createType(registry, 'StorageFunctionTypeV5', newType, index) }); } @@ -62,16 +58,16 @@ function toV5StorageFunction (registry: Registry, storageFn: StorageFunctionMeta * See https://github.com/paritytech/substrate/pull/2836/files for details */ export default function toV5 (registry: Registry, { modules }: MetadataV4): MetadataV5 { - return new MetadataV5(registry, { + return createType(registry, 'MetadataV5', { modules: modules.map(({ calls, events, name, prefix, storage }): ModuleMetadataV5 => - new ModuleMetadataV5(registry, { + createType(registry, 'ModuleMetadataV5', { name, prefix, storage: storage.isSome ? new Option( registry, - Vec.with(StorageFunctionMetadata), - storage.unwrap().map((v): StorageFunctionMetadata => toV5StorageFunction(registry, v)) + 'Vec', + storage.unwrap().map((v): StorageFunctionMetadataV5 => toV5StorageFunction(registry, v)) ) : undefined, calls, diff --git a/packages/metadata/src/Metadata/v5/Metadata.ts b/packages/metadata/src/Metadata/v5/Metadata.ts deleted file mode 100644 index 9313ed6100..0000000000 --- a/packages/metadata/src/Metadata/v5/Metadata.ts +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { EventMetadataV5, FunctionMetadataV5 } from '@polkadot/types/interfaces/metadata'; -import { Registry } from '@polkadot/types/types'; -import { MetadataInterface } from '../types'; - -import Option from '@polkadot/types/codec/Option'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Text from '@polkadot/types/primitive/Text'; -import { StorageFunctionMetadata } from './Storage'; - -/** - * @name ModuleMetadataV5 - * @description - * The definition of a module in the system - */ -export class ModuleMetadataV5 extends Struct { - constructor (registry: Registry, value?: any) { - super(registry, { - name: 'Text', - prefix: 'Text', - storage: Option.with(Vec.with(StorageFunctionMetadata)), - calls: Option.with('Vec'), - events: Option.with('Vec') - }, value); - } - - /** - * @description the module calls - */ - public get calls (): Option> { - return this.get('calls') as Option>; - } - - /** - * @description the module events - */ - public get events (): Option> { - return this.get('events') as Option>; - } - - /** - * @description the module name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description the module prefix - */ - public get prefix (): Text { - return this.get('prefix') as Text; - } - - /** - * @description the associated module storage - */ - public get storage (): Option> { - return this.get('storage') as Option>; - } -} - -/** - * @name MetadataV5 - * @description - * The runtime metadata as a decoded structure - */ -export default class MetadataV5 extends Struct implements MetadataInterface { - constructor (registry: Registry, value?: any) { - super(registry, { - modules: Vec.with(ModuleMetadataV5) - }, value); - } - - /** - * @description The associated modules for this structure - */ - public get modules (): Vec { - return this.get('modules') as Vec; - } -} diff --git a/packages/metadata/src/Metadata/v5/Storage.ts b/packages/metadata/src/Metadata/v5/Storage.ts deleted file mode 100644 index fe016a0401..0000000000 --- a/packages/metadata/src/Metadata/v5/Storage.ts +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { DoubleMapTypeV5, MapTypeV5, PlainTypeV5, StorageFunctionModifierV5 } from '@polkadot/types/interfaces/metadata'; -import { AnyNumber, Registry } from '@polkadot/types/types'; - -import { assert } from '@polkadot/util'; - -import Enum from '@polkadot/types/codec/Enum'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Bytes from '@polkadot/types/primitive/Bytes'; -import Text from '@polkadot/types/primitive/Text'; - -export class StorageFunctionType extends Enum { - constructor (registry: Registry, value?: any, index?: number) { - super(registry, { - Plain: 'PlainTypeV5', - Map: 'MapTypeV5', - DoubleMap: 'DoubleMapTypeV5' - }, value, index); - } - - /** - * @description The value as a mapped value - */ - public get asDoubleMap (): DoubleMapTypeV5 { - assert(this.isDoubleMap, `Cannot convert '${this.type}' via asDoubleMap`); - - return this.value as DoubleMapTypeV5; - } - - /** - * @description The value as a mapped value - */ - public get asMap (): MapTypeV5 { - assert(this.isMap, `Cannot convert '${this.type}' via asMap`); - - return this.value as MapTypeV5; - } - - /** - * @description The value as a [[Type]] value - */ - public get asPlain (): PlainTypeV5 { - assert(this.isPlain, `Cannot convert '${this.type}' via asPlain`); - - return this.value as PlainTypeV5; - } - - /** - * @description `true` if the storage entry is a doublemap - */ - public get isDoubleMap (): boolean { - return this.toNumber() === 2; - } - - /** - * @description `true` if the storage entry is a map - */ - public get isMap (): boolean { - return this.toNumber() === 1; - } - - /** - * @description `true` if the storage entry is a plain type - */ - public get isPlain (): boolean { - return this.toNumber() === 0; - } -} - -export interface StorageFunctionMetadataValue { - name: string | Text; - modifier: StorageFunctionModifierV5 | AnyNumber; - type: StorageFunctionType; - fallback: Bytes; - documentation: Vec | string[]; -} - -/** - * @name StorageFunctionMetadata - * @description - * The definition of a storage function - */ -export class StorageFunctionMetadata extends Struct { - constructor (registry: Registry, value?: StorageFunctionMetadataValue | Uint8Array) { - super(registry, { - name: 'Text', - modifier: 'StorageFunctionModifierV5', - type: StorageFunctionType, - fallback: 'Bytes', - documentation: 'Vec' - }, value); - } - - /** - * @description The default value of the storage function - */ - public get fallback (): Bytes { - return this.get('fallback') as Bytes; - } - - /** - * @description The [[Text]] documentation - */ - public get documentation (): Vec { - return this.get('documentation') as Vec; - } - - /** - * @description The key name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description The modifier - */ - public get modifier (): StorageFunctionModifierV5 { - return this.get('modifier') as StorageFunctionModifierV5; - } - - /** - * @description The [[StorageFunctionType]] - */ - public get type (): StorageFunctionType { - return this.get('type') as StorageFunctionType; - } -} diff --git a/packages/metadata/src/Metadata/v5/index.ts b/packages/metadata/src/Metadata/v5/index.ts deleted file mode 100644 index 8b5d7d448d..0000000000 --- a/packages/metadata/src/Metadata/v5/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import MetadataV5, { ModuleMetadataV5 } from './Metadata'; - -export default MetadataV5; - -export { - ModuleMetadataV5 -}; diff --git a/packages/metadata/src/Metadata/v5/toV6.ts b/packages/metadata/src/Metadata/v5/toV6.ts index c5652b9d99..e4e3ca935f 100644 --- a/packages/metadata/src/Metadata/v5/toV6.ts +++ b/packages/metadata/src/Metadata/v5/toV6.ts @@ -2,20 +2,19 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { MetadataV5, MetadataV6, ModuleMetadataV6 } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; -import MetadataV5 from './Metadata'; -import MetadataV6 from '../v6'; -import { ModuleMetadataV6 } from '../v6/Metadata'; +import { createType } from '@polkadot/types'; /** * Convert from MetadataV5 to MetadataV6 * See https://github.com/polkadot-js/api/issues/1043 for details */ export default function toV6 (registry: Registry, { modules }: MetadataV5): MetadataV6 { - return new MetadataV6(registry, { + return createType(registry, 'MetadataV6', { modules: modules.map(({ calls, events, name, prefix, storage }): ModuleMetadataV6 => - new ModuleMetadataV6(registry, { + createType(registry, 'ModuleMetadataV6', { calls, constants: [], events, diff --git a/packages/metadata/src/Metadata/v6/Metadata.ts b/packages/metadata/src/Metadata/v6/Metadata.ts deleted file mode 100644 index e1effa009a..0000000000 --- a/packages/metadata/src/Metadata/v6/Metadata.ts +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { EventMetadataV6, FunctionMetadataV6, ModuleConstantMetadataV6 } from '@polkadot/types/interfaces/metadata'; -import { Registry } from '@polkadot/types/types'; -import { MetadataInterface } from '../types'; - -import Option from '@polkadot/types/codec/Option'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Text from '@polkadot/types/primitive/Text'; -import { StorageEntryMetadata } from './Storage'; - -/** - * @name ModuleMetadataV6 - * @description - * The definition of a module in the system - */ -export class ModuleMetadataV6 extends Struct { - constructor (registry: Registry, value?: any) { - super(registry, { - name: 'Text', - prefix: 'Text', - storage: Option.with(Vec.with(StorageEntryMetadata)), - calls: Option.with('Vec'), - events: Option.with('Vec'), - constants: 'Vec' - }, value); - } - - /** - * @description the module calls - */ - public get calls (): Option> { - return this.get('calls') as Option>; - } - - /** - * @description the module constants - */ - public get constants (): Vec { - return this.get('constants') as Vec; - } - - /** - * @description the module events - */ - public get events (): Option> { - return this.get('events') as Option>; - } - - /** - * @description the module name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description the module prefix - */ - public get prefix (): Text { - return this.get('prefix') as Text; - } - - /** - * @description the associated module storage - */ - public get storage (): Option> { - return this.get('storage') as Option>; - } -} - -/** - * @name MetadataV6 - * @description - * The runtime metadata as a decoded structure - */ -export default class MetadataV6 extends Struct implements MetadataInterface { - constructor (registry: Registry, value?: any) { - super(registry, { - modules: Vec.with(ModuleMetadataV6) - }, value); - } - - /** - * @description The associated modules for this structure - */ - public get modules (): Vec { - return this.get('modules') as Vec; - } -} diff --git a/packages/metadata/src/Metadata/v6/Storage.ts b/packages/metadata/src/Metadata/v6/Storage.ts deleted file mode 100644 index 4d58e98e8f..0000000000 --- a/packages/metadata/src/Metadata/v6/Storage.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { StorageFunctionMetadata, StorageFunctionMetadataValue, StorageFunctionType } from '../v5/Storage'; - -// Re-export classes that haven't changed between V5 and V6 -export { - StorageFunctionMetadata as StorageEntryMetadata, - StorageFunctionMetadataValue as StorageEntryMetadataValue, - StorageFunctionType as StorageEntryType -}; diff --git a/packages/metadata/src/Metadata/v6/index.ts b/packages/metadata/src/Metadata/v6/index.ts deleted file mode 100644 index 6615bacd2c..0000000000 --- a/packages/metadata/src/Metadata/v6/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import MetadataV6, { ModuleMetadataV6 } from './Metadata'; - -export default MetadataV6; - -export { - ModuleMetadataV6 -}; diff --git a/packages/metadata/src/Metadata/v6/toV7.ts b/packages/metadata/src/Metadata/v6/toV7.ts index 4a1bc4673e..7d12c9929b 100644 --- a/packages/metadata/src/Metadata/v6/toV7.ts +++ b/packages/metadata/src/Metadata/v6/toV7.ts @@ -2,26 +2,24 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { MetadataV6, MetadataV7, ModuleMetadataV7 } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; -import MetadataV6 from './Metadata'; -import MetadataV7 from '../v7'; -import { ModuleMetadataV7 } from '../v7/Metadata'; -import { StorageMetadata as StorageV7 } from '../v7/Storage'; +import { createType } from '@polkadot/types'; /** * Convert from MetadataV6 to MetadataV7 */ export default function toV7 (registry: Registry, { modules }: MetadataV6): MetadataV7 { - return new MetadataV7(registry, { + return createType(registry, 'MetadataV7', { modules: modules.map(({ calls, constants, events, name, prefix, storage }): ModuleMetadataV7 => - new ModuleMetadataV7(registry, { + createType(registry, 'ModuleMetadataV7', { calls, constants, events, name, storage: storage.isSome - ? new StorageV7(registry, { prefix, items: storage.unwrap() }) + ? createType(registry, 'StorageMetadataV7', { prefix, items: storage.unwrap() }) : null }) ) diff --git a/packages/metadata/src/Metadata/v7/Metadata.ts b/packages/metadata/src/Metadata/v7/Metadata.ts deleted file mode 100644 index 2743057600..0000000000 --- a/packages/metadata/src/Metadata/v7/Metadata.ts +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { EventMetadataV7, FunctionMetadataV7, ModuleConstantMetadataV7 } from '@polkadot/types/interfaces/metadata'; -import { Registry } from '@polkadot/types/types'; -import { MetadataInterface } from '../types'; - -import Option from '@polkadot/types/codec/Option'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Text from '@polkadot/types/primitive/Text'; -import { StorageMetadata } from './Storage'; - -/** - * @name ModuleMetadataV7 - * @description - * The definition of a module in the system - */ -export class ModuleMetadataV7 extends Struct { - constructor (registry: Registry, value?: any) { - super(registry, { - name: 'Text', - storage: Option.with(StorageMetadata), - calls: Option.with('Vec'), - events: Option.with('Vec'), - constants: 'Vec' - }, value); - } - - /** - * @description the module calls - */ - public get calls (): Option> { - return this.get('calls') as Option>; - } - - /** - * @description the module constants - */ - public get constants (): Vec { - return this.get('constants') as Vec; - } - - /** - * @description the module events - */ - public get events (): Option> { - return this.get('events') as Option>; - } - - /** - * @description the module name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description the associated module storage - */ - public get storage (): Option { - return this.get('storage') as Option; - } -} - -/** - * @name MetadataV7 - * @description - * The runtime metadata as a decoded structure - */ -export default class MetadataV7 extends Struct implements MetadataInterface { - constructor (registry: Registry, value?: any) { - super(registry, { - modules: Vec.with(ModuleMetadataV7) - }, value); - } - - /** - * @description The associated modules for this structure - */ - public get modules (): Vec { - return this.get('modules') as Vec; - } -} diff --git a/packages/metadata/src/Metadata/v7/Storage.ts b/packages/metadata/src/Metadata/v7/Storage.ts deleted file mode 100644 index 5cf3c32628..0000000000 --- a/packages/metadata/src/Metadata/v7/Storage.ts +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { Registry } from '@polkadot/types/types'; - -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Text from '@polkadot/types/primitive/Text'; -import { StorageEntryMetadata, StorageEntryMetadataValue, StorageEntryType } from '../v6/Storage'; - -// Re-export classes that haven't changed between V6 and V7 -export { - StorageEntryMetadata, - StorageEntryMetadataValue, - StorageEntryType -}; - -export class StorageMetadata extends Struct { - constructor (registry: Registry, value?: any) { - super(registry, { - prefix: 'Text', - // NOTE renamed to items from entries (since Struct already has entries from Map) - items: Vec.with(StorageEntryMetadata) - }, value); - } - - /** - * @description the storage entries - */ - public get items (): Vec { - return this.get('items') as Vec; - } - - /** - * @description the prefix for this module - */ - public get prefix (): Text { - return this.get('prefix') as Text; - } -} diff --git a/packages/metadata/src/Metadata/v7/index.ts b/packages/metadata/src/Metadata/v7/index.ts deleted file mode 100644 index 33cd99f0e8..0000000000 --- a/packages/metadata/src/Metadata/v7/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import MetadataV7, { ModuleMetadataV7 } from './Metadata'; - -export default MetadataV7; - -export { - ModuleMetadataV7 -}; diff --git a/packages/metadata/src/Metadata/v7/toV8.ts b/packages/metadata/src/Metadata/v7/toV8.ts index e0adb1252b..8161d6915b 100644 --- a/packages/metadata/src/Metadata/v7/toV8.ts +++ b/packages/metadata/src/Metadata/v7/toV8.ts @@ -2,19 +2,18 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { MetadataV7, MetadataV8, ModuleMetadataV8 } from '@polkadot/types/interfaces/metadata'; import { Registry } from '@polkadot/types/types'; -import MetadataV7 from './Metadata'; -import MetadataV8 from '../v8'; -import { ModuleMetadataV8 } from '../v8/Metadata'; +import { createType } from '@polkadot/types'; /** * Convert from MetadataV7 to MetadataV8 */ export default function toV8 (registry: Registry, { modules }: MetadataV7): MetadataV8 { - return new MetadataV8(registry, { + return createType(registry, 'MetadataV8', { modules: modules.map(({ calls, constants, events, name, storage }): ModuleMetadataV8 => - new ModuleMetadataV8(registry, { + createType(registry, 'ModuleMetadataV8', { calls, constants, errors: [], diff --git a/packages/metadata/src/Metadata/v8/Metadata.ts b/packages/metadata/src/Metadata/v8/Metadata.ts deleted file mode 100644 index c5158f1cfb..0000000000 --- a/packages/metadata/src/Metadata/v8/Metadata.ts +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { ErrorMetadataV8, EventMetadataV8, FunctionMetadataV8, ModuleConstantMetadataV8 } from '@polkadot/types/interfaces/metadata'; -import { Registry } from '@polkadot/types/types'; -import { MetadataInterface } from '../types'; - -import Option from '@polkadot/types/codec/Option'; -import Struct from '@polkadot/types/codec/Struct'; -import Vec from '@polkadot/types/codec/Vec'; -import Text from '@polkadot/types/primitive/Text'; -import { StorageMetadata } from './Storage'; - -// Note the following errors are non-duplicated and fill the first 2 slots for -// each of the modules - this means that other errors start at index 2 -// -// { -// "name": "Other", -// "documentation": [ -// "Other unspecified error" -// ] -// }, -// { -// "name": "CannotLookup", -// "documentation": [ -// "Can not lookup" -// ] -// } - -/** - * @name ModuleMetadataV8 - * @description - * The definition of a module in the system - */ -export class ModuleMetadataV8 extends Struct { - constructor (registry: Registry, value?: any) { - super(registry, { - name: 'Text', - storage: Option.with(StorageMetadata), - calls: Option.with('Vec'), - events: Option.with('Vec'), - constants: 'Vec', - errors: 'Vec' - }, value); - } - - /** - * @description the module calls - */ - public get calls (): Option> { - return this.get('calls') as Option>; - } - - /** - * @description the module constants - */ - public get constants (): Vec { - return this.get('constants') as Vec; - } - - /** - * @description the module errors - */ - public get errors (): Vec { - return this.get('errors') as Vec; - } - - /** - * @description the module events - */ - public get events (): Option> { - return this.get('events') as Option>; - } - - /** - * @description the module name - */ - public get name (): Text { - return this.get('name') as Text; - } - - /** - * @description the associated module storage - */ - public get storage (): Option { - return this.get('storage') as Option; - } -} - -/** - * @name MetadataV8 - * @description - * The runtime metadata as a decoded structure - */ -export default class MetadataV8 extends Struct implements MetadataInterface { - constructor (registry: Registry, value?: any) { - super(registry, { - modules: Vec.with(ModuleMetadataV8) - }, value); - } - - /** - * @description The associated modules for this structure - */ - public get modules (): Vec { - return this.get('modules') as Vec; - } -} diff --git a/packages/metadata/src/Metadata/v8/Storage.ts b/packages/metadata/src/Metadata/v8/Storage.ts deleted file mode 100644 index b78b899323..0000000000 --- a/packages/metadata/src/Metadata/v8/Storage.ts +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -export { StorageEntryMetadata, StorageEntryMetadataValue, StorageEntryType, StorageMetadata } from '../v7/Storage'; diff --git a/packages/metadata/src/Metadata/v8/index.ts b/packages/metadata/src/Metadata/v8/index.ts deleted file mode 100644 index 0b99a724bf..0000000000 --- a/packages/metadata/src/Metadata/v8/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2017-2019 @polkadot/metadata authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import MetadataV8, { ModuleMetadataV8 } from './Metadata'; - -export default MetadataV8; - -export { - ModuleMetadataV8 -}; diff --git a/packages/types/src/codec/create/createType.ts b/packages/types/src/codec/create/createType.ts index 2866be09e8..68b0633707 100644 --- a/packages/types/src/codec/create/createType.ts +++ b/packages/types/src/codec/create/createType.ts @@ -57,7 +57,7 @@ function initType (registry: // An unsafe version of the `createType` below. It's unsafe because the `type` // argument here can be any string, which, if not parseable, will yield a // runtime error. -export function createTypeUnsafe (registry: Registry, type: K, params: any[] = [], isPedantic?: boolean): FromReg { +export function createTypeUnsafe (registry: Registry, type: K, params: any[] = [], isPedantic?: boolean): T { try { return initType(registry, createClass(registry, type), params, isPedantic); } catch (error) { @@ -72,7 +72,5 @@ export function createTypeUnsafe (registry: Registry, type: K, ...params: any[]): InterfaceRegistry[K] { - // error TS2589: Type instantiation is excessively deep and possibly infinite. - // The above happens with as Constructor; - return createTypeUnsafe(registry, type, params) as any; + return createTypeUnsafe(registry, type, params); } diff --git a/packages/types/src/interfaceRegistry.ts b/packages/types/src/interfaceRegistry.ts index 39a6bdc4f5..dc4cfce841 100644 --- a/packages/types/src/interfaceRegistry.ts +++ b/packages/types/src/interfaceRegistry.ts @@ -27,7 +27,7 @@ import { DispatchResult, DispatchResultOf } from '@polkadot/types/interfaces/uti import { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations'; import { EthereumAddress } from '@polkadot/types/interfaces/claims'; import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains'; -import { CallMetadataV0, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, ErrorMetadataV8, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, MapTypeV0, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MetadataV0, MetadataV1, ModuleConstantMetadataLatest, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleMetadataV0, ModuleMetadataV1, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, RuntimeModuleMetadataV0, StorageEntryModifierLatest, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageMetadataV0 } from '@polkadot/types/interfaces/metadata'; +import { CallMetadataV0, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, ErrorMetadataV8, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, MapTypeV0, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MetadataLatest, MetadataV0, MetadataV1, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, ModuleConstantMetadataLatest, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryModifierLatest, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryTypeLatest, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageMetadataV0, StorageMetadataV7, StorageMetadataV8 } from '@polkadot/types/interfaces/metadata'; import { ApiId, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/rpc'; export interface InterfaceRegistry { @@ -892,12 +892,24 @@ export interface InterfaceRegistry { MapTypeV2: MapTypeV2; 'Option': Option; 'Vec': Vec; + MetadataV2: MetadataV2; + 'Option': Option; + 'Vec': Vec; + ModuleMetadataV2: ModuleMetadataV2; + 'Option': Option; + 'Vec': Vec; PlainTypeV2: PlainTypeV2; 'Option': Option; 'Vec': Vec; + StorageFunctionMetadataV2: StorageFunctionMetadataV2; + 'Option': Option; + 'Vec': Vec; StorageFunctionModifierV2: StorageFunctionModifierV2; 'Option': Option; 'Vec': Vec; + StorageFunctionTypeV2: StorageFunctionTypeV2; + 'Option': Option; + 'Vec': Vec; DoubleMapTypeV3: DoubleMapTypeV3; 'Option': Option; 'Vec': Vec; @@ -913,12 +925,24 @@ export interface InterfaceRegistry { MapTypeV3: MapTypeV3; 'Option': Option; 'Vec': Vec; + MetadataV3: MetadataV3; + 'Option': Option; + 'Vec': Vec; + ModuleMetadataV3: ModuleMetadataV3; + 'Option': Option; + 'Vec': Vec; PlainTypeV3: PlainTypeV3; 'Option': Option; 'Vec': Vec; + StorageFunctionMetadataV3: StorageFunctionMetadataV3; + 'Option': Option; + 'Vec': Vec; StorageFunctionModifierV3: StorageFunctionModifierV3; 'Option': Option; 'Vec': Vec; + StorageFunctionTypeV3: StorageFunctionTypeV3; + 'Option': Option; + 'Vec': Vec; DoubleMapTypeV4: DoubleMapTypeV4; 'Option': Option; 'Vec': Vec; @@ -934,12 +958,24 @@ export interface InterfaceRegistry { MapTypeV4: MapTypeV4; 'Option': Option; 'Vec': Vec; + MetadataV4: MetadataV4; + 'Option': Option; + 'Vec': Vec; + ModuleMetadataV4: ModuleMetadataV4; + 'Option': Option; + 'Vec': Vec; PlainTypeV4: PlainTypeV4; 'Option': Option; 'Vec': Vec; + StorageFunctionMetadataV4: StorageFunctionMetadataV4; + 'Option': Option; + 'Vec': Vec; StorageFunctionModifierV4: StorageFunctionModifierV4; 'Option': Option; 'Vec': Vec; + StorageFunctionTypeV4: StorageFunctionTypeV4; + 'Option': Option; + 'Vec': Vec; DoubleMapTypeV5: DoubleMapTypeV5; 'Option': Option; 'Vec': Vec; @@ -955,12 +991,24 @@ export interface InterfaceRegistry { MapTypeV5: MapTypeV5; 'Option': Option; 'Vec': Vec; + MetadataV5: MetadataV5; + 'Option': Option; + 'Vec': Vec; + ModuleMetadataV5: ModuleMetadataV5; + 'Option': Option; + 'Vec': Vec; PlainTypeV5: PlainTypeV5; 'Option': Option; 'Vec': Vec; + StorageFunctionMetadataV5: StorageFunctionMetadataV5; + 'Option': Option; + 'Vec': Vec; StorageFunctionModifierV5: StorageFunctionModifierV5; 'Option': Option; 'Vec': Vec; + StorageFunctionTypeV5: StorageFunctionTypeV5; + 'Option': Option; + 'Vec': Vec; DoubleMapTypeV6: DoubleMapTypeV6; 'Option': Option; 'Vec': Vec; @@ -976,15 +1024,27 @@ export interface InterfaceRegistry { MapTypeV6: MapTypeV6; 'Option': Option; 'Vec': Vec; + MetadataV6: MetadataV6; + 'Option': Option; + 'Vec': Vec; ModuleConstantMetadataV6: ModuleConstantMetadataV6; 'Option': Option; 'Vec': Vec; + ModuleMetadataV6: ModuleMetadataV6; + 'Option': Option; + 'Vec': Vec; PlainTypeV6: PlainTypeV6; 'Option': Option; 'Vec': Vec; StorageEntryModifierV6: StorageEntryModifierV6; 'Option': Option; 'Vec': Vec; + StorageEntryMetadataV6: StorageEntryMetadataV6; + 'Option': Option; + 'Vec': Vec; + StorageEntryTypeV6: StorageEntryTypeV6; + 'Option': Option; + 'Vec': Vec; DoubleMapTypeV7: DoubleMapTypeV7; 'Option': Option; 'Vec': Vec; @@ -1000,15 +1060,30 @@ export interface InterfaceRegistry { MapTypeV7: MapTypeV7; 'Option': Option; 'Vec': Vec; + MetadataV7: MetadataV7; + 'Option': Option; + 'Vec': Vec; ModuleConstantMetadataV7: ModuleConstantMetadataV7; 'Option': Option; 'Vec': Vec; + ModuleMetadataV7: ModuleMetadataV7; + 'Option': Option; + 'Vec': Vec; PlainTypeV7: PlainTypeV7; 'Option': Option; 'Vec': Vec; StorageEntryModifierV7: StorageEntryModifierV7; 'Option': Option; 'Vec': Vec; + StorageEntryMetadataV7: StorageEntryMetadataV7; + 'Option': Option; + 'Vec': Vec; + StorageEntryTypeV7: StorageEntryTypeV7; + 'Option': Option; + 'Vec': Vec; + StorageMetadataV7: StorageMetadataV7; + 'Option': Option; + 'Vec': Vec; DoubleMapTypeV8: DoubleMapTypeV8; 'Option': Option; 'Vec': Vec; @@ -1027,15 +1102,30 @@ export interface InterfaceRegistry { MapTypeV8: MapTypeV8; 'Option': Option; 'Vec': Vec; + MetadataV8: MetadataV8; + 'Option': Option; + 'Vec': Vec; ModuleConstantMetadataV8: ModuleConstantMetadataV8; 'Option': Option; 'Vec': Vec; + ModuleMetadataV8: ModuleMetadataV8; + 'Option': Option; + 'Vec': Vec; PlainTypeV8: PlainTypeV8; 'Option': Option; 'Vec': Vec; StorageEntryModifierV8: StorageEntryModifierV8; 'Option': Option; 'Vec': Vec; + StorageEntryMetadataV8: StorageEntryMetadataV8; + 'Option': Option; + 'Vec': Vec; + StorageEntryTypeV8: StorageEntryTypeV8; + 'Option': Option; + 'Vec': Vec; + StorageMetadataV8: StorageMetadataV8; + 'Option': Option; + 'Vec': Vec; EventMetadataLatest: EventMetadataLatest; 'Option': Option; 'Vec': Vec; @@ -1045,15 +1135,27 @@ export interface InterfaceRegistry { FunctionMetadataLatest: FunctionMetadataLatest; 'Option': Option; 'Vec': Vec; + MetadataLatest: MetadataLatest; + 'Option': Option; + 'Vec': Vec; ModuleConstantMetadataLatest: ModuleConstantMetadataLatest; 'Option': Option; 'Vec': Vec; + ModuleMetadataLatest: ModuleMetadataLatest; + 'Option': Option; + 'Vec': Vec; PlainTypeLatest: PlainTypeLatest; 'Option': Option; 'Vec': Vec; + StorageEntryMetadataLatest: StorageEntryMetadataLatest; + 'Option': Option; + 'Vec': Vec; StorageEntryModifierLatest: StorageEntryModifierLatest; 'Option': Option; 'Vec': Vec; + StorageEntryTypeLatest: StorageEntryTypeLatest; + 'Option': Option; + 'Vec': Vec; ApiId: ApiId; 'Option': Option; 'Vec': Vec; diff --git a/packages/types/src/interfaces/metadata/definitions.ts b/packages/types/src/interfaces/metadata/definitions.ts index 3ee0a229c1..366a8e7ec4 100644 --- a/packages/types/src/interfaces/metadata/definitions.ts +++ b/packages/types/src/interfaces/metadata/definitions.ts @@ -110,8 +110,31 @@ export default { value: 'Type', linked: 'bool' }, + MetadataV2: { + modules: 'Vec' + }, + ModuleMetadataV2: { + name: 'Text', + prefix: 'Text', + storage: 'Option>', + calls: 'Option>', + events: 'Option>' + }, PlainTypeV2: 'Type', + StorageFunctionMetadataV2: { + name: 'Text', + modifier: 'StorageFunctionModifierV2', + type: 'StorageFunctionTypeV2', + fallback: 'Bytes', + documentation: 'Vec' + }, StorageFunctionModifierV2: 'StorageFunctionModifierV1', + StorageFunctionTypeV2: { + _enum: { + Plain: 'PlainTypeV2', + Map: 'MapTypeV2' + } + }, // v3 DoubleMapTypeV3: { @@ -124,8 +147,32 @@ export default { FunctionArgumentMetadataV3: 'FunctionArgumentMetadataV2', FunctionMetadataV3: 'FunctionMetadataV2', MapTypeV3: 'MapTypeV2', + MetadataV3: { + modules: 'Vec' + }, + ModuleMetadataV3: { + name: 'Text', + prefix: 'Text', + storage: 'Option>', + calls: 'Option>', + events: 'Option>' + }, PlainTypeV3: 'Type', + StorageFunctionMetadataV3: { + name: 'Text', + modifier: 'StorageFunctionModifierV3', + type: 'StorageFunctionTypeV3', + fallback: 'Bytes', + documentation: 'Vec' + }, StorageFunctionModifierV3: 'StorageFunctionModifierV2', + StorageFunctionTypeV3: { + _enum: { + Plain: 'PlainTypeV3', + Map: 'MapTypeV3', + DoubleMap: 'DoubleMapTypeV3' + } + }, // v4 DoubleMapTypeV4: { @@ -144,8 +191,32 @@ export default { value: 'Type', linked: 'bool' }, + MetadataV4: { + modules: 'Vec' + }, + ModuleMetadataV4: { + name: 'Text', + prefix: 'Text', + storage: 'Option>', + calls: 'Option>', + events: 'Option>' + }, PlainTypeV4: 'Type', + StorageFunctionMetadataV4: { + name: 'Text', + modifier: 'StorageFunctionModifierV4', + type: 'StorageFunctionTypeV4', + fallback: 'Bytes', + documentation: 'Vec' + }, StorageFunctionModifierV4: 'StorageFunctionModifierV3', + StorageFunctionTypeV4: { + _enum: { + Plain: 'PlainTypeV4', + Map: 'MapTypeV4', + DoubleMap: 'DoubleMapTypeV4' + } + }, // v5 DoubleMapTypeV5: { @@ -159,8 +230,32 @@ export default { FunctionArgumentMetadataV5: 'FunctionArgumentMetadataV4', FunctionMetadataV5: 'FunctionMetadataV4', MapTypeV5: 'MapTypeV4', + MetadataV5: { + modules: 'Vec' + }, + ModuleMetadataV5: { + name: 'Text', + prefix: 'Text', + storage: 'Option>', + calls: 'Option>', + events: 'Option>' + }, PlainTypeV5: 'Type', + StorageFunctionMetadataV5: { + name: 'Text', + modifier: 'StorageFunctionModifierV5', + type: 'StorageFunctionTypeV5', + fallback: 'Bytes', + documentation: 'Vec' + }, StorageFunctionModifierV5: 'StorageFunctionModifierV4', + StorageFunctionTypeV5: { + _enum: { + Plain: 'PlainTypeV5', + Map: 'MapTypeV5', + DoubleMap: 'DoubleMapTypeV5' + } + }, // v6 DoubleMapTypeV6: 'DoubleMapTypeV5', @@ -168,14 +263,27 @@ export default { FunctionArgumentMetadataV6: 'FunctionArgumentMetadataV5', FunctionMetadataV6: 'FunctionMetadataV5', MapTypeV6: 'MapTypeV5', + MetadataV6: { + modules: 'Vec' + }, ModuleConstantMetadataV6: { name: 'Text', type: 'Type', value: 'Bytes', documentation: 'Vec' }, + ModuleMetadataV6: { + name: 'Text', + prefix: 'Text', + storage: 'Option>', + calls: 'Option>', + events: 'Option>', + constants: 'Vec' + }, PlainTypeV6: 'Type', StorageEntryModifierV6: 'StorageFunctionModifierV5', + StorageEntryMetadataV6: 'StorageFunctionMetadataV5', + StorageEntryTypeV6: 'StorageFunctionTypeV5', // v7 DoubleMapTypeV7: 'DoubleMapTypeV6', @@ -183,9 +291,25 @@ export default { FunctionArgumentMetadataV7: 'FunctionArgumentMetadataV6', FunctionMetadataV7: 'FunctionMetadataV6', MapTypeV7: 'MapTypeV6', + MetadataV7: { + modules: 'Vec' + }, ModuleConstantMetadataV7: 'ModuleConstantMetadataV6', + ModuleMetadataV7: { + name: 'Text', + storage: 'Option', + calls: 'Option>', + events: 'Option>', + constants: 'Vec' + }, PlainTypeV7: 'Type', StorageEntryModifierV7: 'StorageEntryModifierV6', + StorageEntryMetadataV7: 'StorageEntryMetadataV6', + StorageEntryTypeV7: 'StorageEntryTypeV6', + StorageMetadataV7: { + prefix: 'Text', + items: 'Vec' + }, // v8 DoubleMapTypeV8: 'DoubleMapTypeV7', @@ -197,16 +321,34 @@ export default { FunctionArgumentMetadataV8: 'FunctionArgumentMetadataV7', FunctionMetadataV8: 'FunctionMetadataV7', MapTypeV8: 'MapTypeV7', + MetadataV8: { + modules: 'Vec' + }, ModuleConstantMetadataV8: 'ModuleConstantMetadataV7', + ModuleMetadataV8: { + name: 'Text', + storage: 'Option', + calls: 'Option>', + events: 'Option>', + constants: 'Vec', + errors: 'Vec' + }, PlainTypeV8: 'Type', StorageEntryModifierV8: 'StorageEntryModifierV7', + StorageEntryMetadataV8: 'StorageEntryMetadataV7', + StorageEntryTypeV8: 'StorageEntryTypeV7', + StorageMetadataV8: 'StorageMetadataV7', // This always maps to the latest EventMetadataLatest: 'EventMetadataV8', FunctionArgumentMetadataLatest: 'FunctionArgumentMetadataV8', FunctionMetadataLatest: 'FunctionMetadataV8', + MetadataLatest: 'MetadataV8', ModuleConstantMetadataLatest: 'ModuleConstantMetadataV8', + ModuleMetadataLatest: 'ModuleMetadataV8', PlainTypeLatest: 'PlainTypeV8', - StorageEntryModifierLatest: 'StorageEntryModifierV8' + StorageEntryMetadataLatest: 'StorageEntryMetadataV8', + StorageEntryModifierLatest: 'StorageEntryModifierV8', + StorageEntryTypeLatest: 'StorageEntryTypeV8' } }; diff --git a/packages/types/src/interfaces/metadata/types.ts b/packages/types/src/interfaces/metadata/types.ts index ea3e6b60de..39eb8fb6ba 100644 --- a/packages/types/src/interfaces/metadata/types.ts +++ b/packages/types/src/interfaces/metadata/types.ts @@ -233,6 +233,9 @@ export interface MapTypeV7 extends MapTypeV6 {} /** MapTypeV7 */ export interface MapTypeV8 extends MapTypeV7 {} +/** MetadataV8 */ +export interface MetadataLatest extends MetadataV8 {} + /** Struct */ export interface MetadataV0 extends Struct { /** OuterEventMetadataV0 */ @@ -249,6 +252,48 @@ export interface MetadataV1 extends Struct { readonly modules: Vec; } +/** Struct */ +export interface MetadataV2 extends Struct { + /** Vec */ + readonly modules: Vec; +} + +/** Struct */ +export interface MetadataV3 extends Struct { + /** Vec */ + readonly modules: Vec; +} + +/** Struct */ +export interface MetadataV4 extends Struct { + /** Vec */ + readonly modules: Vec; +} + +/** Struct */ +export interface MetadataV5 extends Struct { + /** Vec */ + readonly modules: Vec; +} + +/** Struct */ +export interface MetadataV6 extends Struct { + /** Vec */ + readonly modules: Vec; +} + +/** Struct */ +export interface MetadataV7 extends Struct { + /** Vec */ + readonly modules: Vec; +} + +/** Struct */ +export interface MetadataV8 extends Struct { + /** Vec */ + readonly modules: Vec; +} + /** ModuleConstantMetadataV8 */ export interface ModuleConstantMetadataLatest extends ModuleConstantMetadataV8 {} @@ -270,6 +315,9 @@ export interface ModuleConstantMetadataV7 extends ModuleConstantMetadataV6 {} /** ModuleConstantMetadataV7 */ export interface ModuleConstantMetadataV8 extends ModuleConstantMetadataV7 {} +/** ModuleMetadataV8 */ +export interface ModuleMetadataLatest extends ModuleMetadataV8 {} + /** Struct */ export interface ModuleMetadataV0 extends Struct { /** Text */ @@ -292,6 +340,108 @@ export interface ModuleMetadataV1 extends Struct { readonly events: Option>; } +/** Struct */ +export interface ModuleMetadataV2 extends Struct { + /** Text */ + readonly name: Text; + /** Text */ + readonly prefix: Text; + /** Option> */ + readonly storage: Option>; + /** Option> */ + readonly calls: Option>; + /** Option> */ + readonly events: Option>; +} + +/** Struct */ +export interface ModuleMetadataV3 extends Struct { + /** Text */ + readonly name: Text; + /** Text */ + readonly prefix: Text; + /** Option> */ + readonly storage: Option>; + /** Option> */ + readonly calls: Option>; + /** Option> */ + readonly events: Option>; +} + +/** Struct */ +export interface ModuleMetadataV4 extends Struct { + /** Text */ + readonly name: Text; + /** Text */ + readonly prefix: Text; + /** Option> */ + readonly storage: Option>; + /** Option> */ + readonly calls: Option>; + /** Option> */ + readonly events: Option>; +} + +/** Struct */ +export interface ModuleMetadataV5 extends Struct { + /** Text */ + readonly name: Text; + /** Text */ + readonly prefix: Text; + /** Option> */ + readonly storage: Option>; + /** Option> */ + readonly calls: Option>; + /** Option> */ + readonly events: Option>; +} + +/** Struct */ +export interface ModuleMetadataV6 extends Struct { + /** Text */ + readonly name: Text; + /** Text */ + readonly prefix: Text; + /** Option> */ + readonly storage: Option>; + /** Option> */ + readonly calls: Option>; + /** Option> */ + readonly events: Option>; + /** Vec */ + readonly constants: Vec; +} + +/** Struct */ +export interface ModuleMetadataV7 extends Struct { + /** Text */ + readonly name: Text; + /** Option */ + readonly storage: Option; + /** Option> */ + readonly calls: Option>; + /** Option> */ + readonly events: Option>; + /** Vec */ + readonly constants: Vec; +} + +/** Struct */ +export interface ModuleMetadataV8 extends Struct { + /** Text */ + readonly name: Text; + /** Option */ + readonly storage: Option; + /** Option> */ + readonly calls: Option>; + /** Option> */ + readonly events: Option>; + /** Vec */ + readonly constants: Vec; + /** Vec */ + readonly errors: Vec; +} + /** Struct */ export interface OuterDispatchCallV0 extends Struct { /** Text */ @@ -361,6 +511,18 @@ export interface RuntimeModuleMetadataV0 extends Struct { readonly storage: Option; } +/** StorageEntryMetadataV8 */ +export interface StorageEntryMetadataLatest extends StorageEntryMetadataV8 {} + +/** StorageFunctionMetadataV5 */ +export interface StorageEntryMetadataV6 extends StorageFunctionMetadataV5 {} + +/** StorageEntryMetadataV6 */ +export interface StorageEntryMetadataV7 extends StorageEntryMetadataV6 {} + +/** StorageEntryMetadataV7 */ +export interface StorageEntryMetadataV8 extends StorageEntryMetadataV7 {} + /** StorageEntryModifierV8 */ export interface StorageEntryModifierLatest extends StorageEntryModifierV8 {} @@ -373,6 +535,18 @@ export interface StorageEntryModifierV7 extends StorageEntryModifierV6 {} /** StorageEntryModifierV7 */ export interface StorageEntryModifierV8 extends StorageEntryModifierV7 {} +/** StorageEntryTypeV8 */ +export interface StorageEntryTypeLatest extends StorageEntryTypeV8 {} + +/** StorageFunctionTypeV5 */ +export interface StorageEntryTypeV6 extends StorageFunctionTypeV5 {} + +/** StorageEntryTypeV6 */ +export interface StorageEntryTypeV7 extends StorageEntryTypeV6 {} + +/** StorageEntryTypeV7 */ +export interface StorageEntryTypeV8 extends StorageEntryTypeV7 {} + /** Struct */ export interface StorageFunctionMetadataV0 extends Struct { /** Text */ @@ -390,6 +564,62 @@ export interface StorageFunctionMetadataV0 extends Struct { /** StorageFunctionMetadataV0 */ export interface StorageFunctionMetadataV1 extends StorageFunctionMetadataV0 {} +/** Struct */ +export interface StorageFunctionMetadataV2 extends Struct { + /** Text */ + readonly name: Text; + /** StorageFunctionModifierV2 */ + readonly modifier: StorageFunctionModifierV2; + /** StorageFunctionTypeV2 */ + readonly type: StorageFunctionTypeV2; + /** Bytes */ + readonly fallback: Bytes; + /** Vec */ + readonly documentation: Vec; +} + +/** Struct */ +export interface StorageFunctionMetadataV3 extends Struct { + /** Text */ + readonly name: Text; + /** StorageFunctionModifierV3 */ + readonly modifier: StorageFunctionModifierV3; + /** StorageFunctionTypeV3 */ + readonly type: StorageFunctionTypeV3; + /** Bytes */ + readonly fallback: Bytes; + /** Vec */ + readonly documentation: Vec; +} + +/** Struct */ +export interface StorageFunctionMetadataV4 extends Struct { + /** Text */ + readonly name: Text; + /** StorageFunctionModifierV4 */ + readonly modifier: StorageFunctionModifierV4; + /** StorageFunctionTypeV4 */ + readonly type: StorageFunctionTypeV4; + /** Bytes */ + readonly fallback: Bytes; + /** Vec */ + readonly documentation: Vec; +} + +/** Struct */ +export interface StorageFunctionMetadataV5 extends Struct { + /** Text */ + readonly name: Text; + /** StorageFunctionModifierV5 */ + readonly modifier: StorageFunctionModifierV5; + /** StorageFunctionTypeV5 */ + readonly type: StorageFunctionTypeV5; + /** Bytes */ + readonly fallback: Bytes; + /** Vec */ + readonly documentation: Vec; +} + /** Enum */ export interface StorageFunctionModifierV0 extends Enum { /** 0:: Optional */ @@ -430,6 +660,66 @@ export interface StorageFunctionTypeV0 extends Enum { /** StorageFunctionTypeV0 */ export interface StorageFunctionTypeV1 extends StorageFunctionTypeV0 {} +/** Enum */ +export interface StorageFunctionTypeV2 extends Enum { + /** 0:: Plain(PlainTypeV2) */ + readonly isPlain: boolean; + /** PlainTypeV2 */ + readonly asPlain: PlainTypeV2; + /** 1:: Map(MapTypeV2) */ + readonly isMap: boolean; + /** MapTypeV2 */ + readonly asMap: MapTypeV2; +} + +/** Enum */ +export interface StorageFunctionTypeV3 extends Enum { + /** 0:: Plain(PlainTypeV3) */ + readonly isPlain: boolean; + /** PlainTypeV3 */ + readonly asPlain: PlainTypeV3; + /** 1:: Map(MapTypeV3) */ + readonly isMap: boolean; + /** MapTypeV3 */ + readonly asMap: MapTypeV3; + /** 2:: DoubleMap(DoubleMapTypeV3) */ + readonly isDoubleMap: boolean; + /** DoubleMapTypeV3 */ + readonly asDoubleMap: DoubleMapTypeV3; +} + +/** Enum */ +export interface StorageFunctionTypeV4 extends Enum { + /** 0:: Plain(PlainTypeV4) */ + readonly isPlain: boolean; + /** PlainTypeV4 */ + readonly asPlain: PlainTypeV4; + /** 1:: Map(MapTypeV4) */ + readonly isMap: boolean; + /** MapTypeV4 */ + readonly asMap: MapTypeV4; + /** 2:: DoubleMap(DoubleMapTypeV4) */ + readonly isDoubleMap: boolean; + /** DoubleMapTypeV4 */ + readonly asDoubleMap: DoubleMapTypeV4; +} + +/** Enum */ +export interface StorageFunctionTypeV5 extends Enum { + /** 0:: Plain(PlainTypeV5) */ + readonly isPlain: boolean; + /** PlainTypeV5 */ + readonly asPlain: PlainTypeV5; + /** 1:: Map(MapTypeV5) */ + readonly isMap: boolean; + /** MapTypeV5 */ + readonly asMap: MapTypeV5; + /** 2:: DoubleMap(DoubleMapTypeV5) */ + readonly isDoubleMap: boolean; + /** DoubleMapTypeV5 */ + readonly asDoubleMap: DoubleMapTypeV5; +} + /** Struct */ export interface StorageMetadataV0 extends Struct { /** Text */ @@ -437,3 +727,14 @@ export interface StorageMetadataV0 extends Struct { /** Vec */ readonly functions: Vec; } + +/** Struct */ +export interface StorageMetadataV7 extends Struct { + /** Text */ + readonly prefix: Text; + /** Vec */ + readonly items: Vec; +} + +/** StorageMetadataV7 */ +export interface StorageMetadataV8 extends StorageMetadataV7 {} diff --git a/packages/types/src/primitive/StorageKey.ts b/packages/types/src/primitive/StorageKey.ts index aeb9520960..f25519657b 100644 --- a/packages/types/src/primitive/StorageKey.ts +++ b/packages/types/src/primitive/StorageKey.ts @@ -2,9 +2,9 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { StorageEntryMetadataLatest } from '../interfaces/metadata'; import { AnyU8a, Codec, Registry } from '../types'; -import { StorageEntryMetadata as MetaV8 } from '@polkadot/metadata/Metadata/v8/Storage'; import { assert, isFunction, isString, isU8a } from '@polkadot/util'; import Bytes from './Bytes'; @@ -12,7 +12,7 @@ import Bytes from './Bytes'; export interface StorageEntry { (arg?: any): Uint8Array; headKey?: Uint8Array; - meta: MetaV8; + meta: StorageEntryMetadataLatest; method: string; prefix: string; section: string; @@ -72,7 +72,7 @@ export function unwrapStorageType (type: StorageType): string { * constructed by passing in a raw key or a StorageEntry with (optional) arguments. */ export default class StorageKey extends Bytes { - private _meta?: MetaV8; + private _meta?: StorageEntryMetadataLatest; private _method?: string; @@ -122,7 +122,7 @@ export default class StorageKey extends Bytes { throw new Error(`Unable to convert input ${value} to StorageKey`); } - public static getMeta (value: StorageKey | StorageEntry | [StorageEntry, any]): MetaV8 | undefined { + public static getMeta (value: StorageKey | StorageEntry | [StorageEntry, any]): StorageEntryMetadataLatest | undefined { if (value instanceof StorageKey) { return value.meta; } else if (isFunction(value)) { @@ -153,7 +153,7 @@ export default class StorageKey extends Bytes { /** * @description The metadata or `undefined` when not available */ - public get meta (): MetaV8 | undefined { + public get meta (): StorageEntryMetadataLatest | undefined { return this._meta; } diff --git a/packages/types/src/scripts/MetadataMd.ts b/packages/types/src/scripts/MetadataMd.ts index 76b8cfd276..5d76da0ff0 100644 --- a/packages/types/src/scripts/MetadataMd.ts +++ b/packages/types/src/scripts/MetadataMd.ts @@ -2,13 +2,15 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { MetadataLatest, ModuleMetadataLatest } from '../interfaces/metadata'; + import fs from 'fs'; -import Metadata from '@polkadot/metadata'; +import Decorated from '@polkadot/metadata'; import rpcdata from '@polkadot/metadata/Metadata/static'; -import MetadataV8, { ModuleMetadataV8 } from '@polkadot/metadata/Metadata/v8'; import { stringCamelCase, stringLowerFirst } from '@polkadot/util'; import interfaces from '../../../type-jsonrpc/src'; +import { unwrapStorageType } from '../primitive/StorageKey'; import Call from '../primitive/Generic/Call'; import { TypeRegistry } from '../codec'; @@ -66,7 +68,7 @@ function sortByName (a: T, b: T): number { return nameA.localeCompare(nameB); } -function addConstants (metadata: MetadataV8): string { +function addConstants (metadata: MetadataLatest): string { const renderHeading = `## ${ANCHOR_TOP}Constants${DESC_CONSTANTS}`; const orderedSections = metadata.modules.sort(sortByName); let renderAnchors = ''; @@ -94,7 +96,7 @@ function addConstants (metadata: MetadataV8): string { return renderHeading + renderAnchors + sections; } -function addEvents (metadata: MetadataV8): string { +function addEvents (metadata: MetadataLatest): string { const renderHeading = `## ${ANCHOR_TOP}Events${DESC_EVENTS}`; const orderedSections = metadata.modules.sort(sortByName); let renderAnchors = ''; @@ -124,9 +126,9 @@ function addEvents (metadata: MetadataV8): string { return renderHeading + renderAnchors + sections; } -function addExtrinsics (metadata: MetadataV8): string { +function addExtrinsics (metadata: MetadataLatest): string { const renderHeading = `## ${ANCHOR_TOP}Extrinsics${DESC_EXTRINSICS}`; - const orderedSections = metadata.modules.map((i): ModuleMetadataV8 => i).sort(sortByName); + const orderedSections = metadata.modules.map((i): ModuleMetadataLatest => i).sort(sortByName); let renderAnchors = ''; const sections = orderedSections.reduce((md, meta): string => { if (meta.calls.isNone || !meta.calls.unwrap().length) { @@ -154,7 +156,7 @@ function addExtrinsics (metadata: MetadataV8): string { return renderHeading + renderAnchors + sections; } -function addStorage (metadata: MetadataV8): string { +function addStorage (metadata: MetadataLatest): string { const renderHeading = `## ${ANCHOR_TOP}Storage${DESC_STORAGE}`; const orderedSections = metadata.modules.sort(sortByName); let renderAnchors = ''; @@ -179,11 +181,7 @@ function addStorage (metadata: MetadataV8): string { : ''; const doc = func.documentation.reduce((md, doc): string => `${md.length ? `${md} ` : ''}${doc.trim()}`, ''); - let result = ( - func.type.isDoubleMap - ? func.type.asDoubleMap.value - : func.type - ).toString(); + let result = unwrapStorageType(func.type); if (func.modifier.isOptional) { result = `Option<${result}>`; @@ -217,30 +215,31 @@ function writeToRpcMd (): void { writeFile('docs/substrate/rpc.md', addRpc()); } -function writeToConstantsMd (metadata: MetadataV8): void { +function writeToConstantsMd (metadata: MetadataLatest): void { writeFile('docs/substrate/constants.md', addConstants(metadata)); } -function writeToStorageMd (metadata: MetadataV8): void { +function writeToStorageMd (metadata: MetadataLatest): void { const options = { flags: 'r', encoding: 'utf8' }; const data = fs.readFileSync('docs/substrate/storage-known.md', options); writeFile('docs/substrate/storage.md', addStorage(metadata), data); } -function writeToExtrinsicsMd (metadata: MetadataV8): void { +function writeToExtrinsicsMd (metadata: MetadataLatest): void { writeFile('docs/substrate/extrinsics.md', addExtrinsics(metadata)); } -function writeToEventsMd (metadata: MetadataV8): void { +function writeToEventsMd (metadata: MetadataLatest): void { writeFile('docs/substrate/events.md', addEvents(metadata)); } const registry = new TypeRegistry(); -const metadata = new Metadata(registry, rpcdata).metadata.asLatest; +const decorated = new Decorated(registry, rpcdata); +const latest = decorated.metadata.asLatest; writeToRpcMd(); -writeToConstantsMd(metadata); -writeToStorageMd(metadata); -writeToExtrinsicsMd(metadata); -writeToEventsMd(metadata); +writeToConstantsMd(latest); +writeToStorageMd(latest); +writeToExtrinsicsMd(latest); +writeToEventsMd(latest); diff --git a/packages/types/src/scripts/generateTypes/consts.ts b/packages/types/src/scripts/generateTypes/consts.ts index 46bd69d2c9..9118685568 100644 --- a/packages/types/src/scripts/generateTypes/consts.ts +++ b/packages/types/src/scripts/generateTypes/consts.ts @@ -2,8 +2,9 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { ModuleMetadataLatest } from '../../interfaces/metadata'; + import fs from 'fs'; -import { ModuleMetadataV8 } from '@polkadot/metadata/Metadata/v8/Metadata'; import staticData from '@polkadot/metadata/Metadata/static'; import { stringCamelCase } from '@polkadot/util'; @@ -11,7 +12,7 @@ import { Metadata, TypeRegistry } from '../..'; import { createImportCode, createImports, FOOTER, HEADER, indent, setImports, TypeImports } from '../util'; // Generate types for one module -function generateModule (modul: ModuleMetadataV8, imports: TypeImports): string[] { +function generateModule (modul: ModuleMetadataLatest, imports: TypeImports): string[] { if (!modul.constants.length) { return []; } diff --git a/packages/types/src/scripts/generateTypes/query.ts b/packages/types/src/scripts/generateTypes/query.ts index 30f5564005..2e7797df80 100644 --- a/packages/types/src/scripts/generateTypes/query.ts +++ b/packages/types/src/scripts/generateTypes/query.ts @@ -2,20 +2,19 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Registry } from '@polkadot/types/types'; +import { ModuleMetadataLatest, StorageEntryMetadataLatest } from '../../interfaces/metadata'; +import { Registry } from '../../types'; import fs from 'fs'; -import { ModuleMetadataV8 } from '@polkadot/metadata/Metadata/v8/Metadata'; -import { StorageEntryMetadata } from '@polkadot/metadata/Metadata/v8/Storage'; import staticData from '@polkadot/metadata/Metadata/static'; import { stringLowerFirst } from '@polkadot/util'; import { Metadata } from '../..'; +import { TypeRegistry } from '../../codec'; import { createImportCode, createImports, FOOTER, formatType, getSimilarTypes, HEADER, indent, setImports, TypeImports } from '../util'; -import { TypeRegistry } from '@polkadot/types/codec'; // From a storage entry metadata, we return [args, returnType] -function entrySignature (registry: Registry, storageEntry: StorageEntryMetadata, imports: TypeImports): [string, string] { +function entrySignature (registry: Registry, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [string, string] { if (storageEntry.type.isPlain) { setImports(imports, [storageEntry.type.asPlain.toString()]); @@ -57,7 +56,7 @@ function entrySignature (registry: Registry, storageEntry: StorageEntryMetadata, } // Generate types for one storage entry in a module -function generateEntry (registry: Registry, storageEntry: StorageEntryMetadata, imports: TypeImports): string[] { +function generateEntry (registry: Registry, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): string[] { const [args, returnType] = entrySignature(registry, storageEntry, imports); return [ @@ -66,7 +65,7 @@ function generateEntry (registry: Registry, storageEntry: StorageEntryMetadata, } // Generate types for one module -function generateModule (registry: Registry, modul: ModuleMetadataV8, imports: TypeImports): string[] { +function generateModule (registry: Registry, modul: ModuleMetadataLatest, imports: TypeImports): string[] { if (modul.storage.isNone) { return []; }