@@ -14,7 +14,7 @@ export function lazyVariants <T> (lookup: PortableRegistry, { type }: TypeHolder
|
||||
const result: Record<string, T> = {};
|
||||
const variants = lookup.getSiType(type).def.asVariant.variants;
|
||||
|
||||
for (let i = 0; i < variants.length; i++) {
|
||||
for (let i = 0, count = variants.length; i < count; i++) {
|
||||
lazyMethod(result, variants[i], creator, getName, i);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,9 +35,10 @@ function valueToString (v: { toString: () => string }): string {
|
||||
}
|
||||
|
||||
function getFieldArgs (lookup: PortableRegistry, fields: SiField[]): string[] {
|
||||
const args = new Array<string>(fields.length);
|
||||
const count = fields.length;
|
||||
const args = new Array<string>(count);
|
||||
|
||||
for (let i = 0; i < fields.length; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
args[i] = lookup.getTypeDef(fields[i].type).type;
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ function getFieldArgs (lookup: PortableRegistry, fields: SiField[]): string[] {
|
||||
function clearRecord (record: Record<string, unknown>): void {
|
||||
const keys = Object.keys(record);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
for (let i = 0, count = keys.length; i < count; i++) {
|
||||
delete record[keys[i]];
|
||||
}
|
||||
}
|
||||
@@ -60,7 +61,7 @@ function getVariantStringIdx ({ index }: SiVariant): string {
|
||||
function injectErrors (_: TypeRegistry, { lookup, pallets }: MetadataLatest, version: number, result: Record<string, Record<string, RegistryError>>): void {
|
||||
clearRecord(result);
|
||||
|
||||
for (let i = 0; i < pallets.length; i++) {
|
||||
for (let i = 0, count = pallets.length; i < count; i++) {
|
||||
const { errors, index, name } = pallets[i];
|
||||
|
||||
if (errors.isSome) {
|
||||
@@ -87,7 +88,7 @@ function injectEvents (registry: TypeRegistry, { lookup, pallets }: MetadataLate
|
||||
|
||||
clearRecord(result);
|
||||
|
||||
for (let i = 0; i < filtered.length; i++) {
|
||||
for (let i = 0, count = filtered.length; i < count; i++) {
|
||||
const { events, index, name } = filtered[i];
|
||||
|
||||
lazyMethod(result, version >= 12 ? index.toNumber() : i, () =>
|
||||
@@ -111,7 +112,7 @@ function injectExtrinsics (registry: TypeRegistry, { lookup, pallets }: Metadata
|
||||
clearRecord(result);
|
||||
clearRecord(mapping);
|
||||
|
||||
for (let i = 0; i < filtered.length; i++) {
|
||||
for (let i = 0, count = filtered.length; i < count; i++) {
|
||||
const { calls, index, name } = filtered[i];
|
||||
const sectionIndex = version >= 12 ? index.toNumber() : i;
|
||||
const sectionName = stringCamelCase(name);
|
||||
@@ -180,6 +181,7 @@ export class TypeRegistry implements Registry {
|
||||
#userExtensions?: ExtDef | undefined;
|
||||
|
||||
readonly #knownDefaults: Record<string, CodecClass>;
|
||||
readonly #knownDefaultsEntries: [string, CodecClass][];
|
||||
readonly #knownDefinitions: Record<string, Definitions>;
|
||||
readonly #metadataCalls: Record<string, Record<string, CallFunction>> = {};
|
||||
readonly #metadataErrors: Record<string, Record<string, RegistryError>> = {};
|
||||
@@ -190,11 +192,12 @@ export class TypeRegistry implements Registry {
|
||||
|
||||
constructor (createdAtHash?: Hash | Uint8Array | string) {
|
||||
this.#knownDefaults = objectSpread({ Json, Metadata, PortableRegistry, Raw }, baseTypes);
|
||||
this.#knownDefaultsEntries = Object.entries(this.#knownDefaults);
|
||||
this.#knownDefinitions = definitions;
|
||||
|
||||
const allKnown = Object.values(this.#knownDefinitions);
|
||||
|
||||
for (let i = 0; i < allKnown.length; i++) {
|
||||
for (let i = 0, count = allKnown.length; i < count; i++) {
|
||||
this.register(allKnown[i].types as unknown as RegistryTypes);
|
||||
}
|
||||
|
||||
@@ -393,7 +396,7 @@ export class TypeRegistry implements Registry {
|
||||
// (previously this used to be a simple find & return)
|
||||
const names: string[] = [];
|
||||
|
||||
for (const [name, Clazz] of Object.entries(this.#knownDefaults)) {
|
||||
for (const [name, Clazz] of this.#knownDefaultsEntries) {
|
||||
if (Type === Clazz) {
|
||||
names.push(name);
|
||||
}
|
||||
@@ -405,11 +408,10 @@ export class TypeRegistry implements Registry {
|
||||
}
|
||||
}
|
||||
|
||||
// both sort and reverse are done in-place
|
||||
names.sort().reverse();
|
||||
|
||||
return names.length
|
||||
? names[0]
|
||||
// both sort and reverse are done in-place
|
||||
// ['U32', 'u32'] -> ['u32', 'U32']
|
||||
? names.sort().reverse()[0]
|
||||
: undefined;
|
||||
}
|
||||
|
||||
@@ -485,7 +487,7 @@ export class TypeRegistry implements Registry {
|
||||
#registerObject = (obj: RegistryTypes): void => {
|
||||
const entries = Object.entries(obj);
|
||||
|
||||
for (let e = 0; e < entries.length; e++) {
|
||||
for (let e = 0, count = entries.length; e < count; e++) {
|
||||
const [name, type] = entries[e];
|
||||
|
||||
if (isFunction(type)) {
|
||||
|
||||
@@ -88,7 +88,7 @@ abstract class ExtrinsicBase<A extends AnyTuple> extends AbstractBase<ExtrinsicV
|
||||
|
||||
// This is on the abstract class, ensuring that hasOwnProperty operates
|
||||
// correctly, i.e. it needs to be on the base class exposing it
|
||||
for (let i = 0; i < signKeys.length; i++) {
|
||||
for (let i = 0, count = signKeys.length; i < count; i++) {
|
||||
objectProperty(this, signKeys[i], getter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign
|
||||
const keys = Object.keys(this.#extraTypes);
|
||||
|
||||
// add any explicit overrides we may have
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
for (let i = 0, count = keys.length; i < count; i++) {
|
||||
const key = keys[i];
|
||||
const value = this.get(key) as Codec;
|
||||
const isOption = value instanceof Option;
|
||||
|
||||
@@ -120,7 +120,7 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
|
||||
|
||||
protected _injectSignature (signer: Address, signature: ExtrinsicSignature, payload: GenericExtrinsicPayloadV4): IExtrinsicSignature {
|
||||
// use the fields exposed to guide the getters
|
||||
for (let i = 0; i < this.#signKeys.length; i++) {
|
||||
for (let i = 0, count = this.#signKeys.length; i < count; i++) {
|
||||
const k = this.#signKeys[i];
|
||||
const v = payload.get(k);
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ export class GenericEventData extends Tuple implements IEventData {
|
||||
if (this.#names !== null) {
|
||||
const json: Record<string, AnyJson> = {};
|
||||
|
||||
for (let i = 0; i < this.#names.length; i++) {
|
||||
for (let i = 0, count = this.#names.length; i < count; i++) {
|
||||
json[this.#names[i]] = this[i].toHuman(isExtended);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,9 +103,10 @@ const PATH_RM_INDEX_1 = ['generic', 'misc', 'pallet', 'traits', 'types'];
|
||||
|
||||
/** @internal Converts a Text[] into string[] (used as part of definitions) */
|
||||
function sanitizeDocs (docs: Text[]): string[] {
|
||||
const result = new Array<string>(docs.length);
|
||||
const count = docs.length;
|
||||
const result = new Array<string>(count);
|
||||
|
||||
for (let i = 0; i < docs.length; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
result[i] = docs[i].toString();
|
||||
}
|
||||
|
||||
@@ -114,9 +115,10 @@ function sanitizeDocs (docs: Text[]): string[] {
|
||||
|
||||
/** @internal Split a namespace with :: into individual parts */
|
||||
function splitNamespace (values: string[]): string[][] {
|
||||
const result = new Array<string[]>(values.length);
|
||||
const count = values.length;
|
||||
const result = new Array<string[]>(count);
|
||||
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
result[i] = values[i].split('::');
|
||||
}
|
||||
|
||||
@@ -237,7 +239,7 @@ function extractName (portable: PortableType[], lookupIndex: number, { type: { p
|
||||
function nextDupeMatches (name: string, startAt: number, names: Extract[]): Extract[] {
|
||||
const result = [names[startAt]];
|
||||
|
||||
for (let i = startAt + 1; i < names.length; i++) {
|
||||
for (let i = startAt + 1, count = names.length; i < count; i++) {
|
||||
const v = names[i];
|
||||
|
||||
if (v.name === name) {
|
||||
@@ -331,11 +333,12 @@ function removeDupeNames (lookup: PortableRegistry, portable: PortableType[], na
|
||||
}
|
||||
|
||||
// see if using the param type helps
|
||||
const adjusted = new Array<ExtractBase>(allSame.length);
|
||||
const sameCount = allSame.length;
|
||||
const adjusted = new Array<ExtractBase>(sameCount);
|
||||
|
||||
// loop through all, specifically checking that index where the
|
||||
// first param yields differences
|
||||
for (let i = 0; i < allSame.length; i++) {
|
||||
for (let i = 0; i < sameCount; i++) {
|
||||
const { lookupIndex, name, params } = allSame[i];
|
||||
const { def, path } = lookup.getSiType(params[paramIdx].type.unwrap());
|
||||
|
||||
@@ -364,7 +367,7 @@ function removeDupeNames (lookup: PortableRegistry, portable: PortableType[], na
|
||||
// Last-ditch effort to use the full type path - ugly
|
||||
// loop through all, specifically checking that index where the
|
||||
// first param yields differences
|
||||
for (let i = 0; i < allSame.length; i++) {
|
||||
for (let i = 0; i < sameCount; i++) {
|
||||
const { lookupIndex, name, params } = allSame[i];
|
||||
const { def, path } = lookup.getSiType(params[paramIdx].type.unwrap());
|
||||
const flat = extractNameFlat(portable, lookupIndex, params, path, true);
|
||||
@@ -465,9 +468,8 @@ function extractAliases (params: Record<string, SiTypeParameter[]>, isContract?:
|
||||
function extractTypeInfo (lookup: PortableRegistry, portable: PortableType[]): TypeInfo {
|
||||
const nameInfo: Extract[] = [];
|
||||
const types: Record<number, PortableType> = {};
|
||||
const porCount = portable.length;
|
||||
|
||||
for (let i = 0; i < porCount; i++) {
|
||||
for (let i = 0, count = portable.length; i < count; i++) {
|
||||
const type = portable[i];
|
||||
const lookupIndex = type.id.toNumber();
|
||||
const extracted = extractName(portable, lookupIndex, portable[i]);
|
||||
@@ -483,9 +485,8 @@ function extractTypeInfo (lookup: PortableRegistry, portable: PortableType[]): T
|
||||
const names: Record<number, string> = {};
|
||||
const params: Record<string, SiTypeParameter[]> = {};
|
||||
const dedup = removeDupeNames(lookup, portable, nameInfo);
|
||||
const dedupCount = dedup.length;
|
||||
|
||||
for (let i = 0; i < dedupCount; i++) {
|
||||
for (let i = 0, count = dedup.length; i < count; i++) {
|
||||
const { lookupIndex, name, params: p } = dedup[i];
|
||||
|
||||
names[lookupIndex] = name;
|
||||
@@ -832,8 +833,9 @@ export class PortableRegistry extends Struct implements ILookup {
|
||||
#extractFields (lookupIndex: number, fields: SiField[]): TypeDef {
|
||||
let isStruct = true;
|
||||
let isTuple = true;
|
||||
const count = fields.length;
|
||||
|
||||
for (let f = 0; f < fields.length; f++) {
|
||||
for (let f = 0; f < count; f++) {
|
||||
const { name } = fields[f];
|
||||
|
||||
isStruct = isStruct && name.isSome;
|
||||
@@ -844,12 +846,12 @@ export class PortableRegistry extends Struct implements ILookup {
|
||||
throw new Error('Invalid fields type detected, expected either Tuple (all unnamed) or Struct (all named)');
|
||||
}
|
||||
|
||||
if (fields.length === 0) {
|
||||
if (count === 0) {
|
||||
return {
|
||||
info: TypeDefInfo.Null,
|
||||
type: 'Null'
|
||||
};
|
||||
} else if (isTuple && fields.length === 1) {
|
||||
} else if (isTuple && count === 1) {
|
||||
const typeDef = this.#createSiDef(fields[0].type);
|
||||
|
||||
return objectSpread(
|
||||
@@ -892,9 +894,10 @@ export class PortableRegistry extends Struct implements ILookup {
|
||||
/** @internal Apply field aliassed (with no JS conflicts) */
|
||||
#extractFieldsAlias (fields: SiField[]): [TypeDef[], Map<string, string>] {
|
||||
const alias = new Map<string, string>();
|
||||
const sub = new Array<TypeDef>(fields.length);
|
||||
const count = fields.length;
|
||||
const sub = new Array<TypeDef>(count);
|
||||
|
||||
for (let i = 0; i < fields.length; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
const { docs, name, type, typeName } = fields[i];
|
||||
const typeDef = this.#createSiDef(type);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import { objectNameToCamel } from '../util.js';
|
||||
export function decorateConstants (registry: Registry, { pallets }: MetadataLatest, _version: number): Constants {
|
||||
const result: Constants = {};
|
||||
|
||||
for (let i = 0; i < pallets.length; i++) {
|
||||
for (let i = 0, count = pallets.length; i < count; i++) {
|
||||
const { constants, name } = pallets[i];
|
||||
|
||||
if (!constants.isEmpty) {
|
||||
|
||||
@@ -31,7 +31,7 @@ export function variantToMeta (lookup: PortableRegistry, variant: SiVariant): It
|
||||
export function decorateErrors (registry: Registry, { lookup, pallets }: MetadataLatest, version: number): Errors {
|
||||
const result: Errors = {};
|
||||
|
||||
for (let i = 0; i < pallets.length; i++) {
|
||||
for (let i = 0, count = pallets.length; i < count; i++) {
|
||||
const { errors, index, name } = pallets[i];
|
||||
|
||||
if (errors.isSome) {
|
||||
|
||||
@@ -21,7 +21,7 @@ export function decorateEvents (registry: Registry, { lookup, pallets }: Metadat
|
||||
const result: Events = {};
|
||||
const filtered = pallets.filter(filterEventsSome);
|
||||
|
||||
for (let i = 0; i < filtered.length; i++) {
|
||||
for (let i = 0, count = filtered.length; i < count; i++) {
|
||||
const { events, index, name } = filtered[i];
|
||||
const sectionIndex = version >= 12 ? index.toNumber() : i;
|
||||
|
||||
|
||||
@@ -20,14 +20,15 @@ export function filterCallsSome ({ calls }: PalletMetadataLatest): boolean {
|
||||
|
||||
export function createCallFunction (registry: Registry, lookup: PortableRegistry, variant: SiVariant, sectionName: string, sectionIndex: number): CallFunction {
|
||||
const { fields, index } = variant;
|
||||
const args = new Array<Record<string, unknown>>(fields.length);
|
||||
const count = fields.length;
|
||||
const args = new Array<Record<string, unknown>>(count);
|
||||
|
||||
for (let a = 0; a < fields.length; a++) {
|
||||
const { name, type, typeName } = fields[a];
|
||||
for (let i = 0; i < count; i++) {
|
||||
const { name, type, typeName } = fields[i];
|
||||
|
||||
args[a] = objectSpread(
|
||||
args[i] = objectSpread(
|
||||
{
|
||||
name: stringCamelCase(name.unwrapOr(`param${a}`)),
|
||||
name: stringCamelCase(name.unwrapOr(`param${i}`)),
|
||||
type: getSiName(lookup, type)
|
||||
},
|
||||
typeName.isSome
|
||||
@@ -49,7 +50,7 @@ export function decorateExtrinsics (registry: Registry, { lookup, pallets }: Met
|
||||
const result: Extrinsics = {};
|
||||
const filtered = pallets.filter(filterCallsSome);
|
||||
|
||||
for (let i = 0; i < filtered.length; i++) {
|
||||
for (let i = 0, count = filtered.length; i < count; i++) {
|
||||
const { calls, index, name } = filtered[i];
|
||||
const sectionName = stringCamelCase(name);
|
||||
const sectionIndex = version >= 12 ? index.toNumber() : i;
|
||||
|
||||
@@ -62,9 +62,10 @@ function assertArgs ({ method, section }: CreateItemFn, { args, keys }: RawArgs)
|
||||
|
||||
/** @internal */
|
||||
export function createKeyRawParts (registry: Registry, itemFn: CreateItemBase, { args, hashers, keys }: RawArgs): [Uint8Array[], Uint8Array[]] {
|
||||
const extra = new Array<Uint8Array>(keys.length);
|
||||
const count = keys.length;
|
||||
const extra = new Array<Uint8Array>(count);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
extra[i] = getHasher(hashers[i])(
|
||||
registry.createTypeUnsafe(registry.createLookupType(keys[i]), [args[i]]).toU8a()
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ export function getStorage (registry: Registry): Storage {
|
||||
const storage: Record<string, StorageEntry> = {};
|
||||
const entries = Object.entries(substrate);
|
||||
|
||||
for (let e = 0; e < entries.length; e++) {
|
||||
for (let e = 0, count = entries.length; e < count; e++) {
|
||||
storage[entries[e][0]] = entries[e][1](registry);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ const VERSION_DOCS = { docs: 'Returns the current pallet version from storage',
|
||||
export function decorateStorage (registry: Registry, { pallets }: MetadataLatest, _metaVersion: number): Storage {
|
||||
const result: Storage = getStorage(registry);
|
||||
|
||||
for (let i = 0; i < pallets.length; i++) {
|
||||
for (let i = 0, count = pallets.length; i < count; i++) {
|
||||
const { name, storage } = pallets[i];
|
||||
|
||||
if (storage.isSome) {
|
||||
|
||||
@@ -5,7 +5,7 @@ type Types = string | Types[];
|
||||
|
||||
/** @internal */
|
||||
export function flattenUniq (list: Types[], result: string[] = []): string[] {
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
for (let i = 0, count = list.length; i < count; i++) {
|
||||
const entry = list[i];
|
||||
|
||||
if (Array.isArray(entry)) {
|
||||
|
||||
@@ -54,7 +54,7 @@ function compatType (specs: TypeSpec[], _type: Text | string): number {
|
||||
}
|
||||
|
||||
function compatTypes (specs: TypeSpec[], ...types: (Text | string)[]): void {
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
for (let i = 0, count = types.length; i < count; i++) {
|
||||
compatType(specs, types[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,9 +85,10 @@ function decodeStorageKey (value?: string | Uint8Array | StorageKey | StorageEnt
|
||||
function decodeHashers <A extends AnyTuple> (registry: Registry, value: Uint8Array, hashers: [StorageHasher, SiLookupTypeId][]): A {
|
||||
// the storage entry is xxhashAsU8a(prefix, 128) + xxhashAsU8a(method, 128), 256 bits total
|
||||
let offset = 32;
|
||||
const result = new Array<Codec>(hashers.length);
|
||||
const count = hashers.length;
|
||||
const result = new Array<Codec>(count);
|
||||
|
||||
for (let i = 0; i < hashers.length; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
const [hasher, type] = hashers[i];
|
||||
const [hashLen, canDecode] = HASHER_MAP[hasher.type as 'Identity'];
|
||||
const decoded = canDecode
|
||||
|
||||
Reference in New Issue
Block a user