Support Metadata V9 (#1600)
* Metadata v9 definitions * Update stay V5 in V9 * WIP... * Small adjustments * toV9 looks sane ... may work * v9 tests passes * v8 tests pass... will get to overall... not checked * Cleanup type * Spread storage * Missing semi * Cleanup testUtil * Cater for prefix map key generation * Remove DoubleMap<T> wrapper * Remove DoubleMap<T> wrapper * WIP result types not yet operational * Output formatting * Add missing name prop * Move v9 -> v10, v9 only as storage changes (next up) * Support v9 & v10 * Fixup linked maps
This commit is contained in:
@@ -20,7 +20,7 @@ import { map, switchMap } from 'rxjs/operators';
|
||||
import decorateDerive, { ExactDerive } from '@polkadot/api-derive';
|
||||
import RpcCore from '@polkadot/rpc-core';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
import { Metadata, Null, u64, TypeRegistry } from '@polkadot/types';
|
||||
import { Metadata, Null, TypeRegistry, u64, Vec } from '@polkadot/types';
|
||||
import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/primitive/Extrinsic/constants';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
@@ -255,8 +255,10 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
: [creator, ...args];
|
||||
|
||||
// FIXME We probably want to be able to query the full list with non-subs as well
|
||||
const decorated = this.hasSubscriptions && creator.headKey
|
||||
? this.decorateStorageEntryLinked(creator, decorateMethod)
|
||||
const decorated = this.hasSubscriptions && creator.iterKey
|
||||
? creator.meta.type.asMap.kind.isLinkedMap
|
||||
? this.decorateStorageLinked(creator, decorateMethod)
|
||||
: this.decorateStoragePrefixed(creator, decorateMethod)
|
||||
: decorateMethod((...args: any[]): Observable<Codec> => (
|
||||
this.hasSubscriptions
|
||||
? this._rpcCore.state
|
||||
@@ -292,7 +294,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
return this.decorateFunctionMeta(creator, decorated) as unknown as QueryableStorageEntry<ApiType>;
|
||||
}
|
||||
|
||||
private decorateStorageEntryLinked<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
|
||||
private decorateStorageLinked<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
|
||||
const result: Map<Codec, [Codec, Linkage<Codec>]> = new Map();
|
||||
let subject: BehaviorSubject<LinkageResult>;
|
||||
let head: Codec | null = null;
|
||||
@@ -355,11 +357,31 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
.subscribeStorage<[[Codec, Linkage<Codec>]]>([[creator, ...args]])
|
||||
.pipe(map(([data]): [Codec, Linkage<Codec>] => data))
|
||||
: this._rpcCore.state
|
||||
.subscribeStorage<[LinkageResult]>([creator.headKey])
|
||||
.subscribeStorage<[LinkageResult]>([creator.iterKey])
|
||||
.pipe(switchMap(([key]): Observable<LinkageResult> => getNext(head = key)))
|
||||
);
|
||||
}
|
||||
|
||||
private decorateStoragePrefixed<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
|
||||
const outputType = creator.meta.type.asMap.value.toString();
|
||||
|
||||
return decorateMethod((...args: any[]): Observable<Codec> =>
|
||||
args.length
|
||||
? this._rpcCore.state
|
||||
.subscribeStorage<[Codec]>([[creator, ...args]])
|
||||
.pipe(map(([data]): Codec => data))
|
||||
: this._rpcCore.state
|
||||
// FIXME This should really be some sort of subscription, so we can get stuff as
|
||||
// it changes (as of now it is a one-shot query). Not sure how to do this though...
|
||||
.getKeys(creator.iterKey)
|
||||
.pipe(switchMap((keys): Observable<Vec<Codec>> =>
|
||||
this._rpcCore.state.subscribeStorage(
|
||||
keys.map((key) => key.setOutputType(outputType))
|
||||
)
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
protected decorateDeriveRx (decorateMethod: DecorateMethod<ApiType>): DeriveAllSections<'rxjs', ExactDerive> {
|
||||
// Pull in derive from api-derive
|
||||
const derive = decorateDerive(this._rx as ApiInterfaceRx, this._options.derives);
|
||||
|
||||
@@ -18,7 +18,7 @@ describe('createFunction', (): void => {
|
||||
section: 'timestamp',
|
||||
method: 'Now',
|
||||
meta: { type: {} } as any
|
||||
})()
|
||||
}, { metaVersion: 8 })()
|
||||
).toEqual(
|
||||
Uint8Array.from([64, 14, 73, 68, 207, 217, 141, 111, 76, 195, 116, 209, 111, 90, 78, 63, 156]) // Length-prefixed
|
||||
);
|
||||
@@ -36,7 +36,8 @@ describe('createFunction', (): void => {
|
||||
},
|
||||
{
|
||||
key: ':auth:len',
|
||||
skipHashing: true
|
||||
skipHashing: true,
|
||||
metaVersion: 8
|
||||
}
|
||||
).method
|
||||
).toEqual('authorityCount');
|
||||
@@ -56,7 +57,8 @@ describe('createFunction', (): void => {
|
||||
},
|
||||
{
|
||||
key,
|
||||
skipHashing: true
|
||||
skipHashing: true,
|
||||
metaVersion: 8
|
||||
}
|
||||
)()
|
||||
).toEqual(
|
||||
@@ -88,7 +90,7 @@ describe('createFunction', (): void => {
|
||||
}
|
||||
}
|
||||
} as any
|
||||
});
|
||||
}, { metaVersion: 8 });
|
||||
});
|
||||
|
||||
it('should return correct key', (): void => {
|
||||
@@ -120,7 +122,7 @@ describe('createFunction', (): void => {
|
||||
}
|
||||
}
|
||||
} as any
|
||||
});
|
||||
}, { metaVersion: 8 });
|
||||
|
||||
// the value of the Null type key does not effect the result
|
||||
expect(u8aToHex(storageFn(['any', [1, 2, 3]]))).toEqual(u8aToHex(storageFn([[1, 2, 3], [1, 2, 3]])));
|
||||
|
||||
@@ -7,13 +7,15 @@ import { Codec, Registry } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Compact, U8a, createType, createTypeUnsafe } from '@polkadot/types/codec';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import StorageKey, { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
import { xxhashAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import getHasher, { HasherFunction } from './getHasher';
|
||||
|
||||
export interface CreateItemOptions {
|
||||
key?: string;
|
||||
metaVersion: number;
|
||||
skipHashing?: boolean; // We don't hash the keys defined in ./substrate.ts
|
||||
}
|
||||
|
||||
@@ -24,20 +26,21 @@ export interface CreateItemFn {
|
||||
section: string;
|
||||
}
|
||||
|
||||
interface IterFn {
|
||||
(): U8a;
|
||||
meta: StorageEntryMetadataLatest;
|
||||
}
|
||||
|
||||
type CreateArgType = boolean | string | number | null | BN | Uint8Array | Codec;
|
||||
|
||||
const EMPTY_U8A = new Uint8Array([]);
|
||||
const NULL_HASHER = (value: Uint8Array): Uint8Array => value;
|
||||
|
||||
// with the prefix, method & options, create both the string & raw keys
|
||||
function createKeys ({ method, prefix }: CreateItemFn, options: CreateItemOptions): [string, Uint8Array] {
|
||||
const stringKey = options.key
|
||||
function expandKey ({ method, prefix }: CreateItemFn, options: CreateItemOptions): string {
|
||||
return options.key
|
||||
? options.key
|
||||
: `${prefix} ${method}`;
|
||||
|
||||
return [
|
||||
stringKey,
|
||||
stringToU8a(stringKey)
|
||||
];
|
||||
}
|
||||
|
||||
// get the hashers, the base (and in the case of DoubleMap), the second key
|
||||
@@ -55,45 +58,74 @@ function getHashers ({ meta: { type } }: CreateItemFn): [HasherFunction, HasherF
|
||||
return [getHasher()];
|
||||
}
|
||||
|
||||
// create a base prefixed key
|
||||
function createPrefixedKey ({ method, prefix }: CreateItemFn): Uint8Array {
|
||||
return u8aConcat(xxhashAsU8a(prefix, 128), xxhashAsU8a(method, 128));
|
||||
}
|
||||
|
||||
// create a key for a DoubleMap type
|
||||
function createKeyDoubleMap (registry: Registry, { meta: { name, type } }: CreateItemFn, rawKey: Uint8Array, args: [CreateArgType, CreateArgType], [hasher, key2Hasher]: [HasherFunction, HasherFunction?]): Uint8Array {
|
||||
function createKeyDoubleMap (registry: Registry, itemFn: CreateItemFn, stringKey: string, args: [CreateArgType, CreateArgType], [hasher1, hasher2]: [HasherFunction, HasherFunction?], metaVersion: number): Uint8Array {
|
||||
const { meta: { name, type } } = itemFn;
|
||||
|
||||
// since we are passing an almost-unknown through, trust, but verify
|
||||
assert(
|
||||
Array.isArray(args) && !isUndefined(args[0]) && !isNull(args[0]) && !isUndefined(args[1]) && !isNull(args[1]),
|
||||
`${name} is a DoubleMap and requires two arguments`
|
||||
);
|
||||
|
||||
const [key1, key2] = args;
|
||||
const type1 = type.asDoubleMap.key1.toString();
|
||||
const type2 = type.asDoubleMap.key2.toString();
|
||||
const param1Encoded = u8aConcat(rawKey, createTypeUnsafe(registry, type1, [key1]).toU8a(true));
|
||||
const param1Hashed = hasher(param1Encoded);
|
||||
// if this fails, we have bigger issues
|
||||
assert(!isUndefined(hasher2), '2 hashing functions should be defined for DoubleMaps');
|
||||
|
||||
// If this fails it means the getHashers function failed - and we have much bigger issues
|
||||
const param2Hashed = (key2Hasher as HasherFunction)(createTypeUnsafe(registry, type2, [key2]).toU8a(true));
|
||||
const [key1, key2] = args;
|
||||
const map = type.asDoubleMap;
|
||||
const val1 = createTypeUnsafe(registry, map.key1.toString(), [key1]).toU8a(true);
|
||||
const val2 = createTypeUnsafe(registry, map.key2.toString(), [key2]).toU8a(true);
|
||||
|
||||
// as per createKey, always add the length prefix (underlying it is Bytes)
|
||||
return Compact.addLengthPrefix(u8aConcat(param1Hashed, param2Hashed));
|
||||
return Compact.addLengthPrefix(
|
||||
metaVersion <= 8
|
||||
? u8aConcat(
|
||||
hasher1(u8aConcat(stringToU8a(stringKey), val1)),
|
||||
hasher2(val2)
|
||||
)
|
||||
: u8aConcat(
|
||||
createPrefixedKey(itemFn),
|
||||
hasher1(val1),
|
||||
hasher2(val2)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// create a key for either a map or a plain value
|
||||
function createKey (registry: Registry, { meta: { name, type } }: CreateItemFn, rawKey: Uint8Array, arg: CreateArgType, hasher: (value: Uint8Array) => Uint8Array): Uint8Array {
|
||||
let key = rawKey;
|
||||
function createKey (registry: Registry, itemFn: CreateItemFn, stringKey: string, arg: CreateArgType, hasher: (value: Uint8Array) => Uint8Array, metaVersion: number): Uint8Array {
|
||||
const { meta: { name, type } } = itemFn;
|
||||
let key: Uint8Array | undefined;
|
||||
let param: Uint8Array = EMPTY_U8A;
|
||||
|
||||
if (type.isMap) {
|
||||
const map = type.asMap;
|
||||
|
||||
assert(!isUndefined(arg) && !isNull(arg), `${name} is a Map and requires one argument`);
|
||||
|
||||
const mapType = type.asMap.key.toString();
|
||||
const param = createTypeUnsafe(registry, mapType, [arg]).toU8a();
|
||||
param = createTypeUnsafe(registry, map.key.toString(), [arg]).toU8a();
|
||||
|
||||
key = u8aConcat(key, param);
|
||||
// prefix maps are using prefixes to optimize the trie, so the key generation are
|
||||
// done differently where the prefix/method are hashed separately with only the
|
||||
// parameter for the key being attached via the hasher
|
||||
if (map.kind.isPrefixedMap) {
|
||||
key = u8aConcat(createPrefixedKey(itemFn), hasher(param));
|
||||
}
|
||||
}
|
||||
|
||||
// StorageKey is a Bytes, so is length-prefixed
|
||||
return Compact.addLengthPrefix(hasher(key));
|
||||
return Compact.addLengthPrefix(key || (
|
||||
metaVersion <= 8
|
||||
? hasher(u8aConcat(stringToU8a(stringKey), param))
|
||||
: u8aConcat(createPrefixedKey(itemFn), param.length ? hasher(param) : EMPTY_U8A)
|
||||
));
|
||||
}
|
||||
|
||||
// attach the metadata to expsnd to a StorageFunction
|
||||
// attach the metadata to expand to a StorageFunction
|
||||
function expandWithMeta ({ meta, method, prefix, section }: CreateItemFn, storageFn: StorageEntry): StorageEntry {
|
||||
storageFn.meta = meta;
|
||||
storageFn.method = stringLowerFirst(method);
|
||||
@@ -110,28 +142,41 @@ function expandWithMeta ({ meta, method, prefix, section }: CreateItemFn, storag
|
||||
return storageFn;
|
||||
}
|
||||
|
||||
// attch the head key hashing for linked maps
|
||||
function extendLinkedMap (registry: Registry, { meta: { documentation, name, type } }: CreateItemFn, storageFn: StorageEntry, stringKey: string, hasher: HasherFunction): StorageEntry {
|
||||
const headHash = new U8a(registry, hasher(`head of ${stringKey}`));
|
||||
const headFn: any = (): U8a =>
|
||||
headHash;
|
||||
function extendHeadMeta (registry: Registry, { meta: { documentation, name, type }, section }: CreateItemFn, { method }: StorageEntry, iterFn: () => U8a): StorageKey {
|
||||
const map = type.asMap;
|
||||
const outputType = map.key.toString();
|
||||
|
||||
// metadata with a fallback value using the type of the key, the normal
|
||||
// meta fallback only applies to actual entry values, create one for head
|
||||
headFn.meta = createType(registry, 'StorageEntryMetadataLatest', {
|
||||
(iterFn as IterFn).meta = createType(registry, 'StorageEntryMetadataLatest', {
|
||||
name,
|
||||
modifier: createType(registry, 'StorageEntryModifierLatest', 1), // required
|
||||
type: createType(registry, 'StorageEntryTypeLatest', createType(registry, 'PlainTypeLatest', type.asMap.key), 0),
|
||||
fallback: createType(registry, 'Bytes', createTypeUnsafe(registry, type.asMap.key.toString()).toHex()),
|
||||
type: createType(registry, 'StorageEntryTypeLatest', createType(registry, 'PlainTypeLatest', map.key), 0),
|
||||
fallback: createType(registry, 'Bytes', createTypeUnsafe(registry, outputType).toHex()),
|
||||
documentation
|
||||
});
|
||||
|
||||
// here we pass the section/method through as well - these are not on
|
||||
// the function itself, so specify these explicitly to the constructor
|
||||
storageFn.headKey = createType(registry, 'StorageKey', headFn, {
|
||||
method: storageFn.method,
|
||||
section: `head of ${storageFn.section}`
|
||||
});
|
||||
return createType(registry, 'StorageKey', iterFn, { method, section });
|
||||
}
|
||||
|
||||
// attach the head key hashing for linked maps
|
||||
function extendLinkedMap (registry: Registry, itemFn: CreateItemFn, storageFn: StorageEntry, stringKey: string, hasher: HasherFunction, metaVersion: number): StorageEntry {
|
||||
const key = metaVersion <= 8
|
||||
? hasher(`head of ${stringKey}`)
|
||||
: u8aConcat(xxhashAsU8a(itemFn.prefix, 128), xxhashAsU8a(`HeadOf${itemFn.method}`, 128));
|
||||
|
||||
storageFn.iterKey = extendHeadMeta(registry, itemFn, storageFn, (): U8a =>
|
||||
new U8a(registry, key)
|
||||
);
|
||||
|
||||
return storageFn;
|
||||
}
|
||||
|
||||
// attach the full list hashing for prefixed maps
|
||||
function extendPrefixedMap (registry: Registry, itemFn: CreateItemFn, storageFn: StorageEntry): StorageEntry {
|
||||
storageFn.iterKey = extendHeadMeta(registry, itemFn, storageFn, (): U8a =>
|
||||
new U8a(registry, createPrefixedKey(itemFn))
|
||||
);
|
||||
|
||||
return storageFn;
|
||||
}
|
||||
@@ -146,10 +191,10 @@ function extendLinkedMap (registry: Registry, { meta: { documentation, name, typ
|
||||
* are not known at runtime (from state_getMetadata), they need to be supplied
|
||||
* by us manually at compile time.
|
||||
*/
|
||||
export default function createFunction (registry: Registry, item: CreateItemFn, options: CreateItemOptions = {}): StorageEntry {
|
||||
const { meta: { type } } = item;
|
||||
const [stringKey, rawKey] = createKeys(item, options);
|
||||
const [hasher, key2Hasher] = getHashers(item);
|
||||
export default function createFunction (registry: Registry, itemFn: CreateItemFn, options: CreateItemOptions): StorageEntry {
|
||||
const { meta: { type } } = itemFn;
|
||||
const stringKey = expandKey(itemFn, options);
|
||||
const [hasher, key2Hasher] = getHashers(itemFn);
|
||||
|
||||
// Can only have zero or one argument:
|
||||
// - storage.balances.freeBalance(address)
|
||||
@@ -157,13 +202,19 @@ export default function createFunction (registry: Registry, item: CreateItemFn,
|
||||
// For doublemap queries the params is passed in as an tuple, [key1, key2]
|
||||
const _storageFn = (arg?: CreateArgType | [CreateArgType?, CreateArgType?]): Uint8Array =>
|
||||
type.isDoubleMap
|
||||
? createKeyDoubleMap(registry, item, rawKey, arg as [CreateArgType, CreateArgType], [hasher, key2Hasher])
|
||||
: createKey(registry, item, rawKey, arg as CreateArgType, options.skipHashing ? NULL_HASHER : hasher);
|
||||
? createKeyDoubleMap(registry, itemFn, stringKey, arg as [CreateArgType, CreateArgType], [hasher, key2Hasher], options.metaVersion)
|
||||
: createKey(registry, itemFn, stringKey, arg as CreateArgType, options.skipHashing ? NULL_HASHER : hasher, options.metaVersion);
|
||||
|
||||
const storageFn = expandWithMeta(item, _storageFn as StorageEntry);
|
||||
const storageFn = expandWithMeta(itemFn, _storageFn as StorageEntry);
|
||||
|
||||
if (type.isMap && type.asMap.linked.isTrue) {
|
||||
extendLinkedMap(registry, item, storageFn, stringKey, hasher);
|
||||
if (type.isMap) {
|
||||
const map = type.asMap;
|
||||
|
||||
if (map.kind.isLinkedMap) {
|
||||
extendLinkedMap(registry, itemFn, storageFn, stringKey, hasher, options.metaVersion);
|
||||
} else if (map.kind.isPrefixedMap) {
|
||||
extendPrefixedMap(registry, itemFn, storageFn);
|
||||
}
|
||||
}
|
||||
|
||||
return storageFn;
|
||||
|
||||
@@ -36,11 +36,11 @@ export default function fromMetadata (registry: Registry, metadata: Metadata): S
|
||||
method,
|
||||
prefix,
|
||||
section
|
||||
});
|
||||
}, { metaVersion: metadata.version });
|
||||
|
||||
return newModule;
|
||||
}, {} as unknown as ModuleStorage);
|
||||
|
||||
return result;
|
||||
}, { ...getStorage(registry) });
|
||||
}, { ...getStorage(registry, metadata.version) });
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import getStorage from './storage';
|
||||
|
||||
describe('storage', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const storage = getStorage(registry);
|
||||
const storage = getStorage(registry, 8);
|
||||
|
||||
it('should return well known keys', (): void => {
|
||||
expect(typeof storage.substrate).toBe('object');
|
||||
|
||||
@@ -8,12 +8,12 @@ import { Storage } from '../../types';
|
||||
|
||||
import * as substrate from './substrate';
|
||||
|
||||
export default function getStorage (registry: Registry): Storage {
|
||||
export default function getStorage (registry: Registry, metaVersion: number): Storage {
|
||||
return {
|
||||
substrate: Object
|
||||
.entries(substrate)
|
||||
.reduce((storage: Record<string, StorageEntry>, [key, fn]): Record<string, StorageEntry> => {
|
||||
(storage as any)[key] = fn(registry);
|
||||
(storage as any)[key] = fn(registry, metaVersion);
|
||||
|
||||
return storage;
|
||||
}, {})
|
||||
|
||||
@@ -12,32 +12,32 @@ describe('substrate', (): void => {
|
||||
// @deprecated: The ':auth:' (authorityPrefix) and ':auth:len' (authorityCount) storage keys
|
||||
// have been removed in https://github.com/paritytech/substrate/pull/2802
|
||||
it('authorityCount should return the correct storage key', (): void => {
|
||||
expect(authorityCount(registry)()).toEqual(Uint8Array.from([36, 58, 97, 117, 116, 104, 58, 108, 101, 110])); // Length-prefixed
|
||||
expect(authorityCount(registry, 8)()).toEqual(Uint8Array.from([36, 58, 97, 117, 116, 104, 58, 108, 101, 110])); // Length-prefixed
|
||||
});
|
||||
|
||||
it('authorityPrefix should return the correct storage key', (): void => {
|
||||
expect(authorityPrefix(registry)()).toEqual(Uint8Array.from([24, 58, 97, 117, 116, 104, 58])); // Length-prefixed
|
||||
expect(authorityPrefix(registry, 8)()).toEqual(Uint8Array.from([24, 58, 97, 117, 116, 104, 58])); // Length-prefixed
|
||||
});
|
||||
|
||||
it('changesTrieConfig should return the correct storage key', (): void => {
|
||||
expect(changesTrieConfig(registry)()).toEqual(Uint8Array.from([52, 58, 99, 104, 97, 110, 103, 101, 115, 95, 116, 114, 105, 101])); // Length-prefixed
|
||||
expect(changesTrieConfig(registry, 8)()).toEqual(Uint8Array.from([52, 58, 99, 104, 97, 110, 103, 101, 115, 95, 116, 114, 105, 101])); // Length-prefixed
|
||||
});
|
||||
|
||||
it('childStorageKeyPrefix should return the correct storage key', (): void => {
|
||||
expect(childStorageKeyPrefix(registry)()).toEqual(Uint8Array.from([60, 58, 99, 104, 105, 108, 100, 95, 115, 116, 111, 114, 97, 103, 101, 58])); // Length-prefixed
|
||||
expect(childStorageKeyPrefix(registry, 8)()).toEqual(Uint8Array.from([60, 58, 99, 104, 105, 108, 100, 95, 115, 116, 111, 114, 97, 103, 101, 58])); // Length-prefixed
|
||||
});
|
||||
|
||||
it('code should return the correct storage key', (): void => {
|
||||
expect(code(registry)()).toEqual(Uint8Array.from([20, 58, 99, 111, 100, 101])); // Length-prefixed
|
||||
expect(code(registry, 8)()).toEqual(Uint8Array.from([20, 58, 99, 111, 100, 101])); // Length-prefixed
|
||||
});
|
||||
|
||||
it('extrinsicIndex should return the correct storage key', (): void => {
|
||||
expect(extrinsicIndex(registry)()).toEqual(
|
||||
expect(extrinsicIndex(registry, 8)()).toEqual(
|
||||
Uint8Array.from([64, 58, 101, 120, 116, 114, 105, 110, 115, 105, 99, 95, 105, 110, 100, 101, 120]) // Length-prefixed
|
||||
);
|
||||
});
|
||||
|
||||
it('heapPages should return the correct storage key', (): void => {
|
||||
expect(heapPages(registry)()).toEqual(Uint8Array.from([40, 58, 104, 101, 97, 112, 112, 97, 103, 101, 115])); // Length-prefixed
|
||||
expect(heapPages(registry, 8)()).toEqual(Uint8Array.from([40, 58, 104, 101, 97, 112, 112, 97, 103, 101, 115])); // Length-prefixed
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,8 +16,8 @@ interface SubstrateMetadata {
|
||||
}
|
||||
|
||||
// Small helper function to factorize code on this page.
|
||||
function createRuntimeFunction (method: string, key: string, { documentation, type }: SubstrateMetadata): (registry: Registry) => StorageEntry {
|
||||
return (registry: Registry): StorageEntry =>
|
||||
function createRuntimeFunction (method: string, key: string, { documentation, type }: SubstrateMetadata): (registry: Registry, metaVersion: number) => StorageEntry {
|
||||
return (registry: Registry, metaVersion: number): StorageEntry =>
|
||||
createFunction(registry, {
|
||||
meta: {
|
||||
documentation: createType(registry, 'Vec<Text>', [documentation]),
|
||||
@@ -28,7 +28,7 @@ function createRuntimeFunction (method: string, key: string, { documentation, ty
|
||||
method,
|
||||
prefix: 'Substrate',
|
||||
section: 'substrate'
|
||||
}, { key, skipHashing: true });
|
||||
}, { key, metaVersion, skipHashing: true });
|
||||
}
|
||||
|
||||
// @deprecated: The ':auth:' (authorityPrefix) and ':auth:len' (authorityCount) storage keys
|
||||
|
||||
@@ -2,13 +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 { MetadataLatest, MetadataV0, MetadataV1, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8 } from '@polkadot/types/interfaces/metadata';
|
||||
import { MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, MetadataV10 } from '@polkadot/types/interfaces/metadata';
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import Enum from '@polkadot/types/codec/Enum';
|
||||
import { createType } from '@polkadot/types/codec/create/createType';
|
||||
import Struct from '@polkadot/types/codec/Struct';
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import MagicNumber from './MagicNumber';
|
||||
import v0ToV1 from './v0/toV1';
|
||||
@@ -19,178 +18,13 @@ import v4ToV5 from './v4/toV5';
|
||||
import v5ToV6 from './v5/toV6';
|
||||
import v6ToV7 from './v6/toV7';
|
||||
import v7ToV8 from './v7/toV8';
|
||||
import v8ToV9 from './v8/toV9';
|
||||
import v9ToV10 from './v9/toV10';
|
||||
import { getUniqTypes, toCallsOnly } from './util';
|
||||
|
||||
type MetaMapped = MetadataV0 | MetadataV1 | MetadataV2 | MetadataV3 | MetadataV4 | MetadataV5 | MetadataV6 | MetadataV7;
|
||||
type MetaVersions = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
||||
type MetaAsX = 'asV0' | 'asV1' | 'asV2' | 'asV3' | 'asV4' | 'asV5' | 'asV6' | 'asV7';
|
||||
|
||||
class MetadataEnum extends Enum {
|
||||
constructor (registry: Registry, value?: any, index?: number) {
|
||||
super(registry, {
|
||||
V0: 'MetadataV0', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V1: 'MetadataV1', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V2: 'MetadataV2', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V3: 'MetadataV3', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V4: 'MetadataV4', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V5: 'MetadataV5', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V6: 'MetadataV6', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V7: 'MetadataV7', // once rolled-out, can replace this with MetadataDeprecated
|
||||
V8: 'MetadataV8'
|
||||
}, value, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V0 object
|
||||
*/
|
||||
public get asV0 (): MetadataV0 {
|
||||
assert(this.isV0, `Cannot convert '${this.type}' via asV0`);
|
||||
|
||||
return this.value as MetadataV0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V1 object
|
||||
*/
|
||||
public get asV1 (): MetadataV1 {
|
||||
assert(this.isV1, `Cannot convert '${this.type}' via asV1`);
|
||||
|
||||
return this.value as MetadataV1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V2 object
|
||||
*/
|
||||
public get asV2 (): MetadataV2 {
|
||||
assert(this.isV2, `Cannot convert '${this.type}' via asV2`);
|
||||
|
||||
return this.value as MetadataV2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V3 object
|
||||
*/
|
||||
public get asV3 (): MetadataV3 {
|
||||
assert(this.isV3, `Cannot convert '${this.type}' via asV3`);
|
||||
|
||||
return this.value as MetadataV3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V4 object
|
||||
*/
|
||||
public get asV4 (): MetadataV4 {
|
||||
assert(this.isV4, `Cannot convert '${this.type}' via asV4`);
|
||||
|
||||
return this.value as MetadataV4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V5 object
|
||||
*/
|
||||
public get asV5 (): MetadataV5 {
|
||||
assert(this.isV5, `Cannot convert '${this.type}' via asV5`);
|
||||
|
||||
return this.value as MetadataV5;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V6 object
|
||||
*/
|
||||
public get asV6 (): MetadataV6 {
|
||||
assert(this.isV6, `Cannot convert '${this.type}' via asV6`);
|
||||
|
||||
return this.value as MetadataV6;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V7 object
|
||||
*/
|
||||
public get asV7 (): MetadataV7 {
|
||||
assert(this.isV7, `Cannot convert '${this.type}' via asV7`);
|
||||
|
||||
return this.value as MetadataV7;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V8 object
|
||||
*/
|
||||
public get asV8 (): MetadataV8 {
|
||||
assert(this.isV8, `Cannot convert '${this.type}' via asV8`);
|
||||
|
||||
return this.value as MetadataV8;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if Deprecated
|
||||
*/
|
||||
public get isDeprecated (): boolean {
|
||||
return this.type === 'MetadataDeprectated';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V0
|
||||
*/
|
||||
public get isV0 (): boolean {
|
||||
return this.type === 'V0';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V1
|
||||
*/
|
||||
public get isV1 (): boolean {
|
||||
return this.type === 'V1';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V2
|
||||
*/
|
||||
public get isV2 (): boolean {
|
||||
return this.type === 'V2';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V3
|
||||
*/
|
||||
public get isV3 (): boolean {
|
||||
return this.type === 'V3';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V4
|
||||
*/
|
||||
public get isV4 (): boolean {
|
||||
return this.type === 'V4';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V5
|
||||
*/
|
||||
public get isV5 (): boolean {
|
||||
return this.type === 'V5';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V6
|
||||
*/
|
||||
public get isV6 (): boolean {
|
||||
return this.type === 'V6';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V7
|
||||
*/
|
||||
public get isV7 (): boolean {
|
||||
return this.type === 'V7';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V8
|
||||
*/
|
||||
public get isV8 (): boolean {
|
||||
return this.type === 'V8';
|
||||
}
|
||||
}
|
||||
type MetaMapped = MetadataV0 | MetadataV1 | MetadataV2 | MetadataV3 | MetadataV4 | MetadataV5 | MetadataV6 | MetadataV7 | MetadataV8 | MetadataV9 | MetadataV10;
|
||||
type MetaVersions = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
||||
type MetaAsX = 'asV0' | 'asV1' | 'asV2' | 'asV3' | 'asV4' | 'asV5' | 'asV6' | 'asV7' | 'asV8' | 'asV9' | 'asV10';
|
||||
|
||||
/**
|
||||
* @name MetadataVersioned
|
||||
@@ -203,7 +37,7 @@ export default class MetadataVersioned extends Struct {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
super(registry, {
|
||||
magicNumber: MagicNumber,
|
||||
metadata: MetadataEnum
|
||||
metadata: 'MetadataAll'
|
||||
}, value);
|
||||
|
||||
registry.setMetadata(this);
|
||||
@@ -216,8 +50,8 @@ export default class MetadataVersioned extends Struct {
|
||||
}
|
||||
|
||||
private getVersion<T extends MetaMapped, F extends MetaMapped> (version: MetaVersions, fromPrev: (registry: Registry, input: F) => T): T {
|
||||
const asCurr: MetaAsX = `asV${version}` as any;
|
||||
const asPrev: MetaAsX = `asV${version - 1}` as any;
|
||||
const asCurr = `asV${version}` as MetaAsX;
|
||||
const asPrev = `asV${version - 1}` as MetaAsX;
|
||||
|
||||
if (this.assertVersion(version)) {
|
||||
return this.metadata[asCurr] as T;
|
||||
@@ -236,7 +70,7 @@ export default class MetadataVersioned extends Struct {
|
||||
public get asCallsOnly (): MetadataVersioned {
|
||||
return new MetadataVersioned(this.registry, {
|
||||
magicNumber: this.magicNumber,
|
||||
metadata: new MetadataEnum(this.registry, toCallsOnly(this.registry, this.asLatest), this.version)
|
||||
metadata: createType(this.registry, 'MetadataAll', toCallsOnly(this.registry, this.asLatest), this.version)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -305,11 +139,25 @@ export default class MetadataVersioned extends Struct {
|
||||
return this.getVersion(8, v7ToV8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V9 object
|
||||
*/
|
||||
public get asV9 (): MetadataV9 {
|
||||
return this.getVersion(9, v8ToV9);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V10 object
|
||||
*/
|
||||
public get asV10 (): MetadataV10 {
|
||||
return this.getVersion(10, v9ToV10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a latest version object
|
||||
*/
|
||||
public get asLatest (): MetadataLatest {
|
||||
return this.asV8;
|
||||
return this.asV10;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,8 +170,8 @@ export default class MetadataVersioned extends Struct {
|
||||
/**
|
||||
* @description the metadata wrapped
|
||||
*/
|
||||
private get metadata (): MetadataEnum {
|
||||
return this.get('metadata') as MetadataEnum;
|
||||
private get metadata (): MetadataAll {
|
||||
return this.get('metadata') as MetadataAll;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,7 +36,7 @@ export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry
|
||||
* unique types.
|
||||
*/
|
||||
export function toLatest<Modules extends Codec> (registry: Registry, version: number, rpcData: string): void {
|
||||
it(`converts v${version} to v8`, (): void => {
|
||||
it(`converts v${version} to latest`, (): void => {
|
||||
const metadata = new Metadata(registry, rpcData)[`asV${version}` as keyof Metadata];
|
||||
const metadataLatest = new Metadata(registry, rpcData).asLatest;
|
||||
|
||||
@@ -60,7 +60,7 @@ export function defaultValues (registry: Registry, rpcData: string): void {
|
||||
.forEach((mod): void => {
|
||||
mod.storage.unwrap().items.forEach(({ fallback, name, type }): void => {
|
||||
const inner = unwrapStorageType(type);
|
||||
const location = `${mod.name}.${name}: type ${inner}`;
|
||||
const location = `${mod.name}.${name}: ${inner}`;
|
||||
|
||||
it(`creates default types for ${location}`, (): void => {
|
||||
expect(
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright 2017-2019 @polkadot/metadata authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
|
||||
import substrateJson from './static-substrate.json';
|
||||
import substrateData from './static';
|
||||
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
|
||||
|
||||
describe('MetadataV10 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestSubstrate(registry, 10, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 10, substrateData);
|
||||
|
||||
defaultValues(registry, substrateData);
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,15 @@
|
||||
// Copyright 2017-2019 @polkadot/metadata authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { MetadataV8, MetadataV9 } from '@polkadot/types/interfaces/metadata';
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
/**
|
||||
* Convert from MetadataV8 to MetadataV9
|
||||
*/
|
||||
export default function toV9 (registry: Registry, { modules }: MetadataV8): MetadataV9 {
|
||||
return createType(registry, 'MetadataV9', { modules });
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Copyright 2017-2019 @polkadot/metadata authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
|
||||
import substrateJson from './static-substrate.json';
|
||||
import substrateData from './static';
|
||||
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
|
||||
|
||||
describe('MetadataV9 (substrate)', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
decodeLatestSubstrate(registry, 9, substrateData, substrateJson);
|
||||
|
||||
toLatest(registry, 9, substrateData);
|
||||
|
||||
defaultValues(registry, substrateData);
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,52 @@
|
||||
// Copyright 2017-2019 @polkadot/metadata authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { MetadataV9, MetadataV10, ModuleMetadataV9, ModuleMetadataV10, StorageEntryTypeV9 } from '@polkadot/types/interfaces/metadata';
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
// migrate a storage entry type - only map types are different (with a kind enum)
|
||||
// all return the actual value for the enum, followed by the numeric index
|
||||
function createStorageType (registry: Registry, entryType: StorageEntryTypeV9): [any, number] {
|
||||
if (entryType.isPlain) {
|
||||
return [entryType.asPlain, 0];
|
||||
} else if (entryType.isDoubleMap) {
|
||||
return [entryType.asDoubleMap, 2];
|
||||
}
|
||||
|
||||
const map = entryType.asMap;
|
||||
|
||||
// map needs a migration, removing linked and adding an explicit kind
|
||||
return [{
|
||||
...map,
|
||||
kind: createType(registry, 'MapKindV10', null, map.linked.isTrue ? 1 : 0)
|
||||
}, 1];
|
||||
}
|
||||
|
||||
function convertModule (registry: Registry, mod: ModuleMetadataV9): ModuleMetadataV10 {
|
||||
const storage = mod.storage.unwrapOr(null);
|
||||
|
||||
return createType(registry, 'ModuleMetadataV10', {
|
||||
...mod,
|
||||
storage: storage
|
||||
? {
|
||||
...storage,
|
||||
items: storage.items.map((item): any => ({
|
||||
...item,
|
||||
type: createType(registry, 'StorageEntryTypeV10', ...createStorageType(registry, item.type))
|
||||
}))
|
||||
}
|
||||
: null
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from MetadataV9 to MetadataV10
|
||||
*/
|
||||
export default function toV10 (registry: Registry, { modules }: MetadataV9): MetadataV10 {
|
||||
return createType(registry, 'MetadataV10', {
|
||||
modules: modules.map((mod): ModuleMetadataV10 => convertModule(registry, mod))
|
||||
});
|
||||
}
|
||||
@@ -145,15 +145,15 @@ function formattingTests (version: string, decorated: Metadata, encodedValues: [
|
||||
});
|
||||
|
||||
it('handles fallbacks for linked heads (new metadata only)', (done): void => {
|
||||
const headKey = decorated.query.staking.validators && decorated.query.staking.validators.headKey;
|
||||
const iterKey = decorated.query.staking.validators && decorated.query.staking.validators.iterKey;
|
||||
|
||||
// skip for old
|
||||
if (!headKey) {
|
||||
if (!iterKey) {
|
||||
return done();
|
||||
}
|
||||
|
||||
api.state
|
||||
.subscribeStorage([headKey])
|
||||
.subscribeStorage([iterKey])
|
||||
.subscribe((value: Codec[]): void => {
|
||||
expect(value).toHaveLength(1);
|
||||
// console.error('head fallback', value);
|
||||
@@ -163,10 +163,10 @@ function formattingTests (version: string, decorated: Metadata, encodedValues: [
|
||||
});
|
||||
|
||||
it('handles fallbacks for linked maps (new metadata only)', (done): void => {
|
||||
const headKey = decorated.query.staking.validators && decorated.query.staking.validators.headKey;
|
||||
const iterKey = decorated.query.staking.validators && decorated.query.staking.validators.iterKey;
|
||||
|
||||
// skip for old
|
||||
if (!headKey) {
|
||||
if (!iterKey) {
|
||||
return done();
|
||||
}
|
||||
|
||||
|
||||
@@ -65,9 +65,6 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
|
||||
[TypeDefInfo.Compact]: (registry: Registry, value: TypeDef): Constructor => Compact.with(getSubType(value)),
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
[TypeDefInfo.DoubleMap]: (registry: Registry, value: TypeDef): Constructor => getTypeClass(registry, getSubDef(value)),
|
||||
|
||||
[TypeDefInfo.Enum]: (registry: Registry, value: TypeDef): Constructor => Enum.with(getTypeClassMap(value)),
|
||||
|
||||
[TypeDefInfo.Linkage]: (registry: Registry, value: TypeDef): Constructor => Linkage.withKey(getSubType(value)),
|
||||
|
||||
@@ -97,10 +97,10 @@ describe('getTypeDef', (): void => {
|
||||
|
||||
it('returns a type structure', (): void => {
|
||||
expect(
|
||||
getTypeDef('(u32, Compact<u32>, Vec<u64>, Option<u128>, DoubleMap<u128>, (Text,Vec<(Bool,u128)>))')
|
||||
getTypeDef('(u32, Compact<u32>, Vec<u64>, Option<u128>, (Text,Vec<(Bool,u128)>))')
|
||||
).toEqual({
|
||||
info: TypeDefInfo.Tuple,
|
||||
type: '(u32,Compact<u32>,Vec<u64>,Option<u128>,DoubleMap<u128>,(Text,Vec<(Bool,u128)>))',
|
||||
type: '(u32,Compact<u32>,Vec<u64>,Option<u128>,(Text,Vec<(Bool,u128)>))',
|
||||
sub: [
|
||||
{
|
||||
info: TypeDefInfo.Plain,
|
||||
@@ -130,14 +130,6 @@ describe('getTypeDef', (): void => {
|
||||
type: 'u128'
|
||||
}
|
||||
},
|
||||
{
|
||||
info: TypeDefInfo.DoubleMap,
|
||||
type: 'DoubleMap<u128>',
|
||||
sub: {
|
||||
info: TypeDefInfo.Plain,
|
||||
type: 'u128'
|
||||
}
|
||||
},
|
||||
{
|
||||
info: TypeDefInfo.Tuple,
|
||||
type: '(Text,Vec<(Bool,u128)>)',
|
||||
|
||||
@@ -109,7 +109,6 @@ const nestedExtraction: [string, string, TypeDefInfo, (value: TypeDef, type: str
|
||||
|
||||
const wrappedExtraction: [string, string, TypeDefInfo][] = [
|
||||
['Compact<', '>', TypeDefInfo.Compact],
|
||||
['DoubleMap<', '>', TypeDefInfo.DoubleMap],
|
||||
['Linkage<', '>', TypeDefInfo.Linkage],
|
||||
['Option<', '>', TypeDefInfo.Option],
|
||||
['Vec<', '>', TypeDefInfo.Vec]
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
type Mapper = (value: string) => string;
|
||||
|
||||
const ALLOWED_BOXES = ['BTreeMap', 'Compact', 'DoubleMap', 'Linkage', 'Result', 'Option', 'Vec'];
|
||||
const ALLOWED_BOXES = ['BTreeMap', 'Compact', 'Linkage', 'Result', 'Option', 'Vec'];
|
||||
|
||||
const mappings: Mapper[] = [
|
||||
// alias <T::InherentOfflineReport as InherentOfflineReport>::Inherent -> InherentOfflineReport
|
||||
|
||||
@@ -14,7 +14,6 @@ export type FromReg<T extends Codec, K extends string> = K extends InterfaceType
|
||||
export enum TypeDefInfo {
|
||||
BTreeMap,
|
||||
Compact,
|
||||
DoubleMap,
|
||||
Enum,
|
||||
Linkage,
|
||||
Option,
|
||||
|
||||
@@ -109,7 +109,6 @@ function encodeVecFixed (typeDef: Pick<TypeDef, any>): string {
|
||||
const encoders: Record<TypeDefInfo, (typeDef: TypeDef) => string> = {
|
||||
[TypeDefInfo.BTreeMap]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'BTreeMap'),
|
||||
[TypeDefInfo.Compact]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'Compact'),
|
||||
[TypeDefInfo.DoubleMap]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'DoubleMap'),
|
||||
[TypeDefInfo.Enum]: (typeDef: TypeDef): string => encodeEnum(typeDef),
|
||||
[TypeDefInfo.Linkage]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'Linkage'),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
||||
@@ -27,7 +27,7 @@ import { DispatchResult, DispatchResultOf } from '@polkadot/types/interfaces/uti
|
||||
import { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations';
|
||||
import { EthereumAddress } from '@polkadot/types/interfaces/claims';
|
||||
import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
|
||||
import { CallMetadataV0, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, ErrorMetadataV8, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, MapTypeV0, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MetadataLatest, MetadataV0, MetadataV1, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, ModuleConstantMetadataLatest, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryModifierLatest, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryTypeLatest, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageMetadataV0, StorageMetadataV7, StorageMetadataV8 } from '@polkadot/types/interfaces/metadata';
|
||||
import { CallMetadataV0, DoubleMapTypeV10, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, DoubleMapTypeV9, ErrorMetadataV10, ErrorMetadataV8, ErrorMetadataV9, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV10, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, EventMetadataV9, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV10, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV10, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, FunctionMetadataV9, MapKindV10, MapTypeV0, MapTypeV10, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MapTypeV9, MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV10, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV10, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, ModuleMetadataV9, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV10, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, PlainTypeV9, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageEntryTypeV9, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageMetadataV0, StorageMetadataV10, StorageMetadataV7, StorageMetadataV8, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
|
||||
import { ApiId, BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
|
||||
|
||||
export interface InterfaceRegistry {
|
||||
@@ -1129,6 +1129,93 @@ export interface InterfaceRegistry {
|
||||
StorageMetadataV8: StorageMetadataV8;
|
||||
'Option<StorageMetadataV8>': Option<StorageMetadataV8>;
|
||||
'Vec<StorageMetadataV8>': Vec<StorageMetadataV8>;
|
||||
DoubleMapTypeV9: DoubleMapTypeV9;
|
||||
'Option<DoubleMapTypeV9>': Option<DoubleMapTypeV9>;
|
||||
'Vec<DoubleMapTypeV9>': Vec<DoubleMapTypeV9>;
|
||||
ErrorMetadataV9: ErrorMetadataV9;
|
||||
'Option<ErrorMetadataV9>': Option<ErrorMetadataV9>;
|
||||
'Vec<ErrorMetadataV9>': Vec<ErrorMetadataV9>;
|
||||
EventMetadataV9: EventMetadataV9;
|
||||
'Option<EventMetadataV9>': Option<EventMetadataV9>;
|
||||
'Vec<EventMetadataV9>': Vec<EventMetadataV9>;
|
||||
FunctionArgumentMetadataV9: FunctionArgumentMetadataV9;
|
||||
'Option<FunctionArgumentMetadataV9>': Option<FunctionArgumentMetadataV9>;
|
||||
'Vec<FunctionArgumentMetadataV9>': Vec<FunctionArgumentMetadataV9>;
|
||||
FunctionMetadataV9: FunctionMetadataV9;
|
||||
'Option<FunctionMetadataV9>': Option<FunctionMetadataV9>;
|
||||
'Vec<FunctionMetadataV9>': Vec<FunctionMetadataV9>;
|
||||
MapTypeV9: MapTypeV9;
|
||||
'Option<MapTypeV9>': Option<MapTypeV9>;
|
||||
'Vec<MapTypeV9>': Vec<MapTypeV9>;
|
||||
MetadataV9: MetadataV9;
|
||||
'Option<MetadataV9>': Option<MetadataV9>;
|
||||
'Vec<MetadataV9>': Vec<MetadataV9>;
|
||||
ModuleConstantMetadataV9: ModuleConstantMetadataV9;
|
||||
'Option<ModuleConstantMetadataV9>': Option<ModuleConstantMetadataV9>;
|
||||
'Vec<ModuleConstantMetadataV9>': Vec<ModuleConstantMetadataV9>;
|
||||
ModuleMetadataV9: ModuleMetadataV9;
|
||||
'Option<ModuleMetadataV9>': Option<ModuleMetadataV9>;
|
||||
'Vec<ModuleMetadataV9>': Vec<ModuleMetadataV9>;
|
||||
PlainTypeV9: PlainTypeV9;
|
||||
'Option<PlainTypeV9>': Option<PlainTypeV9>;
|
||||
'Vec<PlainTypeV9>': Vec<PlainTypeV9>;
|
||||
StorageEntryModifierV9: StorageEntryModifierV9;
|
||||
'Option<StorageEntryModifierV9>': Option<StorageEntryModifierV9>;
|
||||
'Vec<StorageEntryModifierV9>': Vec<StorageEntryModifierV9>;
|
||||
StorageEntryMetadataV9: StorageEntryMetadataV9;
|
||||
'Option<StorageEntryMetadataV9>': Option<StorageEntryMetadataV9>;
|
||||
'Vec<StorageEntryMetadataV9>': Vec<StorageEntryMetadataV9>;
|
||||
StorageEntryTypeV9: StorageEntryTypeV9;
|
||||
'Option<StorageEntryTypeV9>': Option<StorageEntryTypeV9>;
|
||||
'Vec<StorageEntryTypeV9>': Vec<StorageEntryTypeV9>;
|
||||
StorageMetadataV9: StorageMetadataV9;
|
||||
'Option<StorageMetadataV9>': Option<StorageMetadataV9>;
|
||||
'Vec<StorageMetadataV9>': Vec<StorageMetadataV9>;
|
||||
DoubleMapTypeV10: DoubleMapTypeV10;
|
||||
'Option<DoubleMapTypeV10>': Option<DoubleMapTypeV10>;
|
||||
'Vec<DoubleMapTypeV10>': Vec<DoubleMapTypeV10>;
|
||||
ErrorMetadataV10: ErrorMetadataV10;
|
||||
'Option<ErrorMetadataV10>': Option<ErrorMetadataV10>;
|
||||
'Vec<ErrorMetadataV10>': Vec<ErrorMetadataV10>;
|
||||
EventMetadataV10: EventMetadataV10;
|
||||
'Option<EventMetadataV10>': Option<EventMetadataV10>;
|
||||
'Vec<EventMetadataV10>': Vec<EventMetadataV10>;
|
||||
FunctionArgumentMetadataV10: FunctionArgumentMetadataV10;
|
||||
'Option<FunctionArgumentMetadataV10>': Option<FunctionArgumentMetadataV10>;
|
||||
'Vec<FunctionArgumentMetadataV10>': Vec<FunctionArgumentMetadataV10>;
|
||||
FunctionMetadataV10: FunctionMetadataV10;
|
||||
'Option<FunctionMetadataV10>': Option<FunctionMetadataV10>;
|
||||
'Vec<FunctionMetadataV10>': Vec<FunctionMetadataV10>;
|
||||
MapKindV10: MapKindV10;
|
||||
'Option<MapKindV10>': Option<MapKindV10>;
|
||||
'Vec<MapKindV10>': Vec<MapKindV10>;
|
||||
MapTypeV10: MapTypeV10;
|
||||
'Option<MapTypeV10>': Option<MapTypeV10>;
|
||||
'Vec<MapTypeV10>': Vec<MapTypeV10>;
|
||||
MetadataV10: MetadataV10;
|
||||
'Option<MetadataV10>': Option<MetadataV10>;
|
||||
'Vec<MetadataV10>': Vec<MetadataV10>;
|
||||
ModuleConstantMetadataV10: ModuleConstantMetadataV10;
|
||||
'Option<ModuleConstantMetadataV10>': Option<ModuleConstantMetadataV10>;
|
||||
'Vec<ModuleConstantMetadataV10>': Vec<ModuleConstantMetadataV10>;
|
||||
ModuleMetadataV10: ModuleMetadataV10;
|
||||
'Option<ModuleMetadataV10>': Option<ModuleMetadataV10>;
|
||||
'Vec<ModuleMetadataV10>': Vec<ModuleMetadataV10>;
|
||||
PlainTypeV10: PlainTypeV10;
|
||||
'Option<PlainTypeV10>': Option<PlainTypeV10>;
|
||||
'Vec<PlainTypeV10>': Vec<PlainTypeV10>;
|
||||
StorageEntryModifierV10: StorageEntryModifierV10;
|
||||
'Option<StorageEntryModifierV10>': Option<StorageEntryModifierV10>;
|
||||
'Vec<StorageEntryModifierV10>': Vec<StorageEntryModifierV10>;
|
||||
StorageEntryMetadataV10: StorageEntryMetadataV10;
|
||||
'Option<StorageEntryMetadataV10>': Option<StorageEntryMetadataV10>;
|
||||
'Vec<StorageEntryMetadataV10>': Vec<StorageEntryMetadataV10>;
|
||||
StorageEntryTypeV10: StorageEntryTypeV10;
|
||||
'Option<StorageEntryTypeV10>': Option<StorageEntryTypeV10>;
|
||||
'Vec<StorageEntryTypeV10>': Vec<StorageEntryTypeV10>;
|
||||
StorageMetadataV10: StorageMetadataV10;
|
||||
'Option<StorageMetadataV10>': Option<StorageMetadataV10>;
|
||||
'Vec<StorageMetadataV10>': Vec<StorageMetadataV10>;
|
||||
EventMetadataLatest: EventMetadataLatest;
|
||||
'Option<EventMetadataLatest>': Option<EventMetadataLatest>;
|
||||
'Vec<EventMetadataLatest>': Vec<EventMetadataLatest>;
|
||||
@@ -1159,6 +1246,9 @@ export interface InterfaceRegistry {
|
||||
StorageEntryTypeLatest: StorageEntryTypeLatest;
|
||||
'Option<StorageEntryTypeLatest>': Option<StorageEntryTypeLatest>;
|
||||
'Vec<StorageEntryTypeLatest>': Vec<StorageEntryTypeLatest>;
|
||||
MetadataAll: MetadataAll;
|
||||
'Option<MetadataAll>': Option<MetadataAll>;
|
||||
'Vec<MetadataAll>': Vec<MetadataAll>;
|
||||
ApiId: ApiId;
|
||||
'Option<ApiId>': Option<ApiId>;
|
||||
'Vec<ApiId>': Vec<ApiId>;
|
||||
|
||||
@@ -339,16 +339,97 @@ export default {
|
||||
StorageEntryTypeV8: 'StorageEntryTypeV7',
|
||||
StorageMetadataV8: 'StorageMetadataV7',
|
||||
|
||||
// v9
|
||||
DoubleMapTypeV9: 'DoubleMapTypeV8',
|
||||
ErrorMetadataV9: 'ErrorMetadataV8',
|
||||
EventMetadataV9: 'EventMetadataV8',
|
||||
FunctionArgumentMetadataV9: 'FunctionArgumentMetadataV8',
|
||||
FunctionMetadataV9: 'FunctionMetadataV8',
|
||||
MapTypeV9: 'MapTypeV8',
|
||||
MetadataV9: 'MetadataV8',
|
||||
ModuleConstantMetadataV9: 'ModuleConstantMetadataV8',
|
||||
ModuleMetadataV9: 'ModuleMetadataV8',
|
||||
PlainTypeV9: 'Type',
|
||||
StorageEntryModifierV9: 'StorageEntryModifierV8',
|
||||
StorageEntryMetadataV9: 'StorageEntryMetadataV8',
|
||||
StorageEntryTypeV9: 'StorageEntryTypeV8',
|
||||
StorageMetadataV9: 'StorageMetadataV8',
|
||||
|
||||
// v10
|
||||
DoubleMapTypeV10: 'DoubleMapTypeV9',
|
||||
ErrorMetadataV10: 'ErrorMetadataV9',
|
||||
EventMetadataV10: 'EventMetadataV9',
|
||||
FunctionArgumentMetadataV10: 'FunctionArgumentMetadataV9',
|
||||
FunctionMetadataV10: 'FunctionMetadataV9',
|
||||
MapKindV10: {
|
||||
_enum: ['Map', 'LinkedMap', 'PrefixedMap']
|
||||
},
|
||||
MapTypeV10: {
|
||||
hasher: 'StorageHasher',
|
||||
key: 'Type',
|
||||
value: 'Type',
|
||||
kind: 'MapKindV10'
|
||||
},
|
||||
MetadataV10: {
|
||||
modules: 'Vec<ModuleMetadataV10>'
|
||||
},
|
||||
ModuleConstantMetadataV10: 'ModuleConstantMetadataV9',
|
||||
ModuleMetadataV10: {
|
||||
name: 'Text',
|
||||
storage: 'Option<StorageMetadataV10>',
|
||||
calls: 'Option<Vec<FunctionMetadataV10>>',
|
||||
events: 'Option<Vec<EventMetadataV10>>',
|
||||
constants: 'Vec<ModuleConstantMetadataV10>',
|
||||
errors: 'Vec<ErrorMetadataV10>'
|
||||
},
|
||||
PlainTypeV10: 'Type',
|
||||
StorageEntryModifierV10: 'StorageEntryModifierV9',
|
||||
StorageEntryMetadataV10: {
|
||||
name: 'Text',
|
||||
modifier: 'StorageEntryModifierV10',
|
||||
type: 'StorageEntryTypeV10',
|
||||
fallback: 'Bytes',
|
||||
documentation: 'Vec<Text>'
|
||||
},
|
||||
StorageEntryTypeV10: {
|
||||
_enum: {
|
||||
Plain: 'PlainTypeV10',
|
||||
Map: 'MapTypeV10',
|
||||
DoubleMap: 'DoubleMapTypeV10'
|
||||
}
|
||||
},
|
||||
StorageMetadataV10: {
|
||||
prefix: 'Text',
|
||||
items: 'Vec<StorageEntryMetadataV10>'
|
||||
},
|
||||
|
||||
// This always maps to the latest
|
||||
EventMetadataLatest: 'EventMetadataV8',
|
||||
FunctionArgumentMetadataLatest: 'FunctionArgumentMetadataV8',
|
||||
FunctionMetadataLatest: 'FunctionMetadataV8',
|
||||
MetadataLatest: 'MetadataV8',
|
||||
ModuleConstantMetadataLatest: 'ModuleConstantMetadataV8',
|
||||
ModuleMetadataLatest: 'ModuleMetadataV8',
|
||||
PlainTypeLatest: 'PlainTypeV8',
|
||||
StorageEntryMetadataLatest: 'StorageEntryMetadataV8',
|
||||
StorageEntryModifierLatest: 'StorageEntryModifierV8',
|
||||
StorageEntryTypeLatest: 'StorageEntryTypeV8'
|
||||
EventMetadataLatest: 'EventMetadataV10',
|
||||
FunctionArgumentMetadataLatest: 'FunctionArgumentMetadataV10',
|
||||
FunctionMetadataLatest: 'FunctionMetadataV10',
|
||||
MetadataLatest: 'MetadataV10',
|
||||
ModuleConstantMetadataLatest: 'ModuleConstantMetadataV10',
|
||||
ModuleMetadataLatest: 'ModuleMetadataV10',
|
||||
PlainTypeLatest: 'PlainTypeV10',
|
||||
StorageEntryMetadataLatest: 'StorageEntryMetadataV10',
|
||||
StorageEntryModifierLatest: 'StorageEntryModifierV10',
|
||||
StorageEntryTypeLatest: 'StorageEntryTypeV10',
|
||||
|
||||
// the enum containing all the mappings
|
||||
MetadataAll: {
|
||||
_enum: {
|
||||
V0: 'MetadataV0',
|
||||
V1: 'MetadataV1',
|
||||
V2: 'MetadataV2',
|
||||
V3: 'MetadataV3',
|
||||
V4: 'MetadataV4',
|
||||
V5: 'MetadataV5',
|
||||
V6: 'MetadataV6',
|
||||
V7: 'MetadataV7',
|
||||
V8: 'MetadataV8',
|
||||
V9: 'MetadataV9',
|
||||
V10: 'MetadataV10'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,6 +13,9 @@ export interface CallMetadataV0 extends Struct {
|
||||
readonly functions: Vec<FunctionMetadataV0>;
|
||||
}
|
||||
|
||||
/** DoubleMapTypeV9 */
|
||||
export interface DoubleMapTypeV10 extends DoubleMapTypeV9 {}
|
||||
|
||||
/** Struct */
|
||||
export interface DoubleMapTypeV3 extends Struct {
|
||||
/** Type */
|
||||
@@ -62,6 +65,12 @@ export interface DoubleMapTypeV7 extends DoubleMapTypeV6 {}
|
||||
/** DoubleMapTypeV7 */
|
||||
export interface DoubleMapTypeV8 extends DoubleMapTypeV7 {}
|
||||
|
||||
/** DoubleMapTypeV8 */
|
||||
export interface DoubleMapTypeV9 extends DoubleMapTypeV8 {}
|
||||
|
||||
/** ErrorMetadataV9 */
|
||||
export interface ErrorMetadataV10 extends ErrorMetadataV9 {}
|
||||
|
||||
/** Struct */
|
||||
export interface ErrorMetadataV8 extends Struct {
|
||||
/** Text */
|
||||
@@ -70,8 +79,11 @@ export interface ErrorMetadataV8 extends Struct {
|
||||
readonly documentation: Vec<Text>;
|
||||
}
|
||||
|
||||
/** EventMetadataV8 */
|
||||
export interface EventMetadataLatest extends EventMetadataV8 {}
|
||||
/** ErrorMetadataV8 */
|
||||
export interface ErrorMetadataV9 extends ErrorMetadataV8 {}
|
||||
|
||||
/** EventMetadataV10 */
|
||||
export interface EventMetadataLatest extends EventMetadataV10 {}
|
||||
|
||||
/** Struct */
|
||||
export interface EventMetadataV0 extends Struct {
|
||||
@@ -86,6 +98,9 @@ export interface EventMetadataV0 extends Struct {
|
||||
/** EventMetadataV0 */
|
||||
export interface EventMetadataV1 extends EventMetadataV0 {}
|
||||
|
||||
/** EventMetadataV9 */
|
||||
export interface EventMetadataV10 extends EventMetadataV9 {}
|
||||
|
||||
/** EventMetadataV1 */
|
||||
export interface EventMetadataV2 extends EventMetadataV1 {}
|
||||
|
||||
@@ -107,8 +122,11 @@ export interface EventMetadataV7 extends EventMetadataV6 {}
|
||||
/** EventMetadataV7 */
|
||||
export interface EventMetadataV8 extends EventMetadataV7 {}
|
||||
|
||||
/** FunctionArgumentMetadataV8 */
|
||||
export interface FunctionArgumentMetadataLatest extends FunctionArgumentMetadataV8 {}
|
||||
/** EventMetadataV8 */
|
||||
export interface EventMetadataV9 extends EventMetadataV8 {}
|
||||
|
||||
/** FunctionArgumentMetadataV10 */
|
||||
export interface FunctionArgumentMetadataLatest extends FunctionArgumentMetadataV10 {}
|
||||
|
||||
/** Struct */
|
||||
export interface FunctionArgumentMetadataV0 extends Struct {
|
||||
@@ -121,6 +139,9 @@ export interface FunctionArgumentMetadataV0 extends Struct {
|
||||
/** FunctionArgumentMetadataV0 */
|
||||
export interface FunctionArgumentMetadataV1 extends FunctionArgumentMetadataV0 {}
|
||||
|
||||
/** FunctionArgumentMetadataV9 */
|
||||
export interface FunctionArgumentMetadataV10 extends FunctionArgumentMetadataV9 {}
|
||||
|
||||
/** FunctionArgumentMetadataV1 */
|
||||
export interface FunctionArgumentMetadataV2 extends FunctionArgumentMetadataV1 {}
|
||||
|
||||
@@ -142,8 +163,11 @@ export interface FunctionArgumentMetadataV7 extends FunctionArgumentMetadataV6 {
|
||||
/** FunctionArgumentMetadataV7 */
|
||||
export interface FunctionArgumentMetadataV8 extends FunctionArgumentMetadataV7 {}
|
||||
|
||||
/** FunctionMetadataV8 */
|
||||
export interface FunctionMetadataLatest extends FunctionMetadataV8 {}
|
||||
/** FunctionArgumentMetadataV8 */
|
||||
export interface FunctionArgumentMetadataV9 extends FunctionArgumentMetadataV8 {}
|
||||
|
||||
/** FunctionMetadataV10 */
|
||||
export interface FunctionMetadataLatest extends FunctionMetadataV10 {}
|
||||
|
||||
/** Struct */
|
||||
export interface FunctionMetadataV0 extends Struct {
|
||||
@@ -167,6 +191,9 @@ export interface FunctionMetadataV1 extends Struct {
|
||||
readonly documentation: Vec<Text>;
|
||||
}
|
||||
|
||||
/** FunctionMetadataV9 */
|
||||
export interface FunctionMetadataV10 extends FunctionMetadataV9 {}
|
||||
|
||||
/** FunctionMetadataV1 */
|
||||
export interface FunctionMetadataV2 extends FunctionMetadataV1 {}
|
||||
|
||||
@@ -188,6 +215,19 @@ export interface FunctionMetadataV7 extends FunctionMetadataV6 {}
|
||||
/** FunctionMetadataV7 */
|
||||
export interface FunctionMetadataV8 extends FunctionMetadataV7 {}
|
||||
|
||||
/** FunctionMetadataV8 */
|
||||
export interface FunctionMetadataV9 extends FunctionMetadataV8 {}
|
||||
|
||||
/** Enum */
|
||||
export interface MapKindV10 extends Enum {
|
||||
/** 0:: Map */
|
||||
readonly isMap: boolean;
|
||||
/** 1:: LinkedMap */
|
||||
readonly isLinkedMap: boolean;
|
||||
/** 2:: PrefixedMap */
|
||||
readonly isPrefixedMap: boolean;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface MapTypeV0 extends Struct {
|
||||
/** Type */
|
||||
@@ -196,6 +236,18 @@ export interface MapTypeV0 extends Struct {
|
||||
readonly value: Type;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface MapTypeV10 extends Struct {
|
||||
/** StorageHasher */
|
||||
readonly hasher: StorageHasher;
|
||||
/** Type */
|
||||
readonly key: Type;
|
||||
/** Type */
|
||||
readonly value: Type;
|
||||
/** MapKindV10 */
|
||||
readonly kind: MapKindV10;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface MapTypeV2 extends Struct {
|
||||
/** Type */
|
||||
@@ -233,8 +285,59 @@ export interface MapTypeV7 extends MapTypeV6 {}
|
||||
/** MapTypeV7 */
|
||||
export interface MapTypeV8 extends MapTypeV7 {}
|
||||
|
||||
/** MetadataV8 */
|
||||
export interface MetadataLatest extends MetadataV8 {}
|
||||
/** MapTypeV8 */
|
||||
export interface MapTypeV9 extends MapTypeV8 {}
|
||||
|
||||
/** Enum */
|
||||
export interface MetadataAll extends Enum {
|
||||
/** 0:: V0(MetadataV0) */
|
||||
readonly isV0: boolean;
|
||||
/** MetadataV0 */
|
||||
readonly asV0: MetadataV0;
|
||||
/** 1:: V1(MetadataV1) */
|
||||
readonly isV1: boolean;
|
||||
/** MetadataV1 */
|
||||
readonly asV1: MetadataV1;
|
||||
/** 2:: V2(MetadataV2) */
|
||||
readonly isV2: boolean;
|
||||
/** MetadataV2 */
|
||||
readonly asV2: MetadataV2;
|
||||
/** 3:: V3(MetadataV3) */
|
||||
readonly isV3: boolean;
|
||||
/** MetadataV3 */
|
||||
readonly asV3: MetadataV3;
|
||||
/** 4:: V4(MetadataV4) */
|
||||
readonly isV4: boolean;
|
||||
/** MetadataV4 */
|
||||
readonly asV4: MetadataV4;
|
||||
/** 5:: V5(MetadataV5) */
|
||||
readonly isV5: boolean;
|
||||
/** MetadataV5 */
|
||||
readonly asV5: MetadataV5;
|
||||
/** 6:: V6(MetadataV6) */
|
||||
readonly isV6: boolean;
|
||||
/** MetadataV6 */
|
||||
readonly asV6: MetadataV6;
|
||||
/** 7:: V7(MetadataV7) */
|
||||
readonly isV7: boolean;
|
||||
/** MetadataV7 */
|
||||
readonly asV7: MetadataV7;
|
||||
/** 8:: V8(MetadataV8) */
|
||||
readonly isV8: boolean;
|
||||
/** MetadataV8 */
|
||||
readonly asV8: MetadataV8;
|
||||
/** 9:: V9(MetadataV9) */
|
||||
readonly isV9: boolean;
|
||||
/** MetadataV9 */
|
||||
readonly asV9: MetadataV9;
|
||||
/** 10:: V10(MetadataV10) */
|
||||
readonly isV10: boolean;
|
||||
/** MetadataV10 */
|
||||
readonly asV10: MetadataV10;
|
||||
}
|
||||
|
||||
/** MetadataV10 */
|
||||
export interface MetadataLatest extends MetadataV10 {}
|
||||
|
||||
/** Struct */
|
||||
export interface MetadataV0 extends Struct {
|
||||
@@ -252,6 +355,12 @@ export interface MetadataV1 extends Struct {
|
||||
readonly modules: Vec<ModuleMetadataV1>;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface MetadataV10 extends Struct {
|
||||
/** Vec<ModuleMetadataV10> */
|
||||
readonly modules: Vec<ModuleMetadataV10>;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface MetadataV2 extends Struct {
|
||||
/** Vec<ModuleMetadataV2> */
|
||||
@@ -294,8 +403,14 @@ export interface MetadataV8 extends Struct {
|
||||
readonly modules: Vec<ModuleMetadataV8>;
|
||||
}
|
||||
|
||||
/** ModuleConstantMetadataV8 */
|
||||
export interface ModuleConstantMetadataLatest extends ModuleConstantMetadataV8 {}
|
||||
/** MetadataV8 */
|
||||
export interface MetadataV9 extends MetadataV8 {}
|
||||
|
||||
/** ModuleConstantMetadataV10 */
|
||||
export interface ModuleConstantMetadataLatest extends ModuleConstantMetadataV10 {}
|
||||
|
||||
/** ModuleConstantMetadataV9 */
|
||||
export interface ModuleConstantMetadataV10 extends ModuleConstantMetadataV9 {}
|
||||
|
||||
/** Struct */
|
||||
export interface ModuleConstantMetadataV6 extends Struct {
|
||||
@@ -315,8 +430,11 @@ export interface ModuleConstantMetadataV7 extends ModuleConstantMetadataV6 {}
|
||||
/** ModuleConstantMetadataV7 */
|
||||
export interface ModuleConstantMetadataV8 extends ModuleConstantMetadataV7 {}
|
||||
|
||||
/** ModuleMetadataV8 */
|
||||
export interface ModuleMetadataLatest extends ModuleMetadataV8 {}
|
||||
/** ModuleConstantMetadataV8 */
|
||||
export interface ModuleConstantMetadataV9 extends ModuleConstantMetadataV8 {}
|
||||
|
||||
/** ModuleMetadataV10 */
|
||||
export interface ModuleMetadataLatest extends ModuleMetadataV10 {}
|
||||
|
||||
/** Struct */
|
||||
export interface ModuleMetadataV0 extends Struct {
|
||||
@@ -340,6 +458,22 @@ export interface ModuleMetadataV1 extends Struct {
|
||||
readonly events: Option<Vec<EventMetadataV1>>;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface ModuleMetadataV10 extends Struct {
|
||||
/** Text */
|
||||
readonly name: Text;
|
||||
/** Option<StorageMetadataV10> */
|
||||
readonly storage: Option<StorageMetadataV10>;
|
||||
/** Option<Vec<FunctionMetadataV10>> */
|
||||
readonly calls: Option<Vec<FunctionMetadataV10>>;
|
||||
/** Option<Vec<EventMetadataV10>> */
|
||||
readonly events: Option<Vec<EventMetadataV10>>;
|
||||
/** Vec<ModuleConstantMetadataV10> */
|
||||
readonly constants: Vec<ModuleConstantMetadataV10>;
|
||||
/** Vec<ErrorMetadataV10> */
|
||||
readonly errors: Vec<ErrorMetadataV10>;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface ModuleMetadataV2 extends Struct {
|
||||
/** Text */
|
||||
@@ -442,6 +576,9 @@ export interface ModuleMetadataV8 extends Struct {
|
||||
readonly errors: Vec<ErrorMetadataV8>;
|
||||
}
|
||||
|
||||
/** ModuleMetadataV8 */
|
||||
export interface ModuleMetadataV9 extends ModuleMetadataV8 {}
|
||||
|
||||
/** Struct */
|
||||
export interface OuterDispatchCallV0 extends Struct {
|
||||
/** Text */
|
||||
@@ -474,12 +611,15 @@ export interface OuterEventMetadataV0 extends Struct {
|
||||
readonly events: Vec<OuterEventEventMetadataV0>;
|
||||
}
|
||||
|
||||
/** PlainTypeV8 */
|
||||
export interface PlainTypeLatest extends PlainTypeV8 {}
|
||||
/** PlainTypeV10 */
|
||||
export interface PlainTypeLatest extends PlainTypeV10 {}
|
||||
|
||||
/** Type */
|
||||
export interface PlainTypeV0 extends Type {}
|
||||
|
||||
/** Type */
|
||||
export interface PlainTypeV10 extends Type {}
|
||||
|
||||
/** Type */
|
||||
export interface PlainTypeV2 extends Type {}
|
||||
|
||||
@@ -501,6 +641,9 @@ export interface PlainTypeV7 extends Type {}
|
||||
/** Type */
|
||||
export interface PlainTypeV8 extends Type {}
|
||||
|
||||
/** Type */
|
||||
export interface PlainTypeV9 extends Type {}
|
||||
|
||||
/** Struct */
|
||||
export interface RuntimeModuleMetadataV0 extends Struct {
|
||||
/** Text */
|
||||
@@ -511,8 +654,22 @@ export interface RuntimeModuleMetadataV0 extends Struct {
|
||||
readonly storage: Option<StorageMetadataV0>;
|
||||
}
|
||||
|
||||
/** StorageEntryMetadataV8 */
|
||||
export interface StorageEntryMetadataLatest extends StorageEntryMetadataV8 {}
|
||||
/** StorageEntryMetadataV10 */
|
||||
export interface StorageEntryMetadataLatest extends StorageEntryMetadataV10 {}
|
||||
|
||||
/** Struct */
|
||||
export interface StorageEntryMetadataV10 extends Struct {
|
||||
/** Text */
|
||||
readonly name: Text;
|
||||
/** StorageEntryModifierV10 */
|
||||
readonly modifier: StorageEntryModifierV10;
|
||||
/** StorageEntryTypeV10 */
|
||||
readonly type: StorageEntryTypeV10;
|
||||
/** Bytes */
|
||||
readonly fallback: Bytes;
|
||||
/** Vec<Text> */
|
||||
readonly documentation: Vec<Text>;
|
||||
}
|
||||
|
||||
/** StorageFunctionMetadataV5 */
|
||||
export interface StorageEntryMetadataV6 extends StorageFunctionMetadataV5 {}
|
||||
@@ -523,8 +680,14 @@ export interface StorageEntryMetadataV7 extends StorageEntryMetadataV6 {}
|
||||
/** StorageEntryMetadataV7 */
|
||||
export interface StorageEntryMetadataV8 extends StorageEntryMetadataV7 {}
|
||||
|
||||
/** StorageEntryModifierV8 */
|
||||
export interface StorageEntryModifierLatest extends StorageEntryModifierV8 {}
|
||||
/** StorageEntryMetadataV8 */
|
||||
export interface StorageEntryMetadataV9 extends StorageEntryMetadataV8 {}
|
||||
|
||||
/** StorageEntryModifierV10 */
|
||||
export interface StorageEntryModifierLatest extends StorageEntryModifierV10 {}
|
||||
|
||||
/** StorageEntryModifierV9 */
|
||||
export interface StorageEntryModifierV10 extends StorageEntryModifierV9 {}
|
||||
|
||||
/** StorageFunctionModifierV5 */
|
||||
export interface StorageEntryModifierV6 extends StorageFunctionModifierV5 {}
|
||||
@@ -535,8 +698,27 @@ export interface StorageEntryModifierV7 extends StorageEntryModifierV6 {}
|
||||
/** StorageEntryModifierV7 */
|
||||
export interface StorageEntryModifierV8 extends StorageEntryModifierV7 {}
|
||||
|
||||
/** StorageEntryTypeV8 */
|
||||
export interface StorageEntryTypeLatest extends StorageEntryTypeV8 {}
|
||||
/** StorageEntryModifierV8 */
|
||||
export interface StorageEntryModifierV9 extends StorageEntryModifierV8 {}
|
||||
|
||||
/** StorageEntryTypeV10 */
|
||||
export interface StorageEntryTypeLatest extends StorageEntryTypeV10 {}
|
||||
|
||||
/** Enum */
|
||||
export interface StorageEntryTypeV10 extends Enum {
|
||||
/** 0:: Plain(PlainTypeV10) */
|
||||
readonly isPlain: boolean;
|
||||
/** PlainTypeV10 */
|
||||
readonly asPlain: PlainTypeV10;
|
||||
/** 1:: Map(MapTypeV10) */
|
||||
readonly isMap: boolean;
|
||||
/** MapTypeV10 */
|
||||
readonly asMap: MapTypeV10;
|
||||
/** 2:: DoubleMap(DoubleMapTypeV10) */
|
||||
readonly isDoubleMap: boolean;
|
||||
/** DoubleMapTypeV10 */
|
||||
readonly asDoubleMap: DoubleMapTypeV10;
|
||||
}
|
||||
|
||||
/** StorageFunctionTypeV5 */
|
||||
export interface StorageEntryTypeV6 extends StorageFunctionTypeV5 {}
|
||||
@@ -547,6 +729,9 @@ export interface StorageEntryTypeV7 extends StorageEntryTypeV6 {}
|
||||
/** StorageEntryTypeV7 */
|
||||
export interface StorageEntryTypeV8 extends StorageEntryTypeV7 {}
|
||||
|
||||
/** StorageEntryTypeV8 */
|
||||
export interface StorageEntryTypeV9 extends StorageEntryTypeV8 {}
|
||||
|
||||
/** Struct */
|
||||
export interface StorageFunctionMetadataV0 extends Struct {
|
||||
/** Text */
|
||||
@@ -728,6 +913,14 @@ export interface StorageMetadataV0 extends Struct {
|
||||
readonly functions: Vec<StorageFunctionMetadataV0>;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface StorageMetadataV10 extends Struct {
|
||||
/** Text */
|
||||
readonly prefix: Text;
|
||||
/** Vec<StorageEntryMetadataV10> */
|
||||
readonly items: Vec<StorageEntryMetadataV10>;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface StorageMetadataV7 extends Struct {
|
||||
/** Text */
|
||||
@@ -738,3 +931,6 @@ export interface StorageMetadataV7 extends Struct {
|
||||
|
||||
/** StorageMetadataV7 */
|
||||
export interface StorageMetadataV8 extends StorageMetadataV7 {}
|
||||
|
||||
/** StorageMetadataV8 */
|
||||
export interface StorageMetadataV9 extends StorageMetadataV8 {}
|
||||
|
||||
@@ -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 { StorageEntryMetadataLatest } from '../interfaces/metadata';
|
||||
import { AnyU8a, Codec, Registry } from '../types';
|
||||
import { StorageEntryMetadataLatest, StorageEntryTypeLatest } from '../interfaces/metadata';
|
||||
import { AnyU8a, Registry } from '../types';
|
||||
|
||||
import { assert, isFunction, isString, isU8a } from '@polkadot/util';
|
||||
|
||||
@@ -11,7 +11,7 @@ import Bytes from './Bytes';
|
||||
|
||||
export interface StorageEntry {
|
||||
(arg?: any): Uint8Array;
|
||||
headKey?: Uint8Array;
|
||||
iterKey?: Uint8Array;
|
||||
meta: StorageEntryMetadataLatest;
|
||||
method: string;
|
||||
prefix: string;
|
||||
@@ -30,39 +30,23 @@ interface StorageKeyExtra {
|
||||
section: string;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
type Text = String & Codec;
|
||||
|
||||
interface StorageType {
|
||||
asDoubleMap: {
|
||||
value: Text;
|
||||
};
|
||||
asMap: {
|
||||
linked: { isTrue: boolean };
|
||||
key: Text;
|
||||
value: Text;
|
||||
};
|
||||
asPlain: Text;
|
||||
isDoubleMap: boolean;
|
||||
isMap: boolean;
|
||||
isPlain: boolean;
|
||||
}
|
||||
|
||||
// we unwrap the type here, turning into an output usable for createType
|
||||
export function unwrapStorageType (type: StorageType): string {
|
||||
if (type.isDoubleMap) {
|
||||
return `DoubleMap<${type.asDoubleMap.value.toString()}>`;
|
||||
export function unwrapStorageType (type: StorageEntryTypeLatest): string {
|
||||
if (type.isPlain) {
|
||||
return type.asPlain.toString();
|
||||
} else if (type.isDoubleMap) {
|
||||
return type.asDoubleMap.value.toString();
|
||||
}
|
||||
|
||||
if (type.isMap) {
|
||||
if (type.asMap.linked.isTrue) {
|
||||
return `(${type.asMap.value.toString()}, Linkage<${type.asMap.key.toString()}>)`;
|
||||
}
|
||||
const map = type.asMap;
|
||||
|
||||
return type.asMap.value.toString();
|
||||
if (map.kind.isLinkedMap) {
|
||||
return `(${map.value.toString()}, Linkage<${map.key.toString()}>)`;
|
||||
} else if (map.kind.isPrefixedMap) {
|
||||
// We are not 100% sure here yet if we are doing something specific or not
|
||||
}
|
||||
|
||||
return type.asPlain.toString();
|
||||
return map.value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,4 +161,22 @@ export default class StorageKey extends Bytes {
|
||||
public get section (): string | undefined {
|
||||
return this._section;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Sets the meta for this key
|
||||
*/
|
||||
public setMeta (meta?: StorageEntryMetadataLatest): this {
|
||||
this._meta = meta;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Sets the output type for this storage key
|
||||
*/
|
||||
public setOutputType (outputType?: string): this {
|
||||
this._outputType = outputType;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +228,6 @@ function generateInterfaces ({ types }: { types: Record<string, any> }, imports:
|
||||
const generators = {
|
||||
[TypeDefInfo.BTreeMap]: tsBTreeMap,
|
||||
[TypeDefInfo.Compact]: tsCompact,
|
||||
[TypeDefInfo.DoubleMap]: errorUnhandled,
|
||||
[TypeDefInfo.Enum]: tsEnum,
|
||||
[TypeDefInfo.Linkage]: errorUnhandled,
|
||||
[TypeDefInfo.Null]: errorUnhandled,
|
||||
|
||||
Reference in New Issue
Block a user