Rework uniqTypes without duplication (#1316)

* Rework uniqTypes without  duplication

* Extra info for vX -> v7 conversion

* Add vX to naming

* Rework unwrap return

* Ignore gathering unique for v0

* Fix getUniq for V0 (well, def. throw-away, but anyway...)

* compareMap cleanup

* Cleanup author extraction

* Add modules via Struct.with (Metadata)

* Revert "Add modules via Struct.with (Metadata)"

This reverts commit 0666c3014cf840fb4ab26a5231cdf67dbe977bd7.

* Consistency in injected vs defined classes (Metadata)

* Add isTrue/isFalse to Bool

* Meta PlainType/MapType in registry

* Fix wrong v6 imports

* Extract storage modifier

* Split additional Metadata classes into interfaces

* Minor cleanups in type naming

* Static json renames

* Convert most V0 classes to interfaces

* Additional meta classes to interfaces

* No classes for Metadata V0 & V1 anymore

* Rename json imports

* Base cleanups

* Add polkadot static
This commit is contained in:
Jaco Greeff
2019-08-18 15:01:21 +02:00
committed by GitHub
parent b685b29e8c
commit c7c76f6edb
75 changed files with 12231 additions and 7922 deletions
@@ -2,13 +2,13 @@
// 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 '../interfaces/metadata';
import { assert } from '@polkadot/util';
import Enum from '../codec/Enum';
import Struct from '../codec/Struct';
import MagicNumber from './MagicNumber';
import MetadataV0 from './v0';
import MetadataV1 from './v1';
import MetadataV2 from './v2';
import MetadataV3 from './v3';
import MetadataV4 from './v4';
@@ -22,6 +22,7 @@ import v3ToV4 from './v3/toV4';
import v4ToV5 from './v4/toV5';
import v5ToV6 from './v5/toV6';
import v6ToV7 from './v6/toV7';
import { getUniqTypes } from './util';
type MetaMapped = MetadataV0 | MetadataV1 | MetadataV2 | MetadataV3 | MetadataV4 | MetadataV5 | MetadataV6 | MetadataV7;
type MetaVersions = 1 | 2 | 3 | 4 | 5 | 6 | 7;
@@ -30,14 +31,14 @@ type MetaAsX = 'asV0' | 'asV1' | 'asV2' | 'asV3' | 'asV4' | 'asV5' | 'asV6';
class MetadataEnum extends Enum {
public constructor (value?: any) {
super({
MetadataV0, // once rolled-out, can replace this with MetadataDeprecated
MetadataV1, // once rolled-out, can replace this with MetadataDeprecated
MetadataV2, // once rolled-out, can replace this with MetadataDeprecated
MetadataV3, // once rolled-out, can replace this with MetadataDeprecated
MetadataV4, // once rolled-out, can replace this with MetadataDeprecated
MetadataV5, // once rolled-out, can replace this with MetadataDeprecated
MetadataV6, // once rolled-out, can replace this with MetadataDeprecated
MetadataV7
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
}, value);
}
@@ -124,63 +125,56 @@ class MetadataEnum extends Enum {
* @description `true` if V0
*/
public get isV0 (): boolean {
return this.type === 'MetadataV0';
return this.type === 'V0';
}
/**
* @description `true` if V1
*/
public get isV1 (): boolean {
return this.type === 'MetadataV1';
return this.type === 'V1';
}
/**
* @description `true` if V2
*/
public get isV2 (): boolean {
return this.type === 'MetadataV2';
return this.type === 'V2';
}
/**
* @description `true` if V3
*/
public get isV3 (): boolean {
return this.type === 'MetadataV3';
return this.type === 'V3';
}
/**
* @description `true` if V4
*/
public get isV4 (): boolean {
return this.type === 'MetadataV4';
return this.type === 'V4';
}
/**
* @description `true` if V5
*/
public get isV5 (): boolean {
return this.type === 'MetadataV5';
return this.type === 'V5';
}
/**
* @description `true` if V6
*/
public get isV6 (): boolean {
return this.type === 'MetadataV6';
return this.type === 'V6';
}
/**
* @description `true` if V7
*/
public get isV7 (): boolean {
return this.type === 'MetadataV7';
}
/**
* @description The version this metadata represents
*/
public get version (): number {
return this.index;
return this.type === 'V7';
}
}
@@ -200,7 +194,7 @@ export default class MetadataVersioned extends Struct {
}
private assertVersion (version: number): boolean {
assert(this.metadata.version <= version, `Cannot convert metadata from v${this.metadata.version} to v${version}`);
assert(this.version <= version, `Cannot convert metadata from v${this.version} to v${version}`);
return this.version === version;
}
@@ -307,6 +301,6 @@ export default class MetadataVersioned extends Struct {
}
public getUniqTypes (throwError: boolean): string[] {
return this.asLatest.getUniqTypes(throwError);
return getUniqTypes(this.asLatest, throwError);
}
}
-1
View File
@@ -7,5 +7,4 @@ import { Codec } from '../types';
export interface MetadataInterface<Modules extends Codec> extends Codec {
modules: Vec<Modules>;
getUniqTypes (throwError: boolean): string[];
}
@@ -0,0 +1,173 @@
// Copyright 2017-2019 @polkadot/types 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 { Codec } from '../../types';
import { Option, Vec } from '../../codec';
import { Text, Type } from '../../primitive';
import flattenUniq from './flattenUniq';
import validateTypes from './validateTypes';
type Arg = { type: Type } & Codec;
type Item = {
type: {
isDoubleMap?: boolean;
isMap: boolean;
asDoubleMap?: {
key1: Text;
key2: Text;
value: Text;
};
asMap: {
key: Text;
value: Text;
};
asType: Text;
};
} & Codec;
type Storage = Option<Vec<Item> | {
// v0
functions?: Vec<Item>;
// V7
items?: Vec<Item>;
} & Codec>;
type Call = { args: Vec<Arg> } & Codec;
type Calls = Option<Vec<Call>>;
type Event = { args: Vec<Type> } & Codec;
type Events = Option<Vec<Event>>;
type Module = {
// V0
module?: {
call: {
functions: Vec<Call>;
};
};
// V1+
calls?: Calls;
// V6+
constants?: Vec<{ type: Text } & Codec>;
events?: Events;
storage?: Storage;
} & Codec;
interface ExtractionMetadata {
modules: Vec<Module>;
// V0
outerEvent?: {
events: Vec<[Text, Vec<Event>] & Codec>;
};
}
function unwrapCalls (mod: Module): Call[] {
return mod.calls
? mod.calls.unwrapOr([])
// V0
: mod.module
? mod.module.call.functions
: [];
}
function getCallNames ({ modules }: ExtractionMetadata): string[][][] {
return modules.map((mod): string[][] =>
unwrapCalls(mod).map(({ args }): string[] =>
args.map((arg): string =>
arg.type.toString()
)
)
);
}
function getConstantNames ({ modules }: ExtractionMetadata): string[][] {
return modules.map(({ constants }): string[] =>
constants
? constants.map((constant): string =>
constant.type.toString()
)
: []
);
}
function unwrapEvents (events?: Events): Event[] {
if (!events) {
return [];
}
return events.unwrapOr([]);
}
function getEventNames ({ modules, outerEvent }: ExtractionMetadata): string[][][] {
const mapArg = ({ args }: Event): string[] =>
args.map((arg): string =>
arg.toString()
);
// V0
if (outerEvent) {
return outerEvent.events.map(([, events]): string[][] =>
events.map(mapArg)
);
}
// V1+
return modules.map(({ events }): string[][] =>
unwrapEvents(events).map(mapArg)
);
}
function unwrapStorage (storage?: Storage): Item[] {
if (!storage) {
return [];
}
const data = storage.unwrapOr([]);
return Array.isArray(data)
? data
: (data.items || data.functions) as Item[];
}
function getStorageNames ({ modules }: ExtractionMetadata): string[][][] {
return modules.map(({ storage }): string[][] =>
unwrapStorage(storage).map(({ type }): string[] => {
if (type.isDoubleMap && type.asDoubleMap) {
return [
type.asDoubleMap.key1.toString(),
type.asDoubleMap.key2.toString(),
type.asDoubleMap.value.toString()
];
} else if (type.isMap) {
return [
type.asMap.key.toString(),
type.asMap.value.toString()
];
} else {
return [
type.asType.toString()
];
}
})
);
}
export default function getUniqTypes (meta: ExtractionMetadata, throwError: boolean): string[] {
const types = flattenUniq([
getCallNames(meta),
getConstantNames(meta),
getEventNames(meta),
getStorageNames(meta)
]);
validateTypes(types, throwError);
return types;
}
@@ -3,4 +3,5 @@
// of the Apache-2.0 license. See the LICENSE file for details.
export { default as flattenUniq } from './flattenUniq';
export { default as getUniqTypes } from './getUniqTypes';
export { default as validateTypes } from './validateTypes';
+10 -7
View File
@@ -11,15 +11,16 @@ import Metadata from '../Metadata';
import Call from '../../primitive/Generic/Call';
import { MetadataInterface } from '../types';
import { Codec } from '../../types';
import getUniqTypes from './getUniqTypes';
/**
* Given the static `rpcData` and the `latestSubstrate` JSON file, Metadata
* should decode `rpcData` and output `latestSubstrate`.
* Given the static `rpcData` and the `staticSubstrate` JSON file, Metadata
* should decode `rpcData` and output `staticSubstrate`.
*/
export function decodeLatestSubstrate<Modules extends Codec> (
version: number,
rpcData: string,
latestSubstrate: object
staticSubstrate: object
): void {
it('decodes latest substrate properly', (): void => {
const metadata = new Metadata(rpcData);
@@ -28,7 +29,7 @@ export function decodeLatestSubstrate<Modules extends Codec> (
expect(metadata.version).toBe(version);
expect((metadata[`asV${version}` as keyof Metadata] as unknown as MetadataInterface<Modules>).modules.length).not.toBe(0);
expect(metadata.toJSON()).toEqual(latestSubstrate);
expect(metadata.toJSON()).toEqual(staticSubstrate);
});
}
@@ -37,13 +38,15 @@ export function decodeLatestSubstrate<Modules extends Codec> (
* unique types.
*/
export function toV7<Modules extends Codec> (version: number, rpcData: string): void {
it('converts to V7', (): void => {
it(`converts v${version} to v7`, (): void => {
const metadata = new Metadata(rpcData)[`asV${version}` as keyof Metadata];
const metadataV7 = new Metadata(rpcData).asV7;
expect(
(metadata as unknown as MetadataInterface<Modules>).getUniqTypes(true)
).toEqual(metadataV7.getUniqTypes(true));
getUniqTypes(metadata as unknown as MetadataInterface<Modules>, true)
).toEqual(
getUniqTypes(metadataV7, true)
);
});
}
-53
View File
@@ -1,53 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 { EventMetadataV0 } from '../../interfaces/metadata/types';
import Struct from '../../codec/Struct';
import Tuple from '../../codec/Tuple';
import Vec from '../../codec/Vec';
import Text from '../../primitive/Text';
export class OuterEventEventMetadata extends Tuple {
public constructor (value?: any) {
super(['Text', 'Vec<EventMetadataV0>'], value);
}
/**
* @description The [[EventMetadata]]
*/
public get events (): Vec<EventMetadataV0> {
return this[1] as Vec<EventMetadataV0>;
}
/**
* @description The name of the section
*/
public get name (): Text {
return this[0] as Text;
}
}
export class OuterEventMetadata extends Struct {
public constructor (value?: any) {
super({
name: Text,
events: Vec.with(OuterEventEventMetadata)
}, value);
}
/**
* @description The [[OuterEventEventMetadata]]
*/
public get events (): Vec<OuterEventEventMetadata> {
return this.get('events') as Vec<OuterEventEventMetadata>;
}
/**
* @description The name of the event
*/
public get name (): Text {
return this.get('name') as Text;
}
}
@@ -2,16 +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 MetadataV0 from './';
import { createType } from '../../codec';
import Metadata from '../';
import latestSubstrateV0 from './latest.substrate.v0.json';
import latestSubstrateV0 from './static-substrate.json';
import rpcData from './static';
import { defaultValues, toV7 } from '../util/testUtil';
describe('Metadata', (): void => {
it('works with fallback', (): void => {
const metadata = new Metadata(rpcData);
const metadataV0 = new MetadataV0(rpcData);
const metadataV0 = createType('MetadataV0', rpcData);
expect(metadata.asV0.toString()).toEqual(metadataV0.toString());
});
-114
View File
@@ -1,114 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 { OuterDispatchMetadataV0, OuterDispatchCallV0 } from '../../interfaces/metadata/types';
import { MetadataInterface } from '../types';
import { hexToU8a, isHex, isU8a } from '@polkadot/util';
import Compact from '../../codec/Compact';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import { flattenUniq, validateTypes } from '../util';
import { OuterEventMetadata, OuterEventEventMetadata } from './Events';
import { RuntimeModuleMetadataV0 } from './Modules';
// Decodes the runtime metadata as passed through from the `state_getMetadata` call.
/**
* @name MetadataV0
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV0 extends Struct implements MetadataInterface<RuntimeModuleMetadataV0> {
public constructor (value?: any) {
super({
outerEvent: OuterEventMetadata,
modules: Vec.with(RuntimeModuleMetadataV0),
outerDispatch: 'OuterDispatchMetadataV0'
}, MetadataV0.decodeMetadata(value));
}
public static decodeMetadata (value: string | Uint8Array | object): object | Uint8Array {
if (isHex(value)) {
// We receive this as an hex in the JSON output from the Node.
// Convert to u8a and use the U8a version to do the actual parsing.
return MetadataV0.decodeMetadata(hexToU8a(value));
} else if (isU8a(value)) {
// HACK 13 Oct 2018 - For current running BBQ nodes, Metadata is not properly
// encoded, it does not have a length prefix. For latest substrate master, it
// is properly encoded. Here we pull the prefix, check it agianst the length -
// if matches, then we have the length, otherwise we assume it is an older node
// and use the whole buffer
const [offset, length] = Compact.decodeU8a(value);
return value.length === (offset + length.toNumber())
? value.subarray(offset)
: value;
}
// Decode as normal struct
return value;
}
/**
* @description Wrapped [[OuterDispatchCall]]
*/
public get calls (): Vec<OuterDispatchCallV0> {
return (this.get('outerDispatch') as OuterDispatchMetadataV0).calls;
}
/**
* @description Wrapped [[OuterEventEventMetadata]]
*/
public get events (): Vec<OuterEventEventMetadata> {
return (this.get('outerEvent') as OuterEventMetadata).events;
}
/**
* @description Wrapped [[RuntimeModuleMetadata]]
*/
public get modules (): Vec<RuntimeModuleMetadataV0> {
return this.get('modules') as Vec<RuntimeModuleMetadataV0>;
}
private get argNames (): string[][][] {
return this.modules.map(({ module: { call: { functions } } }): string[][] =>
functions.map(({ args }): string[] =>
args.map((arg): string => arg.type.toString())
)
);
}
private get eventNames (): string[][][] {
return this.events.map((modul): string[][] =>
modul.events.map((event): string[] =>
event.args.map((argument): string => argument.toString())
)
);
}
private get storageNames (): string[][][] {
return this.modules.map((modul): string[][] =>
modul.storage.isSome
? modul.storage.unwrap().functions.map(({ type }): string[] =>
type.isMap
? [type.asMap.key.toString(), type.asMap.value.toString()]
: [type.asType.toString()]
)
: []
);
}
/**
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
*/
public getUniqTypes (throwError: boolean): string[] {
const types = flattenUniq([this.argNames, this.eventNames, this.storageNames]);
validateTypes(types, throwError);
return types;
}
}
-42
View File
@@ -1,42 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 { ModuleMetadataV0 } from '../../interfaces/types';
import Option from '../../codec/Option';
import Struct from '../../codec/Struct';
import Text from '../../primitive/Text';
import { StorageMetadataV0 } from './Storage';
export class RuntimeModuleMetadataV0 extends Struct {
public constructor (value?: any) {
super({
prefix: Text,
module: 'ModuleMetadataV0',
storage: Option.with(StorageMetadataV0)
}, value);
}
/**
* @description The [[ModuleMetadataV0]]
*/
public get module (): ModuleMetadataV0 {
return this.get('module') as ModuleMetadataV0;
}
/**
* @description The prefix
*/
public get prefix (): Text {
return this.get('prefix') as Text;
}
/**
* @description The optional [[StorageMetadataV0]]
*/
public get storage (): Option<StorageMetadataV0> {
return this.get('storage') as Option<StorageMetadataV0>;
}
}
-205
View File
@@ -1,205 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 { AnyNumber } from '../../types';
import { assert } from '@polkadot/util';
import Enum from '../../codec/Enum';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Bytes from '../../primitive/Bytes';
import Text from '../../primitive/Text';
import Type from '../../primitive/Type';
export class StorageFunctionModifier extends Enum {
public constructor (value?: any) {
super(['Optional', 'Default', 'Required'], value);
}
/**
* @description `true` if the storage entry is optional
*/
public get isOptional (): boolean {
return this.toNumber() === 0;
}
public toJSON (): string {
// This looks prettier in the generated JSON
return this.toString();
}
}
export class MapType extends Struct {
private _isLinked = false;
public constructor (value?: any) {
super({
key: Type,
value: Type
}, value);
if (value && value.isLinked) {
this._isLinked = true;
}
}
/**
* @description The mapped key as [[Type]]
*/
public get key (): Type {
return this.get('key') as Type;
}
/**
* @description The mapped value as [[Type]]
*/
public get value (): Type {
return this.get('value') as Type;
}
/**
* @description Is this an enumerable linked map
*/
public get isLinked (): boolean {
return this._isLinked;
}
}
export class PlainType extends Type {
}
export class StorageFunctionType extends Enum {
public constructor (value?: any, index?: number) {
super({
PlainType,
MapType
}, value, index);
}
/**
* @description The value as a mapped value
*/
public get asMap (): MapType {
assert(this.isMap, `Cannot convert '${this.type}' via asMap`);
return this.value as MapType;
}
/**
* @description The value as a [[Type]] value
*/
public get asType (): PlainType {
assert(this.isPlainType, `Cannot convert '${this.type}' via asType`);
return this.value as PlainType;
}
/**
* @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 isPlainType (): boolean {
return this.toNumber() === 0;
}
/**
* @description Returns the string representation of the value
*/
public toString (): string {
if (this.isMap) {
if (this.asMap.isLinked) {
return `(${this.asMap.value.toString()}, Linkage<${this.asMap.key.toString()}>)`;
}
return this.asMap.value.toString();
}
return this.asType.toString();
}
}
export interface StorageFunctionMetadataValue {
name: string | Text;
modifier: StorageFunctionModifier | AnyNumber;
type: StorageFunctionType;
fallback: Bytes;
documentation: Vec<Text> | string[];
}
export class StorageFunctionMetadata extends Struct {
public constructor (value?: StorageFunctionMetadataValue | Uint8Array) {
super({
name: Text,
modifier: StorageFunctionModifier,
type: StorageFunctionType,
fallback: Bytes,
documentation: Vec.with(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 (): StorageFunctionModifier {
return this.get('modifier') as StorageFunctionModifier;
}
/**
* @description The [[StorageFunctionType]]
*/
public get type (): StorageFunctionType {
return this.get('type') as StorageFunctionType;
}
}
export class StorageMetadataV0 extends Struct {
public constructor (value?: any) {
super({
prefix: Text,
functions: Vec.with(StorageFunctionMetadata)
}, value);
}
/**
* @description The [[StorageFunctionMetadata]] for the section
*/
public get functions (): Vec<StorageFunctionMetadata> {
return this.get('functions') as Vec<StorageFunctionMetadata>;
}
/**
* @description The section prefix
*/
public get prefix (): Text {
return this.get('prefix') as Text;
}
}
-7
View File
@@ -1,7 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 MetadataV0 from './Metadata';
export default MetadataV0;
+23 -29
View File
@@ -3,56 +3,50 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { EventMetadataV1, FunctionMetadataV1 } from '../../interfaces/metadata/types';
import { EventMetadataV1, FunctionMetadataV1, MetadataV0, MetadataV1, ModuleMetadataV1, RuntimeModuleMetadataV0, StorageFunctionMetadataV1 } from '../../interfaces/metadata';
import { stringUpperFirst } from '@polkadot/util';
import { Option, Vec } from '../../codec';
import MetadataV0 from './Metadata';
import { RuntimeModuleMetadataV0 } from './Modules';
import { createType, Option, Vec } from '../../codec';
import { Text } from '../../primitive';
import MetadataV1, { ModuleMetadata as ModuleMetadataV1 } from '../v1/Metadata';
import { StorageFunctionMetadata } from '../v1/Storage';
function toV1Calls (modul: RuntimeModuleMetadataV0): Option<FunctionMetadataV1> {
return modul.module.call.functions.length === 0
? new Option(Vec.with('FunctionMetadataV1'))
: new Option(Vec.with('FunctionMetadataV1'), modul.module.call.functions);
function toV1Calls ({ module: { call: { functions } } }: RuntimeModuleMetadataV0): Option<FunctionMetadataV1> {
return functions.length
? new Option(Vec.with('FunctionMetadataV1'), functions)
: new Option(Vec.with('FunctionMetadataV1'));
}
function toV1Events (metadataV0: MetadataV0, prefix: Text): Option<EventMetadataV1> {
const events = metadataV0.events.find((event): boolean => event.name.eq(prefix));
const events = metadataV0.outerEvent.events.find((event): boolean => event[0].eq(prefix));
return events
? new Option(Vec.with('EventMetadataV1'), events.events)
? new Option(Vec.with('EventMetadataV1'), events[1])
: new Option(Vec.with('EventMetadataV1'));
}
function toV1Storage (modul: RuntimeModuleMetadataV0): Option<StorageFunctionMetadata> {
return modul.storage.isNone
? new Option(Vec.with(StorageFunctionMetadata))
: new Option(
Vec.with(StorageFunctionMetadata),
modul.storage.unwrap().functions
);
function toV1Storage ({ storage }: RuntimeModuleMetadataV0): Option<StorageFunctionMetadataV1> {
return storage.isSome
? new Option('Vec<StorageFunctionMetadataV1>', storage.unwrap().functions)
: new Option('Vec<StorageFunctionMetadataV1>');
}
/**
* Function that converts MetadataV0 to MetadataV1
*/
export default function toV1 (metadataV0: MetadataV0): MetadataV1 {
return new MetadataV1({
modules: metadataV0.modules.map((modul): ModuleMetadataV1 => {
return createType('MetadataV1', {
modules: metadataV0.modules.map((mod): ModuleMetadataV1 => {
// The prefix of this module (capitalized)
const prefix = modul.storage.isSome
? modul.storage.unwrap().prefix.toString()
: stringUpperFirst(modul.prefix.toString()); // If this module doesn't have storage, we just assume the prefix is the name capitalized
const prefix = mod.storage.isSome
? mod.storage.unwrap().prefix.toString()
: stringUpperFirst(mod.prefix.toString()); // If this module doesn't have storage, we just assume the prefix is the name capitalized
return new ModuleMetadataV1({
name: modul.prefix, // Not capitalized
return createType('ModuleMetadataV1', {
name: mod.prefix, // Not capitalized
prefix, // Capitalized
storage: toV1Storage(modul),
calls: toV1Calls(modul),
events: toV1Events(metadataV0, modul.prefix)
storage: toV1Storage(mod),
calls: toV1Calls(mod),
events: toV1Events(metadataV0, mod.prefix)
});
})
});
@@ -2,12 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import latestSubstrate from './latest.substrate.v1.json';
import staticSubstrate from './static-substrate.json';
import rpcData from './static';
import { decodeLatestSubstrate, defaultValues, toV7 } from '../util/testUtil';
describe('MetadataV1', (): void => {
decodeLatestSubstrate(1, rpcData, latestSubstrate);
decodeLatestSubstrate(1, rpcData, staticSubstrate);
toV7(1, rpcData);
-129
View File
@@ -1,129 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 { EventMetadataV1, FunctionMetadataV1 } from '../../interfaces/metadata/types';
import { MetadataInterface } from '../types';
import Option from '../../codec/Option';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Text from '../../primitive/Text';
import { flattenUniq, validateTypes } from '../util';
import { StorageFunctionMetadata } from './Storage';
/**
* @name ModuleMetadata
* @description
* The definition of a module in the system
*/
export class ModuleMetadata extends Struct {
public constructor (value?: any) {
super({
name: Text,
prefix: Text,
storage: Option.with(Vec.with(StorageFunctionMetadata)),
calls: Option.with(Vec.with('FunctionMetadataV1')),
events: Option.with(Vec.with('EventMetadataV1'))
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV1>> {
return this.get('calls') as Option<Vec<FunctionMetadataV1>>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV1>> {
return this.get('events') as Option<Vec<EventMetadataV1>>;
}
/**
* @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 MetadataV1
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV1 extends Struct implements MetadataInterface<ModuleMetadata> {
public constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadata)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadata> {
return this.get('modules') as Vec<ModuleMetadata>;
}
private get callNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.calls.isNone
? []
: mod.calls.unwrap().map((fn): string[] =>
fn.args.map((arg): string => arg.type.toString())
)
);
}
private get eventNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.events.isNone
? []
: mod.events.unwrap().map((event): string[] =>
event.args.map((arg): string => arg.toString())
)
);
}
private get storageNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.storage.isNone
? []
: mod.storage.unwrap().map((fn): string[] =>
fn.type.isMap
? [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()]
: [fn.type.asType.toString()]
)
);
}
/**
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
*/
public getUniqTypes (throwError: boolean): string[] {
const types = flattenUniq([this.callNames, this.eventNames, this.storageNames]);
validateTypes(types, throwError);
return types;
}
}
-20
View File
@@ -1,20 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 {
MapType,
PlainType,
StorageFunctionModifier,
StorageFunctionType,
StorageFunctionMetadata
} from '../v0/Storage';
// Re-export classes that haven't changed between V0 and V1
export {
MapType,
PlainType,
StorageFunctionModifier,
StorageFunctionType,
StorageFunctionMetadata
};
-11
View File
@@ -1,11 +0,0 @@
// Copyright 2017-2019 @polkadot/types 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 MetadataV1, { ModuleMetadata as ModuleMetadataV1 } from './Metadata';
export default MetadataV1;
export {
ModuleMetadataV1
};
+2 -1
View File
@@ -2,7 +2,8 @@
// 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 './Metadata';
import { MetadataV1 } from '../../interfaces/metadata';
import MetadataV2 from '../v2';
export default function toV2 (metadataV1: MetadataV1): MetadataV2 {
@@ -2,12 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import latestSubstrate from './latest.substrate.v2.json';
import staticSubstrate from './static-substrate.json';
import rpcData from './static';
import { decodeLatestSubstrate, defaultValues, toV7 } from '../util/testUtil';
describe('MetadataV2', (): void => {
decodeLatestSubstrate(2, rpcData, latestSubstrate);
decodeLatestSubstrate(2, rpcData, staticSubstrate);
toV7(2, rpcData);
+11 -55
View File
@@ -2,30 +2,29 @@
// 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 '../../interfaces/metadata/types';
import { EventMetadataV2, FunctionMetadataV2 } from '../../interfaces/metadata';
import { MetadataInterface } from '../types';
import Option from '../../codec/Option';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Text from '../../primitive/Text';
import { flattenUniq, validateTypes } from '../util';
import { StorageFunctionMetadata } from './Storage';
/**
* @name ModuleMetadata
* @name ModuleMetadataV2
* @description
* The definition of a module in the system
*/
export class ModuleMetadata extends Struct {
export class ModuleMetadataV2 extends Struct {
public constructor (value?: any) {
super({
name: Text,
prefix: Text,
name: 'Text',
prefix: 'Text',
storage: Option.with(Vec.with(StorageFunctionMetadata)),
calls: Option.with(Vec.with('FunctionMetadataV2')),
events: Option.with(Vec.with('EventMetadataV2'))
calls: Option.with('Vec<FunctionMetadataV2>'),
events: Option.with('Vec<EventMetadataV2>')
}, value);
}
@@ -70,60 +69,17 @@ export class ModuleMetadata extends Struct {
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV2 extends Struct implements MetadataInterface<ModuleMetadata> {
export default class MetadataV2 extends Struct implements MetadataInterface<ModuleMetadataV2> {
public constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadata)
modules: Vec.with(ModuleMetadataV2)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadata> {
return this.get('modules') as Vec<ModuleMetadata>;
}
private get callNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.calls.isNone
? []
: mod.calls.unwrap().map((fn): string[] =>
fn.args.map((arg): string => arg.type.toString())
)
);
}
private get eventNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.events.isNone
? []
: mod.events.unwrap().map((event): string[] =>
event.args.map((arg): string => arg.toString())
)
);
}
private get storageNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.storage.isNone
? []
: mod.storage.unwrap().map((fn): string[] =>
fn.type.isMap
? [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()]
: [fn.type.asType.toString()]
)
);
}
/**
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
*/
public getUniqTypes (throwError: boolean): string[] {
const types = flattenUniq([this.callNames, this.eventNames, this.storageNames]);
validateTypes(types, throwError);
return types;
public get modules (): Vec<ModuleMetadataV2> {
return this.get('modules') as Vec<ModuleMetadataV2>;
}
}
+16 -55
View File
@@ -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 { MapTypeV2, PlainTypeV2, StorageFunctionModifierV2 } from '../../interfaces/metadata';
import { AnyNumber } from '../../types';
import { assert } from '@polkadot/util';
@@ -9,73 +10,33 @@ import { assert } from '@polkadot/util';
import Enum from '../../codec/Enum';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Bool from '../../primitive/Bool';
import Bytes from '../../primitive/Bytes';
import Text from '../../primitive/Text';
import Type from '../../primitive/Type';
import { PlainType, StorageFunctionModifier } from '../v1/Storage';
// Re-export classes that haven't changed between V1 and V2
export {
PlainType,
StorageFunctionModifier
};
export class MapType extends Struct {
public constructor (value?: any) {
super({
key: Type,
value: Type,
isLinked: Bool
}, value);
}
/**
* @description The mapped key as [[Type]]
*/
public get key (): Type {
return this.get('key') as Type;
}
/**
* @description The mapped value as [[Type]]
*/
public get value (): Type {
return this.get('value') as Type;
}
/**
* @description Is this an enumerable linked map
*/
public get isLinked (): boolean {
return (this.get('isLinked') as Bool).valueOf();
}
}
export class StorageFunctionType extends Enum {
public constructor (value?: any, index?: number) {
super({
PlainType,
MapType
Type: 'PlainTypeV2',
Map: 'MapTypeV2'
}, value, index);
}
/**
* @description The value as a mapped value
*/
public get asMap (): MapType {
public get asMap (): MapTypeV2 {
assert(this.isMap, `Cannot convert '${this.type}' via asMap`);
return this.value as MapType;
return this.value as MapTypeV2;
}
/**
* @description The value as a [[Type]] value
*/
public get asType (): PlainType {
public get asType (): PlainTypeV2 {
assert(this.isPlainType, `Cannot convert '${this.type}' via asType`);
return this.value as PlainType;
return this.value as PlainTypeV2;
}
/**
@@ -97,7 +58,7 @@ export class StorageFunctionType extends Enum {
*/
public toString (): string {
if (this.isMap) {
if (this.asMap.isLinked) {
if (this.asMap.linked.isTrue) {
return `(${this.asMap.value.toString()}, Linkage<${this.asMap.key.toString()}>)`;
}
@@ -110,7 +71,7 @@ export class StorageFunctionType extends Enum {
export interface StorageFunctionMetadataValue {
name: string | Text;
modifier: StorageFunctionModifier | AnyNumber;
modifier: StorageFunctionModifierV2 | AnyNumber;
type: StorageFunctionType;
fallback: Bytes;
documentation: Vec<Text> | string[];
@@ -124,11 +85,11 @@ export interface StorageFunctionMetadataValue {
export class StorageFunctionMetadata extends Struct {
public constructor (value?: StorageFunctionMetadataValue | Uint8Array) {
super({
name: Text,
modifier: StorageFunctionModifier,
name: 'Text',
modifier: 'StorageFunctionModifierV2',
type: StorageFunctionType,
fallback: Bytes,
documentation: Vec.with(Text)
fallback: 'Bytes',
documentation: 'Vec<Text>'
}, value);
}
@@ -147,10 +108,10 @@ export class StorageFunctionMetadata extends Struct {
}
/**
* @description The [[MetadataArgument]] for arguments
* @description The [[StorageFunctionModifierV2]] for arguments
*/
public get modifier (): StorageFunctionModifier {
return this.get('modifier') as StorageFunctionModifier;
public get modifier (): StorageFunctionModifierV2 {
return this.get('modifier') as StorageFunctionModifierV2;
}
/**
+1 -1
View File
@@ -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 MetadataV2, { ModuleMetadata as ModuleMetadataV2 } from './Metadata';
import MetadataV2, { ModuleMetadataV2 } from './Metadata';
export default MetadataV2;
@@ -2,12 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import latestSubstrate from './latest.substrate.v3.json';
import staticSubstrate from './static-substrate.json';
import rpcData from './static';
import { decodeLatestSubstrate, defaultValues, toV7 } from '../util/testUtil';
describe('MetadataV3', (): void => {
decodeLatestSubstrate(3, rpcData, latestSubstrate);
decodeLatestSubstrate(3, rpcData, staticSubstrate);
toV7(3, rpcData);
+11 -59
View File
@@ -2,30 +2,29 @@
// 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 '../../interfaces/metadata/types';
import { EventMetadataV3, FunctionMetadataV3 } from '../../interfaces/metadata';
import { MetadataInterface } from '../types';
import Option from '../../codec/Option';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Text from '../../primitive/Text';
import { flattenUniq, validateTypes } from '../util';
import { StorageFunctionMetadata } from './Storage';
/**
* @name ModuleMetadata
* @name ModuleMetadataV3
* @description
* The definition of a module in the system
*/
export class ModuleMetadata extends Struct {
export class ModuleMetadataV3 extends Struct {
public constructor (value?: any) {
super({
name: Text,
prefix: Text,
name: 'Text',
prefix: 'Text',
storage: Option.with(Vec.with(StorageFunctionMetadata)),
calls: Option.with(Vec.with('FunctionMetadataV3')),
events: Option.with(Vec.with('EventMetadataV3'))
calls: Option.with('Vec<FunctionMetadataV3>'),
events: Option.with('Vec<EventMetadataV3>')
}, value);
}
@@ -70,64 +69,17 @@ export class ModuleMetadata extends Struct {
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV3 extends Struct implements MetadataInterface<ModuleMetadata> {
export default class MetadataV3 extends Struct implements MetadataInterface<ModuleMetadataV3> {
public constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadata)
modules: Vec.with(ModuleMetadataV3)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadata> {
return this.get('modules') as Vec<ModuleMetadata>;
}
private get callNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.calls.isNone
? []
: mod.calls.unwrap().map((fn): string[] =>
fn.args.map((arg): string => arg.type.toString())
)
);
}
private get eventNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.events.isNone
? []
: mod.events.unwrap().map((event): string[] =>
event.args.map((arg): string => arg.toString())
)
);
}
private get storageNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.storage.isNone
? []
: mod.storage.unwrap().map((fn): string[] => {
if (fn.type.isMap) {
return [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()];
} else if (fn.type.isDoubleMap) {
return [fn.type.asDoubleMap.key1.toString(), fn.type.asDoubleMap.key2.toString(), fn.type.asDoubleMap.value.toString()];
} else {
return [fn.type.asType.toString()];
}
})
);
}
/**
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
*/
public getUniqTypes (throwError: boolean): string[] {
const types = flattenUniq([this.callNames, this.eventNames, this.storageNames]);
validateTypes(types, throwError);
return types;
public get modules (): Vec<ModuleMetadataV3> {
return this.get('modules') as Vec<ModuleMetadataV3>;
}
}
+17 -25
View File
@@ -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 { DoubleMapTypeV3 } from '../../interfaces/metadata/types';
import { DoubleMapTypeV3, MapTypeV3, PlainTypeV3, StorageFunctionModifierV3 } from '../../interfaces/metadata';
import { AnyNumber } from '../../types';
import { assert } from '@polkadot/util';
@@ -12,21 +12,13 @@ import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Bytes from '../../primitive/Bytes';
import Text from '../../primitive/Text';
import { MapType, PlainType, StorageFunctionModifier } from '../v2/Storage';
// Re-export classes that haven't changed between V2 and V3
export {
MapType,
PlainType,
StorageFunctionModifier
};
export class StorageFunctionType extends Enum {
public constructor (value?: any, index?: number) {
super({
PlainType,
MapType,
DoubleMapType: 'DoubleMapTypeV3'
Type: 'PlainTypeV3',
Map: 'MapTypeV3',
DoubleMap: 'DoubleMapTypeV3'
}, value, index);
}
@@ -42,19 +34,19 @@ export class StorageFunctionType extends Enum {
/**
* @description The value as a mapped value
*/
public get asMap (): MapType {
public get asMap (): MapTypeV3 {
assert(this.isMap, `Cannot convert '${this.type}' via asMap`);
return this.value as MapType;
return this.value as MapTypeV3;
}
/**
* @description The value as a [[Type]] value
*/
public get asType (): PlainType {
public get asType (): PlainTypeV3 {
assert(this.isPlainType, `Cannot convert '${this.type}' via asType`);
return this.value as PlainType;
return this.value as PlainTypeV3;
}
/**
@@ -87,7 +79,7 @@ export class StorageFunctionType extends Enum {
}
if (this.isMap) {
if (this.asMap.isLinked) {
if (this.asMap.linked.isTrue) {
return `(${this.asMap.value.toString()}, Linkage<${this.asMap.key.toString()}>)`;
}
@@ -100,7 +92,7 @@ export class StorageFunctionType extends Enum {
export interface StorageFunctionMetadataValue {
name: string | Text;
modifier: StorageFunctionModifier | AnyNumber;
modifier: StorageFunctionModifierV3 | AnyNumber;
type: StorageFunctionType;
fallback: Bytes;
documentation: Vec<Text> | string[];
@@ -114,11 +106,11 @@ export interface StorageFunctionMetadataValue {
export class StorageFunctionMetadata extends Struct {
public constructor (value?: StorageFunctionMetadataValue | Uint8Array) {
super({
name: Text,
modifier: StorageFunctionModifier,
name: 'Text',
modifier: 'StorageFunctionModifierV3',
type: StorageFunctionType,
fallback: Bytes,
documentation: Vec.with(Text)
fallback: 'Bytes',
documentation: 'Vec<Text>'
}, value);
}
@@ -137,10 +129,10 @@ export class StorageFunctionMetadata extends Struct {
}
/**
* @description The [[MetadataArgument]] for arguments
* @description The [[StorageFunctionModifierV3]] for arguments
*/
public get modifier (): StorageFunctionModifier {
return this.get('modifier') as StorageFunctionModifier;
public get modifier (): StorageFunctionModifierV3 {
return this.get('modifier') as StorageFunctionModifierV3;
}
/**
+1 -1
View File
@@ -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 MetadataV3, { ModuleMetadata as ModuleMetadataV3 } from './Metadata';
import MetadataV3, { ModuleMetadataV3 } from './Metadata';
export default MetadataV3;
+4 -4
View File
@@ -6,8 +6,8 @@ import { createType, Option, Vec } from '../../codec';
import MetadataV3 from './Metadata';
import StorageHasher from '../../primitive/StorageHasher';
import MetadataV4 from '../v4';
import { ModuleMetadata as ModuleMetadataV4 } from '../v4/Metadata';
import { MapType, StorageFunctionMetadata, StorageFunctionType } from '../v4/Storage';
import { ModuleMetadataV4 } from '../v4/Metadata';
import { StorageFunctionMetadata, StorageFunctionType } from '../v4/Storage';
import { StorageFunctionMetadata as StorageFunctionMetadataV3 } from './Storage';
/**
@@ -22,11 +22,11 @@ function toV4StorageFunction (storageFn: StorageFunctionMetadataV3): StorageFunc
const [newType, index] = type.isPlainType
? [type, 0]
: type.isMap
? [new MapType({
? [createType('MapTypeV4', {
hasher: new StorageHasher('Twox128'),
key: type.asMap.key,
value: type.asMap.value,
isLinked: type.asMap.isLinked
linked: type.asMap.linked
}), 1]
: [createType('DoubleMapTypeV4', {
hasher: new StorageHasher('Twox128'),
@@ -2,12 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import latestSubstrate from './latest.substrate.v4.json';
import staticSubstrate from './static-substrate.json';
import rpcData from './static';
import { decodeLatestSubstrate, defaultValues, toV7 } from '../util/testUtil';
describe('MetadataV4', (): void => {
decodeLatestSubstrate(4, rpcData, latestSubstrate);
decodeLatestSubstrate(4, rpcData, staticSubstrate);
toV7(4, rpcData);
+11 -60
View File
@@ -2,30 +2,28 @@
// 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 '../../interfaces/metadata/types';
import { EventMetadataV4, FunctionMetadataV4 } from '../../interfaces/metadata';
import { MetadataInterface } from '../types';
import Option from '../../codec/Option';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Text from '../../primitive/Text';
import { flattenUniq, validateTypes } from '../util';
import { StorageFunctionMetadata } from './Storage';
/**
* @name ModuleMetadata
* @name ModuleMetadataV4
* @description
* The definition of a module in the system
*/
export class ModuleMetadata extends Struct {
export class ModuleMetadataV4 extends Struct {
public constructor (value?: any) {
super({
name: Text,
prefix: Text,
name: 'Text',
prefix: 'Text',
storage: Option.with(Vec.with(StorageFunctionMetadata)),
calls: Option.with(Vec.with('FunctionMetadataV4')),
events: Option.with(Vec.with('EventMetadataV4'))
calls: Option.with('Vec<FunctionMetadataV4>'),
events: Option.with('Vec<EventMetadataV4>')
}, value);
}
@@ -70,64 +68,17 @@ export class ModuleMetadata extends Struct {
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV4 extends Struct implements MetadataInterface<ModuleMetadata> {
export default class MetadataV4 extends Struct implements MetadataInterface<ModuleMetadataV4> {
public constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadata)
modules: Vec.with(ModuleMetadataV4)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadata> {
return this.get('modules') as Vec<ModuleMetadata>;
}
private get callNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.calls.isNone
? []
: mod.calls.unwrap().map((fn): string[] =>
fn.args.map((arg): string => arg.type.toString())
)
);
}
private get eventNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.events.isNone
? []
: mod.events.unwrap().map((event): string[] =>
event.args.map((arg): string => arg.toString())
)
);
}
private get storageNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.storage.isNone
? []
: mod.storage.unwrap().map((fn): string[] => {
if (fn.type.isMap) {
return [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()];
} else if (fn.type.isDoubleMap) {
return [fn.type.asDoubleMap.key1.toString(), fn.type.asDoubleMap.key2.toString(), fn.type.asDoubleMap.value.toString()];
} else {
return [fn.type.asType.toString()];
}
})
);
}
/**
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
*/
public getUniqTypes (throwError: boolean): string[] {
const types = flattenUniq([this.callNames, this.eventNames, this.storageNames]);
validateTypes(types, throwError);
return types;
public get modules (): Vec<ModuleMetadataV4> {
return this.get('modules') as Vec<ModuleMetadataV4>;
}
}
+16 -65
View File
@@ -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 { DoubleMapTypeV4 } from '../../interfaces/metadata/types';
import { DoubleMapTypeV4, MapTypeV4, PlainTypeV4, StorageFunctionModifierV4 } from '../../interfaces/metadata';
import { AnyNumber } from '../../types';
import { assert } from '@polkadot/util';
@@ -10,64 +10,15 @@ import { assert } from '@polkadot/util';
import Enum from '../../codec/Enum';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Bool from '../../primitive/Bool';
import Bytes from '../../primitive/Bytes';
import StorageHasher from '../../primitive/StorageHasher';
import Text from '../../primitive/Text';
import Type from '../../primitive/Type';
import { PlainType, StorageFunctionModifier } from '../v3/Storage';
// Re-export classes that haven't changed between V3 and V4
export {
PlainType,
StorageFunctionModifier
};
export class MapType extends Struct {
public constructor (value?: any) {
super({
hasher: StorageHasher,
key: Type,
value: Type,
isLinked: Bool
}, value);
}
/**
* @description The hash algorithm used to hash keys, as [[StorageHasher]]
*/
public get hasher (): StorageHasher {
return this.get('hasher') as StorageHasher;
}
/**
* @description Is this an enumerable linked map
*/
public get isLinked (): boolean {
return (this.get('isLinked') as Bool).valueOf();
}
/**
* @description The mapped key as [[Type]]
*/
public get key (): Type {
return this.get('key') as Type;
}
/**
* @description The mapped value as [[Type]]
*/
public get value (): Type {
return this.get('value') as Type;
}
}
export class StorageFunctionType extends Enum {
public constructor (value?: any, index?: number) {
super({
PlainType,
MapType,
DoubleMapType: 'DoubleMapTypeV4'
Type: 'PlainTypeV4',
Map: 'MapTypeV4',
DoubleMap: 'DoubleMapTypeV4'
}, value, index);
}
@@ -83,19 +34,19 @@ export class StorageFunctionType extends Enum {
/**
* @description The value as a mapped value
*/
public get asMap (): MapType {
public get asMap (): MapTypeV4 {
assert(this.isMap, `Cannot convert '${this.type}' via asMap`);
return this.value as MapType;
return this.value as MapTypeV4;
}
/**
* @description The value as a [[Type]] value
*/
public get asType (): PlainType {
public get asType (): PlainTypeV4 {
assert(this.isPlainType, `Cannot convert '${this.type}' via asType`);
return this.value as PlainType;
return this.value as PlainTypeV4;
}
/**
@@ -128,7 +79,7 @@ export class StorageFunctionType extends Enum {
}
if (this.isMap) {
if (this.asMap.isLinked) {
if (this.asMap.linked.isTrue) {
return `(${this.asMap.value.toString()}, Linkage<${this.asMap.key.toString()}>)`;
}
@@ -141,7 +92,7 @@ export class StorageFunctionType extends Enum {
export interface StorageFunctionMetadataValue {
name: string | Text;
modifier: StorageFunctionModifier | AnyNumber;
modifier: StorageFunctionModifierV4 | AnyNumber;
type: StorageFunctionType;
fallback: Bytes;
documentation: Vec<Text> | string[];
@@ -155,11 +106,11 @@ export interface StorageFunctionMetadataValue {
export class StorageFunctionMetadata extends Struct {
public constructor (value?: StorageFunctionMetadataValue | Uint8Array) {
super({
name: Text,
modifier: StorageFunctionModifier,
name: 'Text',
modifier: 'StorageFunctionModifierV4',
type: StorageFunctionType,
fallback: Bytes,
documentation: Vec.with(Text)
fallback: 'Bytes',
documentation: 'Vec<Text>'
}, value);
}
@@ -187,8 +138,8 @@ export class StorageFunctionMetadata extends Struct {
/**
* @description The modifier
*/
public get modifier (): StorageFunctionModifier {
return this.get('modifier') as StorageFunctionModifier;
public get modifier (): StorageFunctionModifierV4 {
return this.get('modifier') as StorageFunctionModifierV4;
}
/**
+1 -1
View File
@@ -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 MetadataV4, { ModuleMetadata as ModuleMetadataV4 } from './Metadata';
import MetadataV4, { ModuleMetadataV4 } from './Metadata';
export default MetadataV4;
+1 -1
View File
@@ -9,7 +9,7 @@ import Text from '../../primitive/Text';
import MetadataV4 from './Metadata';
import StorageHasher from '../../primitive/StorageHasher';
import MetadataV5 from '../v5';
import { ModuleMetadata as ModuleMetadataV5 } from '../v5/Metadata';
import { ModuleMetadataV5 } from '../v5/Metadata';
import { StorageFunctionMetadata, StorageFunctionType } from '../v5/Storage';
import { StorageFunctionMetadata as StorageFunctionMetadataV4 } from './Storage';
@@ -2,8 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import polkadotJson from './latest.polkadot.v5.json';
import substrateJson from './latest.substrate.v5.json';
import polkadotJson from './static-polkadot.json';
import substrateJson from './static-substrate.json';
import polkadotData from './static.polkadot';
import substrateData from './static';
import { decodeLatestSubstrate, defaultValues, toV7 } from '../util/testUtil';
+11 -60
View File
@@ -2,30 +2,28 @@
// 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 '../../interfaces/metadata/types';
import { EventMetadataV5, FunctionMetadataV5 } from '../../interfaces/metadata';
import { MetadataInterface } from '../types';
import Option from '../../codec/Option';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Text from '../../primitive/Text';
import { flattenUniq, validateTypes } from '../util';
import { StorageFunctionMetadata } from './Storage';
/**
* @name ModuleMetadata
* @name ModuleMetadataV5
* @description
* The definition of a module in the system
*/
export class ModuleMetadata extends Struct {
export class ModuleMetadataV5 extends Struct {
public constructor (value?: any) {
super({
name: Text,
prefix: Text,
name: 'Text',
prefix: 'Text',
storage: Option.with(Vec.with(StorageFunctionMetadata)),
calls: Option.with(Vec.with('FunctionMetadataV5')),
events: Option.with(Vec.with('EventMetadataV5'))
calls: Option.with('Vec<FunctionMetadataV5>'),
events: Option.with('Vec<EventMetadataV5>')
}, value);
}
@@ -70,64 +68,17 @@ export class ModuleMetadata extends Struct {
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV5 extends Struct implements MetadataInterface<ModuleMetadata> {
export default class MetadataV5 extends Struct implements MetadataInterface<ModuleMetadataV5> {
public constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadata)
modules: Vec.with(ModuleMetadataV5)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadata> {
return this.get('modules') as Vec<ModuleMetadata>;
}
private get callNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.calls.isNone
? []
: mod.calls.unwrap().map((fn): string[] =>
fn.args.map((arg): string => arg.type.toString())
)
);
}
private get eventNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.events.isNone
? []
: mod.events.unwrap().map((event): string[] =>
event.args.map((arg): string => arg.toString())
)
);
}
private get storageNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.storage.isNone
? []
: mod.storage.unwrap().map((fn): string[] => {
if (fn.type.isMap) {
return [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()];
} else if (fn.type.isDoubleMap) {
return [fn.type.asDoubleMap.key1.toString(), fn.type.asDoubleMap.key2.toString(), fn.type.asDoubleMap.value.toString()];
} else {
return [fn.type.asType.toString()];
}
})
);
}
/**
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
*/
public getUniqTypes (throwError: boolean): string[] {
const types = flattenUniq([this.callNames, this.eventNames, this.storageNames]);
validateTypes(types, throwError);
return types;
public get modules (): Vec<ModuleMetadataV5> {
return this.get('modules') as Vec<ModuleMetadataV5>;
}
}
+16 -24
View File
@@ -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 { DoubleMapTypeV5 } from '../../interfaces/metadata/types';
import { DoubleMapTypeV5, MapTypeV5, PlainTypeV5, StorageFunctionModifierV5 } from '../../interfaces/metadata';
import { AnyNumber } from '../../types';
import { assert } from '@polkadot/util';
@@ -12,21 +12,13 @@ import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Bytes from '../../primitive/Bytes';
import Text from '../../primitive/Text';
import { MapType, PlainType, StorageFunctionModifier } from '../v4/Storage';
// Re-export classes that haven't changed between V4 and V5
export {
MapType,
PlainType,
StorageFunctionModifier
};
export class StorageFunctionType extends Enum {
public constructor (value?: any, index?: number) {
super({
PlainType,
MapType,
DoubleMapType: 'DoubleMapTypeV5'
Type: 'PlainTypeV5',
Map: 'MapTypeV5',
DoubleMap: 'DoubleMapTypeV5'
}, value, index);
}
@@ -42,19 +34,19 @@ export class StorageFunctionType extends Enum {
/**
* @description The value as a mapped value
*/
public get asMap (): MapType {
public get asMap (): MapTypeV5 {
assert(this.isMap, `Cannot convert '${this.type}' via asMap`);
return this.value as MapType;
return this.value as MapTypeV5;
}
/**
* @description The value as a [[Type]] value
*/
public get asType (): PlainType {
public get asType (): PlainTypeV5 {
assert(this.isPlainType, `Cannot convert '${this.type}' via asType`);
return this.value as PlainType;
return this.value as PlainTypeV5;
}
/**
@@ -87,7 +79,7 @@ export class StorageFunctionType extends Enum {
}
if (this.isMap) {
if (this.asMap.isLinked) {
if (this.asMap.linked.isTrue) {
return `(${this.asMap.value.toString()}, Linkage<${this.asMap.key.toString()}>)`;
}
@@ -100,7 +92,7 @@ export class StorageFunctionType extends Enum {
export interface StorageFunctionMetadataValue {
name: string | Text;
modifier: StorageFunctionModifier | AnyNumber;
modifier: StorageFunctionModifierV5 | AnyNumber;
type: StorageFunctionType;
fallback: Bytes;
documentation: Vec<Text> | string[];
@@ -114,11 +106,11 @@ export interface StorageFunctionMetadataValue {
export class StorageFunctionMetadata extends Struct {
public constructor (value?: StorageFunctionMetadataValue | Uint8Array) {
super({
name: Text,
modifier: StorageFunctionModifier,
name: 'Text',
modifier: 'StorageFunctionModifierV5',
type: StorageFunctionType,
fallback: Bytes,
documentation: Vec.with(Text)
fallback: 'Bytes',
documentation: 'Vec<Text>'
}, value);
}
@@ -146,8 +138,8 @@ export class StorageFunctionMetadata extends Struct {
/**
* @description The modifier
*/
public get modifier (): StorageFunctionModifier {
return this.get('modifier') as StorageFunctionModifier;
public get modifier (): StorageFunctionModifierV5 {
return this.get('modifier') as StorageFunctionModifierV5;
}
/**
+1 -1
View File
@@ -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 MetadataV5, { ModuleMetadata as ModuleMetadataV5 } from './Metadata';
import MetadataV5, { ModuleMetadataV5 } from './Metadata';
export default MetadataV5;
+1 -1
View File
@@ -4,7 +4,7 @@
import MetadataV5 from './Metadata';
import MetadataV6 from '../v6';
import { ModuleMetadata as ModuleMetadataV6 } from '../v6/Metadata';
import { ModuleMetadataV6 } from '../v6/Metadata';
/**
* Convert from MetadataV5 to MetadataV6
@@ -2,8 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import polkadotJson from './latest.polkadot.v6.json';
import substrateJson from './latest.substrate.v6.json';
import polkadotJson from './static-polkadot.json';
import substrateJson from './static-substrate.json';
import polkadotData from './static.polkadot';
import substrateData from './static';
import { decodeLatestSubstrate, defaultValues, toV7 } from '../util/testUtil';
+12 -69
View File
@@ -2,31 +2,29 @@
// 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 '../../interfaces/metadata/types';
import { EventMetadataV6, FunctionMetadataV6, ModuleConstantMetadataV6 } from '../../interfaces/metadata';
import { MetadataInterface } from '../types';
import Option from '../../codec/Option';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Text from '../../primitive/Text';
import { flattenUniq, validateTypes } from '../util';
import { StorageEntryMetadata } from './Storage';
/**
* @name ModuleMetadata
* @name ModuleMetadataV6
* @description
* The definition of a module in the system
*/
export class ModuleMetadata extends Struct {
export class ModuleMetadataV6 extends Struct {
public constructor (value?: any) {
super({
name: Text,
prefix: Text,
name: 'Text',
prefix: 'Text',
storage: Option.with(Vec.with(StorageEntryMetadata)),
calls: Option.with(Vec.with('FunctionMetadataV6')),
events: Option.with(Vec.with('EventMetadataV6')),
constants: Vec.with('ModuleConstantMetadataV6')
calls: Option.with('Vec<FunctionMetadataV6>'),
events: Option.with('Vec<EventMetadataV6>'),
constants: 'Vec<ModuleConstantMetadataV6>'
}, value);
}
@@ -78,72 +76,17 @@ export class ModuleMetadata extends Struct {
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV6 extends Struct implements MetadataInterface<ModuleMetadata> {
export default class MetadataV6 extends Struct implements MetadataInterface<ModuleMetadataV6> {
public constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadata)
modules: Vec.with(ModuleMetadataV6)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadata> {
return this.get('modules') as Vec<ModuleMetadata>;
}
private get callNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.calls.isNone
? []
: mod.calls.unwrap().map((fn): string[] =>
fn.args.map((arg): string => arg.type.toString())
)
);
}
private get constantNames (): string[][] {
return this.modules.map((mod): string[] =>
mod.constants.map((c): string =>
c.type.toString()
)
);
}
private get eventNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.events.isNone
? []
: mod.events.unwrap().map((event): string[] =>
event.args.map((arg): string => arg.toString())
)
);
}
private get storageNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.storage.isNone
? []
: mod.storage.unwrap().map((fn): string[] => {
if (fn.type.isMap) {
return [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()];
} else if (fn.type.isDoubleMap) {
return [fn.type.asDoubleMap.key1.toString(), fn.type.asDoubleMap.key2.toString(), fn.type.asDoubleMap.value.toString()];
} else {
return [fn.type.asType.toString()];
}
})
);
}
/**
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
*/
public getUniqTypes (throwError: boolean): string[] {
const types = flattenUniq([this.callNames, this.constantNames, this.eventNames, this.storageNames]);
validateTypes(types, throwError);
return types;
public get modules (): Vec<ModuleMetadataV6> {
return this.get('modules') as Vec<ModuleMetadataV6>;
}
}
+1 -4
View File
@@ -2,14 +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 { MapType, PlainType, StorageFunctionMetadata, StorageFunctionMetadataValue, StorageFunctionModifier, StorageFunctionType } from '../v5/Storage';
import { StorageFunctionMetadata, StorageFunctionMetadataValue, StorageFunctionType } from '../v5/Storage';
// Re-export classes that haven't changed between V5 and V6
export {
MapType,
PlainType,
StorageFunctionMetadata as StorageEntryMetadata,
StorageFunctionMetadataValue as StorageEntryMetadataValue,
StorageFunctionModifier as StorageEntryModifier,
StorageFunctionType as StorageEntryType
};
+1 -1
View File
@@ -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 MetadataV6, { ModuleMetadata as ModuleMetadataV6 } from './Metadata';
import MetadataV6, { ModuleMetadataV6 } from './Metadata';
export default MetadataV6;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -4,7 +4,7 @@
import MetadataV6 from './Metadata';
import MetadataV7 from '../v7';
import { ModuleMetadata as ModuleMetadataV7 } from '../v7/Metadata';
import { ModuleMetadataV7 } from '../v7/Metadata';
import { StorageMetadata as StorageV7 } from '../v7/Storage';
/**
@@ -2,7 +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 substrateJson from './latest.substrate.v7.json';
import polkadotJson from './static-polkadot.json';
import substrateJson from './static-substrate.json';
import polkadotData from './static.polkadot';
import substrateData from './static';
import { decodeLatestSubstrate, defaultValues, toV7 } from '../util/testUtil';
@@ -13,3 +15,11 @@ describe('MetadataV7 (substrate)', (): void => {
defaultValues(substrateData);
});
describe('MetadataV7 (polkadot)', (): void => {
decodeLatestSubstrate(7, polkadotData, polkadotJson);
toV7(7, polkadotData);
defaultValues(polkadotData);
});
+11 -68
View File
@@ -2,30 +2,28 @@
// 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 '../../interfaces/metadata/types';
import { EventMetadataV7, FunctionMetadataV7, ModuleConstantMetadataV7 } from '../../interfaces/metadata';
import { MetadataInterface } from '../types';
import Option from '../../codec/Option';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Text from '../../primitive/Text';
import { flattenUniq, validateTypes } from '../util';
import { StorageMetadata } from './Storage';
/**
* @name ModuleMetadata
* @name ModuleMetadataV7
* @description
* The definition of a module in the system
*/
export class ModuleMetadata extends Struct {
export class ModuleMetadataV7 extends Struct {
public constructor (value?: any) {
super({
name: Text,
name: 'Text',
storage: Option.with(StorageMetadata),
calls: Option.with(Vec.with('FunctionMetadataV7')),
events: Option.with(Vec.with('EventMetadataV7')),
constants: Vec.with('ModuleConstantMetadataV7')
calls: Option.with('Vec<FunctionMetadataV7>'),
events: Option.with('Vec<EventMetadataV7>'),
constants: 'Vec<ModuleConstantMetadataV7>'
}, value);
}
@@ -77,72 +75,17 @@ export class ModuleMetadata extends Struct {
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV7 extends Struct implements MetadataInterface<ModuleMetadata> {
export default class MetadataV7 extends Struct implements MetadataInterface<ModuleMetadataV7> {
public constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadata)
modules: Vec.with(ModuleMetadataV7)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadata> {
return this.get('modules') as Vec<ModuleMetadata>;
}
private get callNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.calls.isNone
? []
: mod.calls.unwrap().map((fn): string[] =>
fn.args.map((arg): string => arg.type.toString())
)
);
}
private get constantNames (): string[][] {
return this.modules.map((mod): string[] =>
mod.constants.map((c): string =>
c.type.toString()
)
);
}
private get eventNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.events.isNone
? []
: mod.events.unwrap().map((event): string[] =>
event.args.map((arg): string => arg.toString())
)
);
}
private get storageNames (): string[][][] {
return this.modules.map((mod): string[][] =>
mod.storage.isNone
? []
: mod.storage.unwrap().items.map((fn): string[] => {
if (fn.type.isMap) {
return [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()];
} else if (fn.type.isDoubleMap) {
return [fn.type.asDoubleMap.key1.toString(), fn.type.asDoubleMap.key2.toString(), fn.type.asDoubleMap.value.toString()];
} else {
return [fn.type.asType.toString()];
}
})
);
}
/**
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
*/
public getUniqTypes (throwError: boolean): string[] {
const types = flattenUniq([this.callNames, this.constantNames, this.eventNames, this.storageNames]);
validateTypes(types, throwError);
return types;
public get modules (): Vec<ModuleMetadataV7> {
return this.get('modules') as Vec<ModuleMetadataV7>;
}
}
+2 -5
View File
@@ -5,22 +5,19 @@
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import Text from '../../primitive/Text';
import { MapType, PlainType, StorageEntryMetadata, StorageEntryMetadataValue, StorageEntryModifier, StorageEntryType } from '../v6/Storage';
import { StorageEntryMetadata, StorageEntryMetadataValue, StorageEntryType } from '../v6/Storage';
// Re-export classes that haven't changed between V6 and V7
export {
MapType,
PlainType,
StorageEntryMetadata,
StorageEntryMetadataValue,
StorageEntryModifier,
StorageEntryType
};
export class StorageMetadata extends Struct {
public constructor (value?: any) {
super({
prefix: Text,
prefix: 'Text',
// NOTE renamed to items from entries (since Struct already has entries from Map)
items: Vec.with(StorageEntryMetadata)
}, value);
+1 -1
View File
@@ -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 MetadataV7, { ModuleMetadata as ModuleMetadataV7 } from './Metadata';
import MetadataV7, { ModuleMetadataV7 } from './Metadata';
export default MetadataV7;
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+8 -5
View File
@@ -51,16 +51,19 @@ export default class Enum extends Base<Codec> {
this._index = this._indexes.indexOf(decoded.index) || 0;
}
private static extractDef (def: Record<string, InterfaceTypes | Constructor> | string[]): { def: TypesDef; isBasic: boolean } {
if (!Array.isArray(def)) {
private static extractDef (_def: Record<string, InterfaceTypes | Constructor> | string[]): { def: TypesDef; isBasic: boolean } {
if (!Array.isArray(_def)) {
const def = mapToTypeMap(_def);
const isBasic = !Object.values(def).some((type): boolean => type !== Null);
return {
def: mapToTypeMap(def),
isBasic: false
def,
isBasic
};
}
return {
def: def.reduce((def, key): TypesDef => {
def: _def.reduce((def, key): TypesDef => {
def[key] = Null;
return def;
@@ -29,7 +29,7 @@ describe('createType', (): void => {
it('allows creation of a Enum (simple)', (): void => {
expect(
createTypeUnsafe('{"_enum": ["A", "B", "C"]}', [1]).toJSON()
).toEqual({ B: null });
).toEqual(1);
});
it('allows creation of a Enum (parametrised)', (): void => {
+14 -15
View File
@@ -4,25 +4,24 @@
import { isFunction, isObject, isUndefined } from '@polkadot/util';
function hasMismatch (a?: any, b?: any): boolean {
return isUndefined(a) || (
// Codec has .eq, use it here
isFunction(a.eq)
? !a.eq(b)
: a !== b
);
}
// NOTE These are used internally and when comparing objects, expects that
// when the second is an Map<string, Codec> that the first has to be as well
export default function compareMap (a: Map<any, any>, b?: any): boolean {
if (Array.isArray(b)) {
return (a.size === b.length) && isUndefined(
b.find((entry): boolean => {
if (!Array.isArray(entry) || entry.length !== 2) {
return true;
}
const value = a.get(entry[0]);
return isUndefined(value) || (
// Codec has .eq, use it here
isFunction(value.eq)
? !value.eq(entry[1])
: value !== entry[1]
);
})
// equal number of entries and each entry in the array should match
return (a.size === b.length) && !b.some((entry): boolean =>
!Array.isArray(entry) ||
entry.length !== 2 ||
hasMismatch(a.get(entry[0]), entry[1])
);
} else if (b instanceof Map) {
return compareMap(a, [...b.entries()]);
+103 -1
View File
@@ -25,7 +25,7 @@ import { TreasuryProposal } from './interfaces/treasury';
import { BlockAttestations, IncludedBlocks, MoreAttestations } from './interfaces/attestations';
import { EcdsaSignature, EthereumAddress } from './interfaces/claims';
import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParachainDispatchOrigin, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from './interfaces/parachains';
import { CallMetadataV0, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, EventMetadataV0, EventMetadataV1, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleMetadataV0, OuterDispatchCallV0, OuterDispatchMetadataV0 } from './interfaces/metadata';
import { CallMetadataV0, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, EventMetadataV0, EventMetadataV1, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, MapTypeV0, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MetadataV0, MetadataV1, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleMetadataV0, ModuleMetadataV1, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeV0, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, RuntimeModuleMetadataV0, StorageEntryModifierV6, StorageEntryModifierV7, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageMetadataV0 } from './interfaces/metadata';
import { ApiId, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from './interfaces/rpc';
export interface InterfaceRegistry {
@@ -666,6 +666,12 @@ export interface InterfaceRegistry {
FunctionMetadataV0: FunctionMetadataV0;
'Option<FunctionMetadataV0>': Option<FunctionMetadataV0>;
'Vec<FunctionMetadataV0>': Vec<FunctionMetadataV0>;
MapTypeV0: MapTypeV0;
'Option<MapTypeV0>': Option<MapTypeV0>;
'Vec<MapTypeV0>': Vec<MapTypeV0>;
MetadataV0: MetadataV0;
'Option<MetadataV0>': Option<MetadataV0>;
'Vec<MetadataV0>': Vec<MetadataV0>;
ModuleMetadataV0: ModuleMetadataV0;
'Option<ModuleMetadataV0>': Option<ModuleMetadataV0>;
'Vec<ModuleMetadataV0>': Vec<ModuleMetadataV0>;
@@ -675,6 +681,33 @@ export interface InterfaceRegistry {
OuterDispatchMetadataV0: OuterDispatchMetadataV0;
'Option<OuterDispatchMetadataV0>': Option<OuterDispatchMetadataV0>;
'Vec<OuterDispatchMetadataV0>': Vec<OuterDispatchMetadataV0>;
OuterEventEventMetadataEventsV0: OuterEventEventMetadataEventsV0;
'Option<OuterEventEventMetadataEventsV0>': Option<OuterEventEventMetadataEventsV0>;
'Vec<OuterEventEventMetadataEventsV0>': Vec<OuterEventEventMetadataEventsV0>;
OuterEventEventMetadataV0: OuterEventEventMetadataV0;
'Option<OuterEventEventMetadataV0>': Option<OuterEventEventMetadataV0>;
'Vec<OuterEventEventMetadataV0>': Vec<OuterEventEventMetadataV0>;
OuterEventMetadataV0: OuterEventMetadataV0;
'Option<OuterEventMetadataV0>': Option<OuterEventMetadataV0>;
'Vec<OuterEventMetadataV0>': Vec<OuterEventMetadataV0>;
PlainTypeV0: PlainTypeV0;
'Option<PlainTypeV0>': Option<PlainTypeV0>;
'Vec<PlainTypeV0>': Vec<PlainTypeV0>;
RuntimeModuleMetadataV0: RuntimeModuleMetadataV0;
'Option<RuntimeModuleMetadataV0>': Option<RuntimeModuleMetadataV0>;
'Vec<RuntimeModuleMetadataV0>': Vec<RuntimeModuleMetadataV0>;
StorageFunctionMetadataV0: StorageFunctionMetadataV0;
'Option<StorageFunctionMetadataV0>': Option<StorageFunctionMetadataV0>;
'Vec<StorageFunctionMetadataV0>': Vec<StorageFunctionMetadataV0>;
StorageFunctionModifierV0: StorageFunctionModifierV0;
'Option<StorageFunctionModifierV0>': Option<StorageFunctionModifierV0>;
'Vec<StorageFunctionModifierV0>': Vec<StorageFunctionModifierV0>;
StorageFunctionTypeV0: StorageFunctionTypeV0;
'Option<StorageFunctionTypeV0>': Option<StorageFunctionTypeV0>;
'Vec<StorageFunctionTypeV0>': Vec<StorageFunctionTypeV0>;
StorageMetadataV0: StorageMetadataV0;
'Option<StorageMetadataV0>': Option<StorageMetadataV0>;
'Vec<StorageMetadataV0>': Vec<StorageMetadataV0>;
EventMetadataV1: EventMetadataV1;
'Option<EventMetadataV1>': Option<EventMetadataV1>;
'Vec<EventMetadataV1>': Vec<EventMetadataV1>;
@@ -684,6 +717,21 @@ export interface InterfaceRegistry {
FunctionMetadataV1: FunctionMetadataV1;
'Option<FunctionMetadataV1>': Option<FunctionMetadataV1>;
'Vec<FunctionMetadataV1>': Vec<FunctionMetadataV1>;
MetadataV1: MetadataV1;
'Option<MetadataV1>': Option<MetadataV1>;
'Vec<MetadataV1>': Vec<MetadataV1>;
ModuleMetadataV1: ModuleMetadataV1;
'Option<ModuleMetadataV1>': Option<ModuleMetadataV1>;
'Vec<ModuleMetadataV1>': Vec<ModuleMetadataV1>;
StorageFunctionMetadataV1: StorageFunctionMetadataV1;
'Option<StorageFunctionMetadataV1>': Option<StorageFunctionMetadataV1>;
'Vec<StorageFunctionMetadataV1>': Vec<StorageFunctionMetadataV1>;
StorageFunctionModifierV1: StorageFunctionModifierV1;
'Option<StorageFunctionModifierV1>': Option<StorageFunctionModifierV1>;
'Vec<StorageFunctionModifierV1>': Vec<StorageFunctionModifierV1>;
StorageFunctionTypeV1: StorageFunctionTypeV1;
'Option<StorageFunctionTypeV1>': Option<StorageFunctionTypeV1>;
'Vec<StorageFunctionTypeV1>': Vec<StorageFunctionTypeV1>;
EventMetadataV2: EventMetadataV2;
'Option<EventMetadataV2>': Option<EventMetadataV2>;
'Vec<EventMetadataV2>': Vec<EventMetadataV2>;
@@ -693,6 +741,15 @@ export interface InterfaceRegistry {
FunctionMetadataV2: FunctionMetadataV2;
'Option<FunctionMetadataV2>': Option<FunctionMetadataV2>;
'Vec<FunctionMetadataV2>': Vec<FunctionMetadataV2>;
MapTypeV2: MapTypeV2;
'Option<MapTypeV2>': Option<MapTypeV2>;
'Vec<MapTypeV2>': Vec<MapTypeV2>;
PlainTypeV2: PlainTypeV2;
'Option<PlainTypeV2>': Option<PlainTypeV2>;
'Vec<PlainTypeV2>': Vec<PlainTypeV2>;
StorageFunctionModifierV2: StorageFunctionModifierV2;
'Option<StorageFunctionModifierV2>': Option<StorageFunctionModifierV2>;
'Vec<StorageFunctionModifierV2>': Vec<StorageFunctionModifierV2>;
DoubleMapTypeV3: DoubleMapTypeV3;
'Option<DoubleMapTypeV3>': Option<DoubleMapTypeV3>;
'Vec<DoubleMapTypeV3>': Vec<DoubleMapTypeV3>;
@@ -705,6 +762,15 @@ export interface InterfaceRegistry {
FunctionMetadataV3: FunctionMetadataV3;
'Option<FunctionMetadataV3>': Option<FunctionMetadataV3>;
'Vec<FunctionMetadataV3>': Vec<FunctionMetadataV3>;
MapTypeV3: MapTypeV3;
'Option<MapTypeV3>': Option<MapTypeV3>;
'Vec<MapTypeV3>': Vec<MapTypeV3>;
PlainTypeV3: PlainTypeV3;
'Option<PlainTypeV3>': Option<PlainTypeV3>;
'Vec<PlainTypeV3>': Vec<PlainTypeV3>;
StorageFunctionModifierV3: StorageFunctionModifierV3;
'Option<StorageFunctionModifierV3>': Option<StorageFunctionModifierV3>;
'Vec<StorageFunctionModifierV3>': Vec<StorageFunctionModifierV3>;
DoubleMapTypeV4: DoubleMapTypeV4;
'Option<DoubleMapTypeV4>': Option<DoubleMapTypeV4>;
'Vec<DoubleMapTypeV4>': Vec<DoubleMapTypeV4>;
@@ -717,6 +783,15 @@ export interface InterfaceRegistry {
FunctionMetadataV4: FunctionMetadataV4;
'Option<FunctionMetadataV4>': Option<FunctionMetadataV4>;
'Vec<FunctionMetadataV4>': Vec<FunctionMetadataV4>;
MapTypeV4: MapTypeV4;
'Option<MapTypeV4>': Option<MapTypeV4>;
'Vec<MapTypeV4>': Vec<MapTypeV4>;
PlainTypeV4: PlainTypeV4;
'Option<PlainTypeV4>': Option<PlainTypeV4>;
'Vec<PlainTypeV4>': Vec<PlainTypeV4>;
StorageFunctionModifierV4: StorageFunctionModifierV4;
'Option<StorageFunctionModifierV4>': Option<StorageFunctionModifierV4>;
'Vec<StorageFunctionModifierV4>': Vec<StorageFunctionModifierV4>;
DoubleMapTypeV5: DoubleMapTypeV5;
'Option<DoubleMapTypeV5>': Option<DoubleMapTypeV5>;
'Vec<DoubleMapTypeV5>': Vec<DoubleMapTypeV5>;
@@ -729,6 +804,15 @@ export interface InterfaceRegistry {
FunctionMetadataV5: FunctionMetadataV5;
'Option<FunctionMetadataV5>': Option<FunctionMetadataV5>;
'Vec<FunctionMetadataV5>': Vec<FunctionMetadataV5>;
MapTypeV5: MapTypeV5;
'Option<MapTypeV5>': Option<MapTypeV5>;
'Vec<MapTypeV5>': Vec<MapTypeV5>;
PlainTypeV5: PlainTypeV5;
'Option<PlainTypeV5>': Option<PlainTypeV5>;
'Vec<PlainTypeV5>': Vec<PlainTypeV5>;
StorageFunctionModifierV5: StorageFunctionModifierV5;
'Option<StorageFunctionModifierV5>': Option<StorageFunctionModifierV5>;
'Vec<StorageFunctionModifierV5>': Vec<StorageFunctionModifierV5>;
DoubleMapTypeV6: DoubleMapTypeV6;
'Option<DoubleMapTypeV6>': Option<DoubleMapTypeV6>;
'Vec<DoubleMapTypeV6>': Vec<DoubleMapTypeV6>;
@@ -741,9 +825,18 @@ export interface InterfaceRegistry {
FunctionMetadataV6: FunctionMetadataV6;
'Option<FunctionMetadataV6>': Option<FunctionMetadataV6>;
'Vec<FunctionMetadataV6>': Vec<FunctionMetadataV6>;
MapTypeV6: MapTypeV6;
'Option<MapTypeV6>': Option<MapTypeV6>;
'Vec<MapTypeV6>': Vec<MapTypeV6>;
ModuleConstantMetadataV6: ModuleConstantMetadataV6;
'Option<ModuleConstantMetadataV6>': Option<ModuleConstantMetadataV6>;
'Vec<ModuleConstantMetadataV6>': Vec<ModuleConstantMetadataV6>;
PlainTypeV6: PlainTypeV6;
'Option<PlainTypeV6>': Option<PlainTypeV6>;
'Vec<PlainTypeV6>': Vec<PlainTypeV6>;
StorageEntryModifierV6: StorageEntryModifierV6;
'Option<StorageEntryModifierV6>': Option<StorageEntryModifierV6>;
'Vec<StorageEntryModifierV6>': Vec<StorageEntryModifierV6>;
DoubleMapTypeV7: DoubleMapTypeV7;
'Option<DoubleMapTypeV7>': Option<DoubleMapTypeV7>;
'Vec<DoubleMapTypeV7>': Vec<DoubleMapTypeV7>;
@@ -756,9 +849,18 @@ export interface InterfaceRegistry {
FunctionMetadataV7: FunctionMetadataV7;
'Option<FunctionMetadataV7>': Option<FunctionMetadataV7>;
'Vec<FunctionMetadataV7>': Vec<FunctionMetadataV7>;
MapTypeV7: MapTypeV7;
'Option<MapTypeV7>': Option<MapTypeV7>;
'Vec<MapTypeV7>': Vec<MapTypeV7>;
ModuleConstantMetadataV7: ModuleConstantMetadataV7;
'Option<ModuleConstantMetadataV7>': Option<ModuleConstantMetadataV7>;
'Vec<ModuleConstantMetadataV7>': Vec<ModuleConstantMetadataV7>;
PlainTypeV7: PlainTypeV7;
'Option<PlainTypeV7>': Option<PlainTypeV7>;
'Vec<PlainTypeV7>': Vec<PlainTypeV7>;
StorageEntryModifierV7: StorageEntryModifierV7;
'Option<StorageEntryModifierV7>': Option<StorageEntryModifierV7>;
'Vec<StorageEntryModifierV7>': Vec<StorageEntryModifierV7>;
ApiId: ApiId;
'Option<ApiId>': Option<ApiId>;
'Vec<ApiId>': Vec<ApiId>;
@@ -24,6 +24,15 @@ export default {
args: 'Vec<FunctionArgumentMetadataV0>',
documentation: 'Vec<Text>'
},
MapTypeV0: {
key: 'Type',
value: 'Type'
},
MetadataV0: {
outerEvent: 'OuterEventMetadataV0',
modules: 'Vec<RuntimeModuleMetadataV0>',
outerDispatch: 'OuterDispatchMetadataV0'
},
ModuleMetadataV0: {
name: 'Text',
call: 'CallMetadataV0'
@@ -37,6 +46,38 @@ export default {
name: 'Text',
calls: 'Vec<OuterDispatchCallV0>'
},
OuterEventEventMetadataEventsV0: 'Vec<EventMetadataV0>',
OuterEventEventMetadataV0: '(Text, OuterEventEventMetadataEventsV0)',
OuterEventMetadataV0: {
name: 'Text',
events: 'Vec<OuterEventEventMetadataV0>'
},
PlainTypeV0: 'Type',
RuntimeModuleMetadataV0: {
prefix: 'Text',
module: 'ModuleMetadataV0',
storage: 'Option<StorageMetadataV0>'
},
StorageFunctionMetadataV0: {
name: 'Text',
modifier: 'StorageFunctionModifierV0',
type: 'StorageFunctionTypeV0',
fallback: 'Bytes',
documentation: 'Vec<Text>'
},
StorageFunctionModifierV0: {
_enum: ['Optional', 'Default', 'Required']
},
StorageFunctionTypeV0: {
_enum: {
Type: 'PlainTypeV0',
Map: 'MapTypeV0'
}
},
StorageMetadataV0: {
prefix: 'Text',
functions: 'Vec<StorageFunctionMetadataV0>'
},
// v1
EventMetadataV1: 'EventMetadataV0',
@@ -46,11 +87,31 @@ export default {
args: 'Vec<FunctionArgumentMetadataV1>',
documentation: 'Vec<Text>'
},
MetadataV1: {
modules: 'Vec<ModuleMetadataV1>'
},
ModuleMetadataV1: {
name: 'Text',
prefix: 'Text',
storage: 'Option<Vec<StorageFunctionMetadataV1>>',
calls: 'Option<Vec<FunctionMetadataV1>>',
events: 'Option<Vec<EventMetadataV1>>'
},
StorageFunctionMetadataV1: 'StorageFunctionMetadataV0',
StorageFunctionModifierV1: 'StorageFunctionModifierV0',
StorageFunctionTypeV1: 'StorageFunctionTypeV0',
// v2
EventMetadataV2: 'EventMetadataV1',
FunctionArgumentMetadataV2: 'FunctionArgumentMetadataV1',
FunctionMetadataV2: 'FunctionMetadataV1',
MapTypeV2: {
key: 'Type',
value: 'Type',
linked: 'bool'
},
PlainTypeV2: 'Type',
StorageFunctionModifierV2: 'StorageFunctionModifierV1',
// v3
DoubleMapTypeV3: {
@@ -62,6 +123,9 @@ export default {
EventMetadataV3: 'EventMetadataV2',
FunctionArgumentMetadataV3: 'FunctionArgumentMetadataV2',
FunctionMetadataV3: 'FunctionMetadataV2',
MapTypeV3: 'MapTypeV2',
PlainTypeV3: 'Type',
StorageFunctionModifierV3: 'StorageFunctionModifierV2',
// v4
DoubleMapTypeV4: {
@@ -74,6 +138,14 @@ export default {
EventMetadataV4: 'EventMetadataV3',
FunctionArgumentMetadataV4: 'FunctionArgumentMetadataV3',
FunctionMetadataV4: 'FunctionMetadataV3',
MapTypeV4: {
hasher: 'StorageHasher',
key: 'Type',
value: 'Type',
linked: 'bool'
},
PlainTypeV4: 'Type',
StorageFunctionModifierV4: 'StorageFunctionModifierV3',
// v5
DoubleMapTypeV5: {
@@ -86,24 +158,33 @@ export default {
EventMetadataV5: 'EventMetadataV4',
FunctionArgumentMetadataV5: 'FunctionArgumentMetadataV4',
FunctionMetadataV5: 'FunctionMetadataV4',
MapTypeV5: 'MapTypeV4',
PlainTypeV5: 'Type',
StorageFunctionModifierV5: 'StorageFunctionModifierV4',
// v6
DoubleMapTypeV6: 'DoubleMapTypeV5',
EventMetadataV6: 'EventMetadataV5',
FunctionArgumentMetadataV6: 'FunctionArgumentMetadataV5',
FunctionMetadataV6: 'FunctionMetadataV5',
MapTypeV6: 'MapTypeV5',
ModuleConstantMetadataV6: {
name: 'Text',
type: 'Type',
value: 'Bytes',
documentation: 'Vec<Text>'
},
PlainTypeV6: 'Type',
StorageEntryModifierV6: 'StorageFunctionModifierV5',
// v7
DoubleMapTypeV7: 'DoubleMapTypeV6',
EventMetadataV7: 'EventMetadataV6',
FunctionArgumentMetadataV7: 'FunctionArgumentMetadataV6',
FunctionMetadataV7: 'FunctionMetadataV6',
ModuleConstantMetadataV7: 'ModuleConstantMetadataV6'
MapTypeV7: 'MapTypeV6',
ModuleConstantMetadataV7: 'ModuleConstantMetadataV6',
PlainTypeV7: 'Type',
StorageEntryModifierV7: 'StorageEntryModifierV6'
}
};
+191 -2
View File
@@ -1,8 +1,9 @@
// Auto-generated via `yarn build:interfaces`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Struct, Vec } from '../../codec';
import { Bytes, StorageHasher, Text, Type, u16 } from '../../primitive';
import { Codec } from '../../types';
import { Enum, Option, Struct, Vec } from '../../codec';
import { Bytes, StorageHasher, Text, Type, bool, u16 } from '../../primitive';
/** Struct */
export interface CallMetadataV0 extends Struct {
@@ -158,6 +159,64 @@ export type FunctionMetadataV6 = FunctionMetadataV5;
/** FunctionMetadataV6 */
export type FunctionMetadataV7 = FunctionMetadataV6;
/** Struct */
export interface MapTypeV0 extends Struct {
/** Type */
readonly key: Type;
/** Type */
readonly value: Type;
}
/** Struct */
export interface MapTypeV2 extends Struct {
/** Type */
readonly key: Type;
/** Type */
readonly value: Type;
/** bool */
readonly linked: bool;
}
/** MapTypeV2 */
export type MapTypeV3 = MapTypeV2;
/** Struct */
export interface MapTypeV4 extends Struct {
/** StorageHasher */
readonly hasher: StorageHasher;
/** Type */
readonly key: Type;
/** Type */
readonly value: Type;
/** bool */
readonly linked: bool;
}
/** MapTypeV4 */
export type MapTypeV5 = MapTypeV4;
/** MapTypeV5 */
export type MapTypeV6 = MapTypeV5;
/** MapTypeV6 */
export type MapTypeV7 = MapTypeV6;
/** Struct */
export interface MetadataV0 extends Struct {
/** OuterEventMetadataV0 */
readonly outerEvent: OuterEventMetadataV0;
/** Vec<RuntimeModuleMetadataV0> */
readonly modules: Vec<RuntimeModuleMetadataV0>;
/** OuterDispatchMetadataV0 */
readonly outerDispatch: OuterDispatchMetadataV0;
}
/** Struct */
export interface MetadataV1 extends Struct {
/** Vec<ModuleMetadataV1> */
readonly modules: Vec<ModuleMetadataV1>;
}
/** Struct */
export interface ModuleConstantMetadataV6 extends Struct {
/** Text */
@@ -181,6 +240,20 @@ export interface ModuleMetadataV0 extends Struct {
readonly call: CallMetadataV0;
}
/** Struct */
export interface ModuleMetadataV1 extends Struct {
/** Text */
readonly name: Text;
/** Text */
readonly prefix: Text;
/** Option<Vec<StorageFunctionMetadataV1>> */
readonly storage: Option<Vec<StorageFunctionMetadataV1>>;
/** Option<Vec<FunctionMetadataV1>> */
readonly calls: Option<Vec<FunctionMetadataV1>>;
/** Option<Vec<EventMetadataV1>> */
readonly events: Option<Vec<EventMetadataV1>>;
}
/** Struct */
export interface OuterDispatchCallV0 extends Struct {
/** Text */
@@ -198,3 +271,119 @@ export interface OuterDispatchMetadataV0 extends Struct {
/** Vec<OuterDispatchCallV0> */
readonly calls: Vec<OuterDispatchCallV0>;
}
/** Vec<EventMetadataV0> */
export type OuterEventEventMetadataEventsV0 = Vec<EventMetadataV0>;
/** [Text, OuterEventEventMetadataEventsV0] & Codec */
export type OuterEventEventMetadataV0 = [Text, OuterEventEventMetadataEventsV0] & Codec;
/** Struct */
export interface OuterEventMetadataV0 extends Struct {
/** Text */
readonly name: Text;
/** Vec<OuterEventEventMetadataV0> */
readonly events: Vec<OuterEventEventMetadataV0>;
}
/** Type */
export type PlainTypeV0 = Type;
/** Type */
export type PlainTypeV2 = Type;
/** Type */
export type PlainTypeV3 = Type;
/** Type */
export type PlainTypeV4 = Type;
/** Type */
export type PlainTypeV5 = Type;
/** Type */
export type PlainTypeV6 = Type;
/** Type */
export type PlainTypeV7 = Type;
/** Struct */
export interface RuntimeModuleMetadataV0 extends Struct {
/** Text */
readonly prefix: Text;
/** ModuleMetadataV0 */
readonly module: ModuleMetadataV0;
/** Option<StorageMetadataV0> */
readonly storage: Option<StorageMetadataV0>;
}
/** StorageFunctionModifierV5 */
export type StorageEntryModifierV6 = StorageFunctionModifierV5;
/** StorageEntryModifierV6 */
export type StorageEntryModifierV7 = StorageEntryModifierV6;
/** Struct */
export interface StorageFunctionMetadataV0 extends Struct {
/** Text */
readonly name: Text;
/** StorageFunctionModifierV0 */
readonly modifier: StorageFunctionModifierV0;
/** StorageFunctionTypeV0 */
readonly type: StorageFunctionTypeV0;
/** Bytes */
readonly fallback: Bytes;
/** Vec<Text> */
readonly documentation: Vec<Text>;
}
/** StorageFunctionMetadataV0 */
export type StorageFunctionMetadataV1 = StorageFunctionMetadataV0;
/** Enum */
export interface StorageFunctionModifierV0 extends Enum {
/** 0:: Optional */
readonly isOptional: boolean;
/** 1:: Default */
readonly isDefault: boolean;
/** 2:: Required */
readonly isRequired: boolean;
}
/** StorageFunctionModifierV0 */
export type StorageFunctionModifierV1 = StorageFunctionModifierV0;
/** StorageFunctionModifierV1 */
export type StorageFunctionModifierV2 = StorageFunctionModifierV1;
/** StorageFunctionModifierV2 */
export type StorageFunctionModifierV3 = StorageFunctionModifierV2;
/** StorageFunctionModifierV3 */
export type StorageFunctionModifierV4 = StorageFunctionModifierV3;
/** StorageFunctionModifierV4 */
export type StorageFunctionModifierV5 = StorageFunctionModifierV4;
/** Enum */
export interface StorageFunctionTypeV0 extends Enum {
/** 0:: Type(PlainTypeV0) */
readonly isType: boolean;
/** PlainTypeV0 */
readonly asType: PlainTypeV0;
/** 1:: Map(MapTypeV0) */
readonly isMap: boolean;
/** MapTypeV0 */
readonly asMap: MapTypeV0;
}
/** StorageFunctionTypeV0 */
export type StorageFunctionTypeV1 = StorageFunctionTypeV0;
/** Struct */
export interface StorageMetadataV0 extends Struct {
/** Text */
readonly prefix: Text;
/** Vec<StorageFunctionMetadataV0> */
readonly functions: Vec<StorageFunctionMetadataV0>;
}
@@ -45,5 +45,13 @@ describe('Bool', (): void => {
it('compares agains a Bool', (): void => {
expect(new Bool(false).eq(new Bool(false))).toBe(true);
});
it('has isTrue', (): void => {
expect(new Bool(true).isTrue).toBe(true);
});
it('has isFalse', (): void => {
expect(new Bool(true).isFalse).toBe(false);
});
});
});
+14
View File
@@ -54,6 +54,20 @@ export default class Bool extends Boolean implements Codec {
return false;
}
/**
* @description Checks if the value is an empty value (always false)
*/
public get isFalse (): boolean {
return !this.isTrue;
}
/**
* @description Checks if the value is an empty value (always false)
*/
public get isTrue (): boolean {
return this.valueOf();
}
/**
* @description Compares the value of the input to see if there is a match
*/
@@ -79,14 +79,14 @@ export default class ConsensusEngineId extends U32 {
/**
* @description From the input bytes, decode into an author
*/
public extractAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId {
public extractAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId | undefined {
if (this.isAura) {
return this.getAuraAuthor(bytes, sessionValidators);
} else if (this.isBabe) {
return this.getBabeAuthor(bytes, sessionValidators);
}
throw new Error('Invalid engine for extractAuthor conversion');
return undefined;
}
/**
+1 -3
View File
@@ -370,9 +370,7 @@ function generateInterfaceRegistry (): void {
const primitives = Object
.keys(primitiveClasses)
.filter((name): boolean =>
!!name.indexOf('Generic') && !!name.indexOf('Metadata')
)
.filter((name): boolean => !!name.indexOf('Generic'))
.reduce((accumulator, primitiveName): string => {
setImports(imports, [primitiveName]);