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
This commit is contained in:
Jaco Greeff
2019-11-22 13:38:20 +01:00
committed by GitHub
parent 4b6b0305e6
commit 8b1a7a8584
42 changed files with 644 additions and 1396 deletions
@@ -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
});
@@ -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,
@@ -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<Text>', [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'
@@ -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;
}
@@ -38,12 +38,12 @@ export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry
export function toLatest<Modules extends Codec> (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<Modules>, true)
).toEqual(
getUniqTypes(registry, metadataV8, true)
getUniqTypes(registry, metadataLatest, true)
);
});
}
@@ -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,
+3 -3
View File
@@ -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);
}
@@ -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<FunctionMetadataV2>'),
events: Option.with('Vec<EventMetadataV2>')
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV2>> {
return this.get('calls') as Option<Vec<FunctionMetadataV2>>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV2>> {
return this.get('events') as Option<Vec<EventMetadataV2>>;
}
/**
* @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<Vec<StorageFunctionMetadata>> {
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
}
}
/**
* @name MetadataV2
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV2 extends Struct implements MetadataInterface<ModuleMetadataV2> {
constructor (registry: Registry, value?: any) {
super(registry, {
modules: Vec.with(ModuleMetadataV2)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV2> {
return this.get('modules') as Vec<ModuleMetadataV2>;
}
}
@@ -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<Text> | 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<Text>'
}, value);
}
/**
* @description The [[Text]] documentation
*/
public get documentation (): Vec<Text> {
return this.get('documentation') as Vec<Text>;
}
/**
* @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;
}
}
@@ -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
};
+3 -3
View File
@@ -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);
}
@@ -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<FunctionMetadataV3>'),
events: Option.with('Vec<EventMetadataV3>')
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV3>> {
return this.get('calls') as Option<Vec<FunctionMetadataV3>>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV3>> {
return this.get('events') as Option<Vec<EventMetadataV3>>;
}
/**
* @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<Vec<StorageFunctionMetadata>> {
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
}
}
/**
* @name MetadataV3
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV3 extends Struct implements MetadataInterface<ModuleMetadataV3> {
constructor (registry: Registry, value?: any) {
super(registry, {
modules: Vec.with(ModuleMetadataV3)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV3> {
return this.get('modules') as Vec<ModuleMetadataV3>;
}
}
@@ -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<Text> | 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<Text>'
}, value);
}
/**
* @description The [[Text]] documentation
*/
public get documentation (): Vec<Text> {
return this.get('documentation') as Vec<Text>;
}
/**
* @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;
}
}
@@ -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
};
+9 -14
View File
@@ -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<StorageFunctionMetadataV4>',
storage.unwrap().map((v): StorageFunctionMetadataV4 => toV4StorageFunction(registry, v))
)
: undefined
})
@@ -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<FunctionMetadataV4>'),
events: Option.with('Vec<EventMetadataV4>')
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV4>> {
return this.get('calls') as Option<Vec<FunctionMetadataV4>>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV4>> {
return this.get('events') as Option<Vec<EventMetadataV4>>;
}
/**
* @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<Vec<StorageFunctionMetadata>> {
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
}
}
/**
* @name MetadataV4
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV4 extends Struct implements MetadataInterface<ModuleMetadataV4> {
constructor (registry: Registry, value?: any) {
super(registry, {
modules: Vec.with(ModuleMetadataV4)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV4> {
return this.get('modules') as Vec<ModuleMetadataV4>;
}
}
@@ -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<Text> | 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<Text>'
}, 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<Text> {
return this.get('documentation') as Vec<Text>;
}
/**
* @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;
}
}
@@ -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
};
+9 -13
View File
@@ -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<string, string> = 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<StorageFunctionMetadataV5>',
storage.unwrap().map((v): StorageFunctionMetadataV5 => toV5StorageFunction(registry, v))
)
: undefined,
calls,
@@ -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<FunctionMetadataV5>'),
events: Option.with('Vec<EventMetadataV5>')
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV5>> {
return this.get('calls') as Option<Vec<FunctionMetadataV5>>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV5>> {
return this.get('events') as Option<Vec<EventMetadataV5>>;
}
/**
* @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<Vec<StorageFunctionMetadata>> {
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
}
}
/**
* @name MetadataV5
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV5 extends Struct implements MetadataInterface<ModuleMetadataV5> {
constructor (registry: Registry, value?: any) {
super(registry, {
modules: Vec.with(ModuleMetadataV5)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV5> {
return this.get('modules') as Vec<ModuleMetadataV5>;
}
}
@@ -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<Text> | 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<Text>'
}, 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<Text> {
return this.get('documentation') as Vec<Text>;
}
/**
* @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;
}
}
@@ -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
};
+4 -5
View File
@@ -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,
@@ -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<FunctionMetadataV6>'),
events: Option.with('Vec<EventMetadataV6>'),
constants: 'Vec<ModuleConstantMetadataV6>'
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV6>> {
return this.get('calls') as Option<Vec<FunctionMetadataV6>>;
}
/**
* @description the module constants
*/
public get constants (): Vec<ModuleConstantMetadataV6> {
return this.get('constants') as Vec<ModuleConstantMetadataV6>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV6>> {
return this.get('events') as Option<Vec<EventMetadataV6>>;
}
/**
* @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<Vec<StorageEntryMetadata>> {
return this.get('storage') as Option<Vec<StorageEntryMetadata>>;
}
}
/**
* @name MetadataV6
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV6 extends Struct implements MetadataInterface<ModuleMetadataV6> {
constructor (registry: Registry, value?: any) {
super(registry, {
modules: Vec.with(ModuleMetadataV6)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV6> {
return this.get('modules') as Vec<ModuleMetadataV6>;
}
}
@@ -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
};
@@ -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
};
+5 -7
View File
@@ -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
})
)
@@ -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<FunctionMetadataV7>'),
events: Option.with('Vec<EventMetadataV7>'),
constants: 'Vec<ModuleConstantMetadataV7>'
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV7>> {
return this.get('calls') as Option<Vec<FunctionMetadataV7>>;
}
/**
* @description the module constants
*/
public get constants (): Vec<ModuleConstantMetadataV7> {
return this.get('constants') as Vec<ModuleConstantMetadataV7>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV7>> {
return this.get('events') as Option<Vec<EventMetadataV7>>;
}
/**
* @description the module name
*/
public get name (): Text {
return this.get('name') as Text;
}
/**
* @description the associated module storage
*/
public get storage (): Option<StorageMetadata> {
return this.get('storage') as Option<StorageMetadata>;
}
}
/**
* @name MetadataV7
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV7 extends Struct implements MetadataInterface<ModuleMetadataV7> {
constructor (registry: Registry, value?: any) {
super(registry, {
modules: Vec.with(ModuleMetadataV7)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV7> {
return this.get('modules') as Vec<ModuleMetadataV7>;
}
}
@@ -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<StorageEntryMetadata> {
return this.get('items') as Vec<StorageEntryMetadata>;
}
/**
* @description the prefix for this module
*/
public get prefix (): Text {
return this.get('prefix') as Text;
}
}
@@ -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
};
+4 -5
View File
@@ -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: [],
@@ -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<FunctionMetadataV8>'),
events: Option.with('Vec<EventMetadataV8>'),
constants: 'Vec<ModuleConstantMetadataV8>',
errors: 'Vec<ErrorMetadataV8>'
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV8>> {
return this.get('calls') as Option<Vec<FunctionMetadataV8>>;
}
/**
* @description the module constants
*/
public get constants (): Vec<ModuleConstantMetadataV8> {
return this.get('constants') as Vec<ModuleConstantMetadataV8>;
}
/**
* @description the module errors
*/
public get errors (): Vec<ErrorMetadataV8> {
return this.get('errors') as Vec<ErrorMetadataV8>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV8>> {
return this.get('events') as Option<Vec<EventMetadataV8>>;
}
/**
* @description the module name
*/
public get name (): Text {
return this.get('name') as Text;
}
/**
* @description the associated module storage
*/
public get storage (): Option<StorageMetadata> {
return this.get('storage') as Option<StorageMetadata>;
}
}
/**
* @name MetadataV8
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV8 extends Struct implements MetadataInterface<ModuleMetadataV8> {
constructor (registry: Registry, value?: any) {
super(registry, {
modules: Vec.with(ModuleMetadataV8)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV8> {
return this.get('modules') as Vec<ModuleMetadataV8>;
}
}
@@ -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';
@@ -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
};