Support Metadata V8 (#1441)
* Support Metadata V8 * Update V7 references, introduce *Latest (as applicable) * Add v8 static metadata * Bump to latest metadata
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import { ModuleConstantMetadataV7 } from '@polkadot/types/interfaces';
|
||||
import { ModuleConstantMetadataLatest } from '@polkadot/types/interfaces';
|
||||
|
||||
export interface ConstantCodec extends Codec {
|
||||
meta: ModuleConstantMetadataV7;
|
||||
meta: ModuleConstantMetadataLatest;
|
||||
}
|
||||
|
||||
export type ModuleConstants = Record<string, Codec>;
|
||||
|
||||
@@ -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 { Call, FunctionMetadataV7 } from '@polkadot/types/interfaces';
|
||||
import { Call, FunctionMetadataLatest } from '@polkadot/types/interfaces';
|
||||
import { CallFunction } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
@@ -21,7 +21,7 @@ export default function createDescriptor (
|
||||
section: string,
|
||||
sectionIndex: number,
|
||||
methodIndex: number,
|
||||
callMetadata: FunctionMetadataV7
|
||||
callMetadata: FunctionMetadataLatest
|
||||
): CallFunction {
|
||||
const callIndex = new Uint8Array([sectionIndex, methodIndex]);
|
||||
const expectedArgs = callMetadata.args;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import '@polkadot/types/injector';
|
||||
|
||||
import { createType, Metadata } from '@polkadot/types';
|
||||
import json from '@polkadot/types/Metadata/v7/static';
|
||||
import json from '@polkadot/types/Metadata/static';
|
||||
|
||||
import fromMetadata from '.';
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { Calls, ModulesWithCalls } from '@polkadot/types/types';
|
||||
|
||||
import { ModuleMetadataV7 } from '@polkadot/types/Metadata/v7/Metadata';
|
||||
import { ModuleMetadataV8 } from '@polkadot/types/Metadata/v8/Metadata';
|
||||
import Metadata from '@polkadot/types/Metadata';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
@@ -19,7 +19,7 @@ import createUnchecked from './createUnchecked';
|
||||
export default function fromMetadata (metadata: Metadata): ModulesWithCalls {
|
||||
return metadata.asLatest.modules
|
||||
.filter(({ calls }): boolean => calls.isSome)
|
||||
.reduce((result, modul: ModuleMetadataV7, sectionIndex): ModulesWithCalls => {
|
||||
.reduce((result, modul: ModuleMetadataV8, sectionIndex): ModulesWithCalls => {
|
||||
const section = stringCamelCase(modul.name.toString());
|
||||
|
||||
result[section] = modul.calls.unwrap().reduce((newModule, callMetadata, methodIndex): Calls => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Codec } from '@polkadot/types/types';
|
||||
import BN from 'bn.js';
|
||||
import { Bytes, Compact, StorageKey, U8a } from '@polkadot/types';
|
||||
import { createType, createTypeUnsafe } from '@polkadot/types/codec';
|
||||
import { StorageEntryMetadata, StorageEntryType } from '@polkadot/types/Metadata/v7/Storage';
|
||||
import { StorageEntryMetadata, StorageEntryType } from '@polkadot/types/Metadata/v8/Storage';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
@@ -121,8 +121,8 @@ function extendLinkedMap ({ meta: { documentation, name, type } }: CreateItemFn,
|
||||
// meta fallback only applies to actual entry values, create one for head
|
||||
headFn.meta = new StorageEntryMetadata({
|
||||
name,
|
||||
modifier: createType('StorageEntryModifierV7', 1), // required
|
||||
type: new StorageEntryType(createType('PlainTypeV7', type.asMap.key), 0),
|
||||
modifier: createType('StorageEntryModifierLatest', 1), // required
|
||||
type: new StorageEntryType(createType('PlainTypeLatest', type.asMap.key), 0),
|
||||
fallback: new Bytes(createTypeUnsafe(type.asMap.key.toString()).toHex()),
|
||||
documentation
|
||||
});
|
||||
|
||||
@@ -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 { StorageEntryMetadata, StorageEntryType } from '@polkadot/types/Metadata/v7/Storage';
|
||||
import { StorageEntryMetadata, StorageEntryType } from '@polkadot/types/Metadata/v8/Storage';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { createType, Text, Vec } from '@polkadot/types';
|
||||
|
||||
@@ -19,7 +19,7 @@ const createRuntimeFunction = (method: string, key: string, { documentation, typ
|
||||
{
|
||||
meta: {
|
||||
documentation: new Vec(Text, [documentation]),
|
||||
modifier: createType('StorageEntryModifierV7', 1), // required
|
||||
modifier: createType('StorageEntryModifierLatest', 1), // required
|
||||
type: new StorageEntryType(type, 0),
|
||||
toJSON: (): any => key
|
||||
} as unknown as StorageEntryMetadata,
|
||||
|
||||
Reference in New Issue
Block a user