Add type string generation to PortableRegistry (#3802)
* Add type string generation to PortableRegistry * createClass updates * Add missing field
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/api": "5.1.2-7",
|
||||
"@polkadot/types": "5.1.2-7",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util": "^7.0.3-0",
|
||||
"rxjs": "^7.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
"@polkadot/api": "5.1.2-7",
|
||||
"@polkadot/rpc-core": "5.1.2-7",
|
||||
"@polkadot/types": "5.1.2-7",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util-crypto": "^7.0.2",
|
||||
"@polkadot/util": "^7.0.3-0",
|
||||
"@polkadot/util-crypto": "^7.0.3-0",
|
||||
"rxjs": "^7.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.0.2",
|
||||
"@polkadot/keyring": "^7.0.3-0",
|
||||
"@polkadot/rpc-provider": "5.1.2-7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/api-derive": "5.1.2-7",
|
||||
"@polkadot/keyring": "^7.0.2",
|
||||
"@polkadot/keyring": "^7.0.3-0",
|
||||
"@polkadot/rpc-core": "5.1.2-7",
|
||||
"@polkadot/rpc-provider": "5.1.2-7",
|
||||
"@polkadot/types": "5.1.2-7",
|
||||
"@polkadot/types-known": "5.1.2-7",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util-crypto": "^7.0.2",
|
||||
"@polkadot/util": "^7.0.3-0",
|
||||
"@polkadot/util-crypto": "^7.0.3-0",
|
||||
"eventemitter3": "^4.0.7",
|
||||
"rxjs": "^7.2.0"
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/rpc-provider": "5.1.2-7",
|
||||
"@polkadot/types": "5.1.2-7",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util": "^7.0.3-0",
|
||||
"rxjs": "^7.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.0.2"
|
||||
"@polkadot/keyring": "^7.0.3-0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/types": "5.1.2-7",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util-crypto": "^7.0.2",
|
||||
"@polkadot/x-fetch": "^7.0.2",
|
||||
"@polkadot/x-global": "^7.0.2",
|
||||
"@polkadot/x-ws": "^7.0.2",
|
||||
"@polkadot/util": "^7.0.3-0",
|
||||
"@polkadot/util-crypto": "^7.0.3-0",
|
||||
"@polkadot/x-fetch": "^7.0.3-0",
|
||||
"@polkadot/x-global": "^7.0.3-0",
|
||||
"@polkadot/x-ws": "^7.0.3-0",
|
||||
"eventemitter3": "^4.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.0.2",
|
||||
"@polkadot/keyring": "^7.0.3-0",
|
||||
"@polkadot/types": "5.1.2-7",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^13.1.1"
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
"@polkadot/api": "5.1.2-7",
|
||||
"@polkadot/rpc-provider": "5.1.2-7",
|
||||
"@polkadot/types": "5.1.2-7",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util": "^7.0.3-0",
|
||||
"handlebars": "^4.7.7",
|
||||
"websocket": "^1.0.34",
|
||||
"yargs": "^17.0.1"
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/networks": "^7.0.2",
|
||||
"@polkadot/networks": "^7.0.3-0",
|
||||
"@polkadot/types": "5.1.2-7",
|
||||
"@polkadot/util": "^7.0.2"
|
||||
"@polkadot/util": "^7.0.3-0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util-crypto": "^7.0.2",
|
||||
"@polkadot/util": "^7.0.3-0",
|
||||
"@polkadot/util-crypto": "^7.0.3-0",
|
||||
"rxjs": "^7.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.0.2",
|
||||
"@polkadot/keyring": "^7.0.3-0",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.11.9"
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { FromReg, TypeDef } from './types';
|
||||
import { assert, isNumber, isUndefined, stringify } from '@polkadot/util';
|
||||
|
||||
import { BTreeMap, BTreeSet, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Option, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed } from '../codec';
|
||||
import { Bytes, Null } from '../primitive';
|
||||
import { getTypeDef } from './getTypeDef';
|
||||
import { TypeDefInfo } from './types';
|
||||
|
||||
@@ -36,18 +37,6 @@ export function ClassOf<K extends keyof InterfaceTypes> (registry: Registry, nam
|
||||
return ClassOfUnsafe<Codec, K>(registry, name) as any;
|
||||
}
|
||||
|
||||
function expandLookup (registry: Registry, type: string): keyof InterfaceTypes {
|
||||
if (registry.isLookupType(type)) {
|
||||
const subType = registry.lookup.getTypeDef(type).type;
|
||||
|
||||
if (subType !== type) {
|
||||
return expandLookup(registry, subType);
|
||||
}
|
||||
}
|
||||
|
||||
return type as keyof InterfaceTypes;
|
||||
}
|
||||
|
||||
function getSubDefArray (value: TypeDef): TypeDef[] {
|
||||
assert(value.sub && Array.isArray(value.sub), () => `Expected subtype as TypeDef[] in ${stringify(value)}`);
|
||||
|
||||
@@ -142,7 +131,7 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
[TypeDefInfo.Null]: (registry: Registry, _: TypeDef): Constructor =>
|
||||
createClass(registry, 'Null'),
|
||||
Null,
|
||||
|
||||
[TypeDefInfo.Option]: (registry: Registry, value: TypeDef): Constructor =>
|
||||
Option.with(getSubType(value)),
|
||||
@@ -171,7 +160,7 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
},
|
||||
|
||||
[TypeDefInfo.Si]: (registry: Registry, value: TypeDef): Constructor =>
|
||||
getTypeClass(registry, registry.lookup.getTypeDef(value.index as number)),
|
||||
getTypeClass(registry, registry.lookup.getTypeDef(value.type)),
|
||||
|
||||
[TypeDefInfo.Struct]: (registry: Registry, value: TypeDef): Constructor =>
|
||||
Struct.with(getTypeClassMap(value), value.alias),
|
||||
@@ -183,11 +172,11 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
createInt(value, UInt),
|
||||
|
||||
[TypeDefInfo.Vec]: (registry: Registry, value: TypeDef): Constructor => {
|
||||
const subType = expandLookup(registry, getSubType(value));
|
||||
const subType = getSubType(value);
|
||||
|
||||
return (
|
||||
subType === 'u8'
|
||||
? createClass(registry, 'Bytes')
|
||||
? Bytes
|
||||
: Vec.with(subType)
|
||||
);
|
||||
},
|
||||
@@ -195,7 +184,7 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
[TypeDefInfo.VecFixed]: (registry: Registry, { displayName, length, sub }: TypeDef): Constructor => {
|
||||
assert(isNumber(length) && !isUndefined(sub), 'Expected length & type information for fixed vector');
|
||||
|
||||
const subType = expandLookup(registry, (sub as TypeDef).type);
|
||||
const subType = (sub as TypeDef).type as keyof InterfaceTypes;
|
||||
|
||||
return (
|
||||
subType === 'u8'
|
||||
@@ -206,25 +195,27 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
};
|
||||
|
||||
// Returns the type Class for construction
|
||||
export function getTypeClass<T extends Codec = Codec> (registry: Registry, value: TypeDef): Constructor<T> {
|
||||
let Type = registry.get<T>(value.type);
|
||||
export function getTypeClass<T extends Codec = Codec> (registry: Registry, typeDef: TypeDef): Constructor<T> {
|
||||
let Type = registry.get<T>(typeDef.type);
|
||||
|
||||
if (Type) {
|
||||
return Type;
|
||||
}
|
||||
|
||||
const getFn = infoMapping[value.info];
|
||||
try {
|
||||
Type = infoMapping[typeDef.info](registry, typeDef) as Constructor<T>;
|
||||
|
||||
assert(getFn, () => `Unable to construct class from ${stringify(value)}`);
|
||||
assert(Type, 'No class created');
|
||||
|
||||
Type = getFn(registry, value) as Constructor<T>;
|
||||
// don't clobber any existing
|
||||
if (!Type.__fallbackType && typeDef.fallbackType) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore ...this is the only place we we actually assign this...
|
||||
Type.__fallbackType = typeDef.fallbackType;
|
||||
}
|
||||
|
||||
// don't clobber any existing
|
||||
if (!Type.__fallbackType && value.fallbackType) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore ...this is the only place we we actually assign this...
|
||||
Type.__fallbackType = value.fallbackType;
|
||||
return Type;
|
||||
} catch (error) {
|
||||
throw new Error(`Unable to construct class from ${stringify(typeDef)}: ${(error as Error).message}`);
|
||||
}
|
||||
|
||||
return Type;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ export interface TypeDef {
|
||||
displayName?: string;
|
||||
fallbackType?: string;
|
||||
info: TypeDefInfo;
|
||||
isFromSi?: boolean;
|
||||
index?: number;
|
||||
length?: number;
|
||||
name?: string;
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
import type { Vec } from '../codec/Vec';
|
||||
import type { PortableType } from '../interfaces/metadata';
|
||||
import type { SiField, SiLookupTypeId, SiType, SiTypeDefArray, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiVariant } from '../interfaces/scaleInfo';
|
||||
import type { Type } from '../primitive/Type';
|
||||
import type { Registry, TypeDef } from '../types';
|
||||
|
||||
import { assert, isNumber, isString, stringCamelCase, stringify } from '@polkadot/util';
|
||||
|
||||
import { Struct } from '../codec/Struct';
|
||||
import { withTypeString } from '../create/encodeTypes';
|
||||
import { getTypeDef } from '../create/getTypeDef';
|
||||
import { TypeDefInfo } from '../types';
|
||||
|
||||
@@ -62,17 +64,33 @@ export class GenericPortableRegistry extends Struct {
|
||||
const index = this.#getLookupId(lookupId);
|
||||
|
||||
if (!this.#typeDefs[index]) {
|
||||
this.#typeDefs[index] = this.#extract(this.getSiType(lookupId), index);
|
||||
// we set first since we will get into circular lookups along the way
|
||||
this.#typeDefs[index] = {
|
||||
info: TypeDefInfo.DoNotConstruct,
|
||||
type: this.registry.createLookupType(index)
|
||||
};
|
||||
|
||||
const typeDef = this.#extract(this.getSiType(lookupId), index);
|
||||
|
||||
Object.keys(typeDef).forEach((key): void => {
|
||||
// these are safe since we are looking through the keys as set
|
||||
this.#typeDefs[index][key as 'info'] = typeDef[key as 'info'];
|
||||
});
|
||||
}
|
||||
|
||||
return this.#typeDefs[index];
|
||||
}
|
||||
|
||||
#createSiDef (type: SiLookupTypeId): TypeDef {
|
||||
return {
|
||||
info: TypeDefInfo.Si,
|
||||
type: this.registry.createLookupType(type)
|
||||
};
|
||||
#createSiDef (lookupId: SiLookupTypeId): TypeDef {
|
||||
const typeDef = this.getTypeDef(lookupId);
|
||||
|
||||
// Flatten Plain types immediately, otherwise setup for a lookup
|
||||
return typeDef.info === TypeDefInfo.Plain
|
||||
? typeDef
|
||||
: {
|
||||
info: TypeDefInfo.Si,
|
||||
type: this.registry.createLookupType(lookupId)
|
||||
};
|
||||
}
|
||||
|
||||
#getLookupId (lookupId: SiLookupTypeId | string | number): number {
|
||||
@@ -112,7 +130,7 @@ export class GenericPortableRegistry extends Struct {
|
||||
} else if (type.def.isComposite) {
|
||||
typeDef = this.#extractComposite(lookupIndex, type.def.asComposite);
|
||||
} else if (type.def.isHistoricMetaCompat) {
|
||||
typeDef = getTypeDef(type.def.asHistoricMetaCompat);
|
||||
typeDef = this.#extractHistoric(lookupIndex, type.def.asHistoricMetaCompat);
|
||||
} else if (type.def.isPrimitive) {
|
||||
typeDef = this.#extractPrimitive(lookupIndex, type);
|
||||
} else if (type.def.isSequence) {
|
||||
@@ -143,30 +161,28 @@ export class GenericPortableRegistry extends Struct {
|
||||
};
|
||||
}
|
||||
|
||||
#extractArray (lookupIndex: number, { len: length, type }: SiTypeDefArray): TypeDef {
|
||||
#extractArray (_: number, { len: length, type }: SiTypeDefArray): TypeDef {
|
||||
assert(!length || length.toNumber() <= 256, 'PortableRegistry: Only support for [Type; <length>], where length <= 256');
|
||||
|
||||
return {
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.VecFixed,
|
||||
length: length.toNumber(),
|
||||
sub: this.#createSiDef(type),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
sub: this.#createSiDef(type)
|
||||
});
|
||||
}
|
||||
|
||||
#extractCompact (lookupIndex: number, { type }: SiTypeDefCompact): TypeDef {
|
||||
return {
|
||||
#extractCompact (_: number, { type }: SiTypeDefCompact): TypeDef {
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Compact,
|
||||
sub: this.#createSiDef(type),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
sub: this.#createSiDef(type)
|
||||
});
|
||||
}
|
||||
|
||||
#extractComposite (lookupIndex: number, { fields }: SiTypeDefComposite): TypeDef {
|
||||
return this.#extractFields(lookupIndex, fields);
|
||||
}
|
||||
|
||||
#extractFields (lookupIndex: number, fields: SiField[]): TypeDef {
|
||||
#extractFields (_: number, fields: SiField[]): TypeDef {
|
||||
const [isStruct, isTuple] = fields.reduce(([isAllNamed, isAllUnnamed], { name }) => ([
|
||||
isAllNamed && name.isSome,
|
||||
isAllUnnamed && name.isNone
|
||||
@@ -175,21 +191,19 @@ export class GenericPortableRegistry extends Struct {
|
||||
|
||||
assert(isTuple || isStruct, 'PortableRegistry: Invalid fields type detected, expected either Tuple or Struct');
|
||||
|
||||
if (isTuple) {
|
||||
if (fields.length === 0) {
|
||||
return {
|
||||
info: TypeDefInfo.Null,
|
||||
type: 'Null'
|
||||
};
|
||||
} else if (fields.length === 1) {
|
||||
return {
|
||||
...this.#createSiDef(fields[0].type),
|
||||
...(fields[0].name.isSome
|
||||
? { name: stringCamelCase(fields[0].name.unwrap()) }
|
||||
: {}
|
||||
)
|
||||
};
|
||||
}
|
||||
if (fields.length === 0) {
|
||||
return {
|
||||
info: TypeDefInfo.Null,
|
||||
type: 'Null'
|
||||
};
|
||||
} else if (isTuple && fields.length === 1) {
|
||||
return {
|
||||
...this.#createSiDef(fields[0].type),
|
||||
...(fields[0].name.isSome
|
||||
? { name: stringCamelCase(fields[0].name.unwrap()) }
|
||||
: {}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
const sub = fields.map(({ name, type }) => ({
|
||||
@@ -200,16 +214,21 @@ export class GenericPortableRegistry extends Struct {
|
||||
)
|
||||
}));
|
||||
|
||||
return {
|
||||
return withTypeString(this.registry, {
|
||||
info: isTuple // Tuple check first
|
||||
? TypeDefInfo.Tuple
|
||||
: TypeDefInfo.Struct,
|
||||
sub,
|
||||
type: `(${sub.map(({ type }) => type).join(',')})`
|
||||
};
|
||||
sub
|
||||
});
|
||||
}
|
||||
|
||||
#extractPrimitive (lookupIndex: number, type: SiType): TypeDef {
|
||||
#extractHistoric (_: number, type: Type): TypeDef {
|
||||
const inner = getTypeDef(type);
|
||||
|
||||
return { ...inner, displayName: type.toString(), isFromSi: true };
|
||||
}
|
||||
|
||||
#extractPrimitive (_: number, type: SiType): TypeDef {
|
||||
const typeStr = type.def.asPrimitive.type.toString();
|
||||
|
||||
return {
|
||||
@@ -218,68 +237,89 @@ export class GenericPortableRegistry extends Struct {
|
||||
};
|
||||
}
|
||||
|
||||
#extractPrimitivePath (lookupIndex: number, type: SiType): TypeDef {
|
||||
#extractPrimitivePath (_: number, type: SiType): TypeDef {
|
||||
return {
|
||||
info: TypeDefInfo.Plain,
|
||||
type: type.path[type.path.length - 1].toString()
|
||||
};
|
||||
}
|
||||
|
||||
#extractSequence (lookupIndex: number, { type }: SiTypeDefSequence): TypeDef {
|
||||
return {
|
||||
#extractSequence (_: number, { type }: SiTypeDefSequence): TypeDef {
|
||||
const sub = this.#createSiDef(type);
|
||||
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Vec,
|
||||
sub: this.#createSiDef(type),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
sub
|
||||
});
|
||||
}
|
||||
|
||||
#extractTuple (lookupIndex: number, ids: SiTypeDefTuple): TypeDef {
|
||||
return ids.length === 1
|
||||
? this.getTypeDef(ids[0])
|
||||
: {
|
||||
info: TypeDefInfo.Tuple,
|
||||
sub: ids.map((type) => this.#createSiDef(type)),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
#extractTuple (_: number, ids: SiTypeDefTuple): TypeDef {
|
||||
if (ids.length === 1) {
|
||||
return this.getTypeDef(ids[0]);
|
||||
}
|
||||
|
||||
const sub = ids.map((type) => this.#createSiDef(type));
|
||||
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Tuple,
|
||||
sub
|
||||
});
|
||||
}
|
||||
|
||||
#extractVariant (lookupIndex: number, { params, path }: SiType, { variants }: SiTypeDefVariant): TypeDef {
|
||||
const specialVariant = path[0].toString();
|
||||
|
||||
return specialVariant === 'Option'
|
||||
? {
|
||||
if (specialVariant === 'Option') {
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Option,
|
||||
sub: this.#createSiDef(params[0].type.unwrap()),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
}
|
||||
: specialVariant === 'Result'
|
||||
? {
|
||||
info: TypeDefInfo.Result,
|
||||
sub: params.map((p, index) => ({
|
||||
name: ['Ok', 'Error'][index],
|
||||
...this.#createSiDef(p.type.unwrap())
|
||||
})),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
}
|
||||
: {
|
||||
info: TypeDefInfo.Enum,
|
||||
sub: this.#extractVariantSub(lookupIndex, variants),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
sub: this.#createSiDef(params[0].type.unwrap())
|
||||
});
|
||||
} else if (specialVariant === 'Result') {
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Result,
|
||||
sub: params.map((p) => this.#createSiDef(p.type.unwrap())).map((def, index) => ({
|
||||
name: ['Ok', 'Error'][index],
|
||||
...def
|
||||
}))
|
||||
});
|
||||
} else if (variants.length === 0) {
|
||||
return {
|
||||
info: TypeDefInfo.Null,
|
||||
type: 'Null'
|
||||
};
|
||||
}
|
||||
|
||||
return this.#extractVariantEnum(lookupIndex, variants);
|
||||
}
|
||||
|
||||
#extractVariantSub (lookupIndex: number, variants: SiVariant[]): TypeDef[] {
|
||||
return variants.every(({ fields }) => fields.length === 0)
|
||||
? variants.map(({ index, name }) => ({
|
||||
index: index.toNumber(),
|
||||
info: TypeDefInfo.Plain,
|
||||
name: name.toString(),
|
||||
type: 'Null'
|
||||
}))
|
||||
: variants.map(({ fields, index, name }) => ({
|
||||
...this.#extractFields(lookupIndex, fields),
|
||||
index: index.toNumber(),
|
||||
name: name.toString()
|
||||
}));
|
||||
#extractVariantEnum (lookupIndex: number, variants: SiVariant[]): TypeDef {
|
||||
const sub: (TypeDef & { name: string })[] = [];
|
||||
|
||||
// we may get entries out of order, arrange them first before creating with gaps filled
|
||||
variants
|
||||
.sort((a, b) => a.index.cmp(b.index))
|
||||
.forEach(({ fields, index, name }) => {
|
||||
const desired = index.toNumber();
|
||||
|
||||
while (sub.length !== desired) {
|
||||
sub.push({
|
||||
index: sub.length,
|
||||
info: TypeDefInfo.Null,
|
||||
name: `Unused${sub.length}`,
|
||||
type: 'Null'
|
||||
});
|
||||
}
|
||||
|
||||
sub.push({
|
||||
...this.#extractFields(lookupIndex, fields),
|
||||
index: index.toNumber(),
|
||||
name: name.toString()
|
||||
});
|
||||
});
|
||||
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Enum,
|
||||
sub
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1869,7 +1869,7 @@ __metadata:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/api": 5.1.2-7
|
||||
"@polkadot/types": 5.1.2-7
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util": ^7.0.3-0
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@@ -1880,12 +1880,12 @@ __metadata:
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/api": 5.1.2-7
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/keyring": ^7.0.3-0
|
||||
"@polkadot/rpc-core": 5.1.2-7
|
||||
"@polkadot/rpc-provider": 5.1.2-7
|
||||
"@polkadot/types": 5.1.2-7
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util-crypto": ^7.0.2
|
||||
"@polkadot/util": ^7.0.3-0
|
||||
"@polkadot/util-crypto": ^7.0.3-0
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@@ -1896,13 +1896,13 @@ __metadata:
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/api-derive": 5.1.2-7
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/keyring": ^7.0.3-0
|
||||
"@polkadot/rpc-core": 5.1.2-7
|
||||
"@polkadot/rpc-provider": 5.1.2-7
|
||||
"@polkadot/types": 5.1.2-7
|
||||
"@polkadot/types-known": 5.1.2-7
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util-crypto": ^7.0.2
|
||||
"@polkadot/util": ^7.0.3-0
|
||||
"@polkadot/util-crypto": ^7.0.3-0
|
||||
eventemitter3: ^4.0.7
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
@@ -2001,26 +2001,26 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/keyring@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/keyring@npm:7.0.2"
|
||||
"@polkadot/keyring@npm:^7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/keyring@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/util": 7.0.2
|
||||
"@polkadot/util-crypto": 7.0.2
|
||||
"@polkadot/util": 7.0.3-0
|
||||
"@polkadot/util-crypto": 7.0.3-0
|
||||
peerDependencies:
|
||||
"@polkadot/util": 7.0.2
|
||||
"@polkadot/util-crypto": 7.0.2
|
||||
checksum: f963ca2f474f95f9abacf255b22f95bd188f30e4b288d0703b484e6abc54d76b3244f9a9170af763be04a04fc8198ad1481c22a00e14a1dea449847a8360bd43
|
||||
"@polkadot/util": 7.0.3-0
|
||||
"@polkadot/util-crypto": 7.0.3-0
|
||||
checksum: 53ea603e40ffda04bb41e3478f7c5385f04905adf4f8ec577419b087691f2d878a5fec53cb02752bde22086fd311242e421bfae2ffb0367b619b16543af53cff
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/networks@npm:7.0.2, @polkadot/networks@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/networks@npm:7.0.2"
|
||||
"@polkadot/networks@npm:7.0.3-0, @polkadot/networks@npm:^7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/networks@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
checksum: c12b99d537523ac57fdfedaf1ecd759d74cd74b4bde121efb6917079b8ad33138799f8f083af602b523ef6473170667c40a80fc035499d9704e9ea8b495d9935
|
||||
checksum: e96d777a4c55218223665b498e844a1d327a75257e119e6a5096376827fbeab1b254c9ae812f04e288d4544f5e22876470e3ffd4f78a0541c22ee9b486d5a07d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2029,10 +2029,10 @@ __metadata:
|
||||
resolution: "@polkadot/rpc-core@workspace:packages/rpc-core"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/keyring": ^7.0.3-0
|
||||
"@polkadot/rpc-provider": 5.1.2-7
|
||||
"@polkadot/types": 5.1.2-7
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util": ^7.0.3-0
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@@ -2042,13 +2042,13 @@ __metadata:
|
||||
resolution: "@polkadot/rpc-provider@workspace:packages/rpc-provider"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/keyring": ^7.0.3-0
|
||||
"@polkadot/types": 5.1.2-7
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util-crypto": ^7.0.2
|
||||
"@polkadot/x-fetch": ^7.0.2
|
||||
"@polkadot/x-global": ^7.0.2
|
||||
"@polkadot/x-ws": ^7.0.2
|
||||
"@polkadot/util": ^7.0.3-0
|
||||
"@polkadot/util-crypto": ^7.0.3-0
|
||||
"@polkadot/x-fetch": ^7.0.3-0
|
||||
"@polkadot/x-global": ^7.0.3-0
|
||||
"@polkadot/x-ws": ^7.0.3-0
|
||||
eventemitter3: ^4.0.7
|
||||
mock-socket: ^9.0.3
|
||||
nock: ^13.1.1
|
||||
@@ -2074,7 +2074,7 @@ __metadata:
|
||||
"@polkadot/api": 5.1.2-7
|
||||
"@polkadot/rpc-provider": 5.1.2-7
|
||||
"@polkadot/types": 5.1.2-7
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util": ^7.0.3-0
|
||||
"@types/websocket": ^1.0.3
|
||||
"@types/yargs": ^17.0.2
|
||||
handlebars: ^4.7.7
|
||||
@@ -2094,9 +2094,9 @@ __metadata:
|
||||
resolution: "@polkadot/types-known@workspace:packages/types-known"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/networks": ^7.0.2
|
||||
"@polkadot/networks": ^7.0.3-0
|
||||
"@polkadot/types": 5.1.2-7
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util": ^7.0.3-0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
@@ -2105,24 +2105,24 @@ __metadata:
|
||||
resolution: "@polkadot/types@workspace:packages/types"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util-crypto": ^7.0.2
|
||||
"@polkadot/keyring": ^7.0.3-0
|
||||
"@polkadot/util": ^7.0.3-0
|
||||
"@polkadot/util-crypto": ^7.0.3-0
|
||||
"@types/bn.js": ^4.11.6
|
||||
bn.js: ^4.11.9
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/util-crypto@npm:7.0.2, @polkadot/util-crypto@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/util-crypto@npm:7.0.2"
|
||||
"@polkadot/util-crypto@npm:7.0.3-0, @polkadot/util-crypto@npm:^7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/util-crypto@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/networks": 7.0.2
|
||||
"@polkadot/util": 7.0.2
|
||||
"@polkadot/networks": 7.0.3-0
|
||||
"@polkadot/util": 7.0.3-0
|
||||
"@polkadot/wasm-crypto": ^4.1.2
|
||||
"@polkadot/x-randomvalues": 7.0.2
|
||||
"@polkadot/x-randomvalues": 7.0.3-0
|
||||
base-x: ^3.0.8
|
||||
base64-js: ^1.5.1
|
||||
blakejs: ^1.1.1
|
||||
@@ -2135,23 +2135,23 @@ __metadata:
|
||||
tweetnacl: ^1.0.3
|
||||
xxhashjs: ^0.2.2
|
||||
peerDependencies:
|
||||
"@polkadot/util": 7.0.2
|
||||
checksum: a5f500f510f9fd5fe5a6b2566453b44ea94f63bb2fd608c7495a54112fea71abf342730b4c6758947f65835d6a3e6731b5975d775108855a48d3a5637129400b
|
||||
"@polkadot/util": 7.0.3-0
|
||||
checksum: bbf279d2930f07cd1399c6eebdfd0050d8ac538d193bea156ee9eb4ad0dc770c47d445033bfa41e53a0f16175c5b2f9be3ba3644f22a6b87a484a7229cef2d68
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/util@npm:7.0.2, @polkadot/util@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/util@npm:7.0.2"
|
||||
"@polkadot/util@npm:7.0.3-0, @polkadot/util@npm:^7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/util@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-textdecoder": 7.0.2
|
||||
"@polkadot/x-textencoder": 7.0.2
|
||||
"@polkadot/x-textdecoder": 7.0.3-0
|
||||
"@polkadot/x-textencoder": 7.0.3-0
|
||||
"@types/bn.js": ^4.11.6
|
||||
bn.js: ^4.11.9
|
||||
camelcase: ^5.3.1
|
||||
ip-regex: ^4.3.0
|
||||
checksum: 5fea37104aa5712a288cdb10b65f8d1dd4e743c7d9b4b09ce1e17aeea5a4400817f187cf8c9fd7c9b2161ede8c99d5b4dc22418b7f7426527cb12592dad91432
|
||||
checksum: 61f2bdfdb5b223f55912c22a76f9ae0b91ad105204960e5aca9fa98f892bfba693a7ff56e036428e1e842a5987a045c5245e8e3a1ec9e1a0eeabdbccb9554014
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2187,66 +2187,66 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-fetch@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-fetch@npm:7.0.2"
|
||||
"@polkadot/x-fetch@npm:^7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/x-fetch@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
"@polkadot/x-global": 7.0.3-0
|
||||
"@types/node-fetch": ^2.5.11
|
||||
node-fetch: ^2.6.1
|
||||
checksum: aaef78745959210ffdeae25d0845781c3c7afe12e3bc094a50334051817446ff4397d34b2daac3cefa7f75b60216d8588491fc7418daa9ab9b5e6cd1a99b447d
|
||||
checksum: d2fb35d13132f75af608274f66716872b06f2e31fc4d65980dea59e69c93b747210bc2a2bda7d69bfc22d78e7925b09cc3b9704c1b2d56d128161f3fe4e7293c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-global@npm:7.0.2, @polkadot/x-global@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-global@npm:7.0.2"
|
||||
"@polkadot/x-global@npm:7.0.3-0, @polkadot/x-global@npm:^7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/x-global@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
checksum: 35705f8d33e746ab872288ae61fd31ead5b2fbefd0ef942f0cf8be76ac3e54a304b3ff9ced960232cb3bca0d71c5515a0abe8e534cc5f2fbcdf543c8df01f1f6
|
||||
checksum: f5d40749e224af1edbe7e4b3b1798f6dfb0a51201d139e49b4bd6a4ebbcdf95169ea6c831eb255ecf5ee9028aba5e09a8df8bae0467a64e6ac2aaa348e1c837b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-randomvalues@npm:7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-randomvalues@npm:7.0.2"
|
||||
"@polkadot/x-randomvalues@npm:7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/x-randomvalues@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
checksum: e6f2fd9f7386ceb6124366580ef639f664b9b3624644e4749ac19e2a17456f84078febb953e293fe5cc8cbed287f1ab84e8d1acfe7d075c5a3fb779253ede082
|
||||
"@polkadot/x-global": 7.0.3-0
|
||||
checksum: 84278e9ae351a9a22502547e0705ac848cfb4fc5b8ed259095177262a84cd46ea5b2eee0ef967aaa29fda8848596a25f51a0a25b0e28367dc78b4b2133fa88e4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-textdecoder@npm:7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-textdecoder@npm:7.0.2"
|
||||
"@polkadot/x-textdecoder@npm:7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/x-textdecoder@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
checksum: ad31a9ed430d1886168f42d6b8fc5528c22b783b7c4d086a2c77ac66017af4800c64a80a8466f85e93ea73e5892cebbd1f4612bdd4c7a5ed87227ee9a3f98f5e
|
||||
"@polkadot/x-global": 7.0.3-0
|
||||
checksum: fd233da7b8b22fda2ef8dcc38b3648331b53b0d22083f48de0c7ae062ddd243abd8c101f545d42c491ec4cc8b4883fdaa192629fc80ed79b2824e7b38969d254
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-textencoder@npm:7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-textencoder@npm:7.0.2"
|
||||
"@polkadot/x-textencoder@npm:7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/x-textencoder@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
checksum: 990ed08a001112a33d7ecbe1c6b442afacb3e09a04b10c62574876e2a2d26d0ee0da31f41a3731ffa91b19799c3828a8f09e0ee883768f608fd499b724774d6e
|
||||
"@polkadot/x-global": 7.0.3-0
|
||||
checksum: 0237178d92e99623feee0a10fef13e26c84e67611d3a6bd00ad56a4fe3a9d5506279f8476213124191fbb66afbc1c22189c19cf7c327625fe5ada67c2c376ccf
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-ws@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-ws@npm:7.0.2"
|
||||
"@polkadot/x-ws@npm:^7.0.3-0":
|
||||
version: 7.0.3-0
|
||||
resolution: "@polkadot/x-ws@npm:7.0.3-0"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
"@polkadot/x-global": 7.0.3-0
|
||||
"@types/websocket": ^1.0.3
|
||||
websocket: ^1.0.34
|
||||
checksum: 7b62fbd7254596aa60d541eb40d973e0ba7d962906596864742698b7bf9c8ad57153db61e213d647b9fad40f59ed01ceb0dbee7bef41970989b16990f0541ea2
|
||||
checksum: ba527964e271c4d0aa7ebb8272043beb02fc8f1b8375cbdd5e4ceca989f8e65162a74b5fa70cdea338894eaee47952b55245926d1b0391777b0001c8b9efa0a2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user