Pass registry to formatters (#3799)

This commit is contained in:
Jaco
2021-07-22 19:39:40 +02:00
committed by GitHub
parent 592407d691
commit 196d3c5995
17 changed files with 133 additions and 97 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Registry } from '../types/registry';
import type { TypeDef } from './types';
import { assert, isNumber, isUndefined, stringify } from '@polkadot/util';
@@ -140,7 +141,7 @@ export function encodeTypeDef (typeDef: TypeDef): string {
return encodeType(typeDef);
}
export function withTypeString (typeDef: Omit<TypeDef, 'type'>): TypeDef {
export function withTypeString (_: Registry, typeDef: Omit<TypeDef, 'type'>): TypeDef {
return {
...typeDef,
type: encodeType(typeDef as TypeDef)
+1 -1
View File
@@ -54,7 +54,7 @@ export function defaultValues (registry: Registry, rpcData: string, withThrow =
metadata.asLatest.modules.filter(({ storage }): boolean => storage.isSome).forEach((mod): void => {
mod.storage.unwrap().items.forEach(({ fallback, modifier, name, type }): void => {
const inner = unwrapStorageType(type, modifier.isOptional);
const inner = unwrapStorageType(registry, type, modifier.isOptional);
const location = `${mod.name.toString()}.${name.toString()}: ${inner}`;
it(`creates default types for ${location}`, (): void => {
+6 -6
View File
@@ -33,7 +33,7 @@ const HASHER_MAP: Record<keyof typeof AllHashers, [number, boolean]> = {
};
/** @internal */
export function unwrapStorageType (type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
export function unwrapStorageType (_: Registry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
const outputType = type.isPlain
? type.asPlain.toString()
: type.isMap
@@ -142,16 +142,16 @@ function getMeta (value: StorageKey | StorageEntry | [StorageEntry, unknown]): S
}
/** @internal */
function getType (value: StorageKey | StorageEntry | [StorageEntry, unknown]): string {
function getType (registry: Registry, value: StorageKey | StorageEntry | [StorageEntry, unknown]): string {
if (value instanceof StorageKey) {
return value.outputType;
} else if (isFunction(value)) {
return unwrapStorageType(value.meta.type);
return unwrapStorageType(registry, value.meta.type);
} else if (Array.isArray(value)) {
const [fn] = value;
if (fn.meta) {
return unwrapStorageType(fn.meta.type);
return unwrapStorageType(registry, fn.meta.type);
}
}
@@ -183,7 +183,7 @@ export class StorageKey<A extends AnyTuple = AnyTuple> extends Bytes implements
super(registry, key);
this._outputType = getType(value as StorageKey);
this._outputType = getType(registry, value as StorageKey);
// decode the args (as applicable based on the key and the hashers, after all init)
this.setMeta(getMeta(value as StorageKey), override.section || section, override.method || method);
@@ -237,7 +237,7 @@ export class StorageKey<A extends AnyTuple = AnyTuple> extends Bytes implements
this._section = section || this._section;
if (meta) {
this._outputType = unwrapStorageType(meta.type);
this._outputType = unwrapStorageType(this.registry, meta.type);
}
try {