Augment Registry (w/o CodecRegistry & CreateRegistry) (#4463)

* Augment Registry (w/o CodecRegistry & CreateRegistry)

* Build fixes

* Final build fixes

* licence headers
This commit is contained in:
Jaco
2022-01-18 12:52:01 +02:00
committed by GitHub
parent f8c2701751
commit 500e2022c3
112 changed files with 570 additions and 537 deletions
+1 -2
View File
@@ -3,7 +3,6 @@
import type { Observable } from 'rxjs';
import type { AccountId } from '@polkadot/types/interfaces';
import type { Registry } from '@polkadot/types/types';
import type { HeaderExtended } from '../type/types';
import type { DeriveApi } from '../types';
@@ -39,7 +38,7 @@ export function getHeader (instanceId: string, api: DeriveApi): (blockHash: Uint
)
]).pipe(
map(([header, validators]) =>
createHeaderExtended(header.registry as Registry, header, validators)
createHeaderExtended(header.registry, header, validators)
),
catchError((): Observable<undefined> =>
// where rpc.chain.getHeader throws, we will land here - it can happen that
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { Registry } from '@polkadot/types/types';
import type { SignedBlockExtended } from '../type/types';
import type { DeriveApi } from '../types';
@@ -33,7 +32,7 @@ export function subscribeNewBlocks (instanceId: string, api: DeriveApi): () => O
]);
}),
map(([header, block, events]) =>
createSignedBlockExtended(block.registry as Registry, block, events, header.validators)
createSignedBlockExtended(block.registry, block, events, header.validators)
)
)
);
@@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { Registry } from '@polkadot/types/types';
import type { HeaderExtended } from '../type/types';
import type { DeriveApi } from '../types';
@@ -35,7 +34,7 @@ export function subscribeNewHeads (instanceId: string, api: DeriveApi): () => Ob
map(([header, validators]): HeaderExtended => {
header.createdAtHash = header.hash;
return createHeaderExtended(header.registry as Registry, header, validators);
return createHeaderExtended(header.registry, header, validators);
})
)
);
+2 -2
View File
@@ -472,7 +472,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
const lazySection = (section: string) =>
lazyMethods({}, Object.keys(query[section]), (method: string) =>
blockHash
? this._decorateStorageEntryAt(registry as Registry, query[section][method], decorateMethod, blockHash)
? this._decorateStorageEntryAt(registry, query[section][method], decorateMethod, blockHash)
: this._decorateStorageEntry(query[section][method], decorateMethod)
);
@@ -526,7 +526,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
decorated.sizeAt = decorateMethod((blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<u64> =>
getQueryAt(blockHash).pipe(
switchMap((q) =>
this._rpcCore.state.getStorageSize(getArgs(args, q.creator.meta.registry as Registry), blockHash))));
this._rpcCore.state.getStorageSize(getArgs(args, q.creator.meta.registry), blockHash))));
// .keys() & .entries() only available on map types
if (creator.iterKey && creator.meta.type.isMap) {
+3 -3
View File
@@ -6,7 +6,7 @@
import type { Observable, OperatorFunction } from 'rxjs';
import type { Address, ApplyExtrinsicResult, Call, Extrinsic, ExtrinsicEra, ExtrinsicStatus, Hash, Header, Index, RuntimeDispatchInfo, SignerPayload } from '@polkadot/types/interfaces';
import type { Callback, Codec, Constructor, IKeyringPair, ISubmittableResult, SignatureOptions } from '@polkadot/types/types';
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { ApiInterfaceRx, ApiTypes, PromiseOrObs, SignerResult } from '../types';
import type { AddressOrPair, SignerOptions, SubmittableDryRunResult, SubmittableExtrinsic, SubmittablePaymentResult, SubmittableResultResult, SubmittableResultSubscription } from './types';
@@ -26,7 +26,7 @@ interface SubmittableOptions<ApiType extends ApiTypes> {
const identity = <T> (input: T): T => input;
function makeEraOptions (api: ApiInterfaceRx, registry: CodecRegistry, partialOptions: Partial<SignerOptions>, { header, mortalLength, nonce }: { header: Header | null; mortalLength: number; nonce: Index }): SignatureOptions {
function makeEraOptions (api: ApiInterfaceRx, registry: Registry, partialOptions: Partial<SignerOptions>, { header, mortalLength, nonce }: { header: Header | null; mortalLength: number; nonce: Index }): SignatureOptions {
if (!header) {
if (isNumber(partialOptions.era)) {
// since we have no header, it is immortal, remove any option overrides
@@ -84,7 +84,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, decorate
#transformResult: (input: ISubmittableResult) => ISubmittableResult = identity;
constructor (registry: CodecRegistry, extrinsic: Call | Extrinsic | Uint8Array | string) {
constructor (registry: Registry, extrinsic: Call | Extrinsic | Uint8Array | string) {
super(registry, extrinsic, { version: api.extrinsicType });
this.#ignoreStatusCb = apiType === 'rxjs';
+2 -2
View File
@@ -219,8 +219,8 @@ function generateLookup (destDir: string, entries: [string | undefined, HexStrin
const { lookup, registry } = initMeta(staticMeta).metadata.asLatest;
const filtered = getFilteredTypes(lookup, exclude);
generateLookupDefs(registry as Registry, filtered, destDir, subPath);
generateLookupTypes(registry as Registry, filtered, destDir, subPath);
generateLookupDefs(registry, filtered, destDir, subPath);
generateLookupTypes(registry, filtered, destDir, subPath);
return exclude.concat(
...filtered
+27 -28
View File
@@ -4,7 +4,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { Registry } from '@polkadot/types/types';
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { TypeDef } from '@polkadot/types-create/types';
import Handlebars from 'handlebars';
@@ -109,7 +108,7 @@ export function exportInterface (lookupIndex = -1, name = '', base: string, body
return `${doc}export interface ${name} extends ${base} {${body.length ? '\n' : ''}${body}}`;
}
function singleParamNotation (registry: CodecRegistry, wrapper: string, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean): string {
function singleParamNotation (registry: Registry, wrapper: string, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean): string {
const sub = (typeDef.sub as TypeDef);
setImports(definitions, imports, [wrapper, sub.lookupName]);
@@ -117,7 +116,7 @@ function singleParamNotation (registry: CodecRegistry, wrapper: string, typeDef:
return paramsNotation(wrapper, sub.lookupName || formatType(registry, definitions, sub.type, imports, withShortcut));
}
function dualParamsNotation (registry: CodecRegistry, wrapper: string, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean): string {
function dualParamsNotation (registry: Registry, wrapper: string, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean): string {
const [a, b] = (typeDef.sub as TypeDef[]);
setImports(definitions, imports, [wrapper, a.lookupName, b.lookupName]);
@@ -128,18 +127,18 @@ function dualParamsNotation (registry: CodecRegistry, wrapper: string, typeDef:
]);
}
const formatters: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => string> = {
[TypeDefInfo.Compact]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
const formatters: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => string> = {
[TypeDefInfo.Compact]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return singleParamNotation(registry, 'Compact', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.DoNotConstruct]: (registry: CodecRegistry, { lookupName }: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.DoNotConstruct]: (registry: Registry, { lookupName }: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
setImports(definitions, imports, ['DoNotConstruct']);
return 'DoNotConstruct';
},
[TypeDefInfo.Enum]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Enum]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
if (typeDef.lookupName) {
return typeDef.lookupName;
}
@@ -147,43 +146,43 @@ const formatters: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef
throw new Error(`TypeDefInfo.Enum: Not implemented on ${stringify(typeDef)}`);
},
[TypeDefInfo.Int]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Int]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
throw new Error(`TypeDefInfo.Int: Not implemented on ${stringify(typeDef)}`);
},
[TypeDefInfo.UInt]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.UInt]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
throw new Error(`TypeDefInfo.UInt: Not implemented on ${stringify(typeDef)}`);
},
[TypeDefInfo.Null]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Null]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
setImports(definitions, imports, ['Null']);
return 'Null';
},
[TypeDefInfo.Option]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Option]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return singleParamNotation(registry, 'Option', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.Plain]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Plain]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
setImports(definitions, imports, [typeDef.type]);
return typeDef.type;
},
[TypeDefInfo.Range]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Range]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
throw new Error(`TypeDefInfo.Range: Not implemented on ${stringify(typeDef)}`);
},
[TypeDefInfo.Set]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Set]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
throw new Error(`TypeDefInfo.Set: Not implemented on ${stringify(typeDef)}`);
},
[TypeDefInfo.Si]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return formatType(registry, definitions, (registry as Registry).lookup.getTypeDef(typeDef.type), imports, withShortcut);
[TypeDefInfo.Si]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return formatType(registry, definitions, (registry).lookup.getTypeDef(typeDef.type), imports, withShortcut);
},
[TypeDefInfo.Struct]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Struct]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
if (typeDef.lookupName) {
return typeDef.lookupName;
}
@@ -200,7 +199,7 @@ const formatters: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef
}${withShortcut ? ' ' : '\n '}} & Struct`;
},
[TypeDefInfo.Tuple]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Tuple]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
const sub = typeDef.sub as TypeDef[];
setImports(definitions, imports, ['ITuple', ...sub.map(({ lookupName }) => lookupName)]);
@@ -213,11 +212,11 @@ const formatters: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef
}]`);
},
[TypeDefInfo.Vec]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Vec]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return singleParamNotation(registry, 'Vec', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.VecFixed]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.VecFixed]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
const sub = (typeDef.sub as TypeDef);
if (sub.type === 'u8') {
@@ -229,31 +228,31 @@ const formatters: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef
return singleParamNotation(registry, 'Vec', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.BTreeMap]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.BTreeMap]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return dualParamsNotation(registry, 'BTreeMap', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.BTreeSet]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.BTreeSet]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return singleParamNotation(registry, 'BTreeSet', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.HashMap]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.HashMap]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return dualParamsNotation(registry, 'HashMap', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.Linkage]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Linkage]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return singleParamNotation(registry, 'Linkage', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.Result]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.Result]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return dualParamsNotation(registry, 'Result', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.WrapperKeepOpaque]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.WrapperKeepOpaque]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return singleParamNotation(registry, 'WrapperKeepOpaque', typeDef, definitions, imports, withShortcut);
},
[TypeDefInfo.WrapperOpaque]: (registry: CodecRegistry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
[TypeDefInfo.WrapperOpaque]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports, withShortcut: boolean) => {
return singleParamNotation(registry, 'WrapperOpaque', typeDef, definitions, imports, withShortcut);
}
};
@@ -263,7 +262,7 @@ const formatters: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef
*/
/** @internal */
// eslint-disable-next-line @typescript-eslint/ban-types
export function formatType (registry: CodecRegistry, definitions: Record<string, ModuleTypes>, type: string | String | TypeDef, imports: TypeImports, withShortcut = false): string {
export function formatType (registry: Registry, definitions: Record<string, ModuleTypes>, type: string | String | TypeDef, imports: TypeImports, withShortcut = false): string {
let typeDef: TypeDef;
if (isString(type)) {
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecRegistry, IU8a, IVec } from '../types';
import type { AnyJson, Codec, IU8a, IVec, Registry } from '../types';
import { compactToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
@@ -16,13 +16,13 @@ import { compareArray } from '../utils/compareArray';
* @noInheritDoc
*/
export abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
readonly initialU8aLength?: number;
protected constructor (registry: CodecRegistry, values: T[], initialU8aLength?: number) {
protected constructor (registry: Registry, values: T[], initialU8aLength?: number) {
super(values.length);
// explicitly set the values here - this removes the need for any extra allocations
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyNumber, CodecRegistry, INumber, IU8a, UIntBitLength } from '../types';
import type { AnyNumber, INumber, IU8a, Registry, UIntBitLength } from '../types';
import { assert, BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, BN_ZERO, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isHex, isNumber, isString, isU8a, u8aToBn } from '@polkadot/util';
@@ -47,7 +47,7 @@ function decodeAbstractInt (value: AnyNumber, bitLength: UIntBitLength, isNegati
* @noInheritDoc
*/
export abstract class AbstractInt extends BN implements INumber {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
@@ -57,7 +57,7 @@ export abstract class AbstractInt extends BN implements INumber {
readonly #isSigned: boolean;
constructor (registry: CodecRegistry, value: AnyNumber = 0, bitLength: UIntBitLength = DEFAULT_UINT_BITS, isSigned = false) {
constructor (registry: Registry, value: AnyNumber = 0, bitLength: UIntBitLength = DEFAULT_UINT_BITS, isSigned = false) {
// Construct via a string, which will be passed in the BN constructor.
// It would be ideal to actually return a BN, but there is an issue:
// https://github.com/indutny/bn.js/issues/206
+4 -4
View File
@@ -2,14 +2,14 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, BareOpts, Codec, CodecRegistry, IU8a } from '../types';
import type { AnyJson, BareOpts, Codec, IU8a, Registry } from '../types';
/**
* @name Base
* @description A type extends the Base class, when it holds a value
*/
export abstract class Base<T extends Codec> implements Codec {
readonly #registry: CodecRegistry;
readonly #registry: Registry;
public createdAtHash?: IU8a;
@@ -17,7 +17,7 @@ export abstract class Base<T extends Codec> implements Codec {
readonly #raw: T;
protected constructor (registry: CodecRegistry, value: T, initialU8aLength?: number) {
protected constructor (registry: Registry, value: T, initialU8aLength?: number) {
this.#registry = registry;
this.#raw = value;
this.initialU8aLength = initialU8aLength;
@@ -48,7 +48,7 @@ export abstract class Base<T extends Codec> implements Codec {
return this.#raw.isEmpty;
}
public get registry (): CodecRegistry {
public get registry (): Registry {
return this.#registry;
}
+5 -5
View File
@@ -3,7 +3,7 @@
import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, AnyNumber, CodecClass, CodecRegistry, ICompact, INumber, IU8a } from '../types';
import type { AnyJson, AnyNumber, CodecClass, ICompact, INumber, IU8a, Registry } from '../types';
import { compactFromU8a, compactToU8a, isBigInt, isBn, isNumber, isString } from '@polkadot/util';
@@ -18,7 +18,7 @@ import { typeToConstructor } from '../utils';
* a number and making the compact representation thereof
*/
export class Compact<T extends INumber> implements ICompact<T> {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
@@ -28,7 +28,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
readonly #raw: T;
constructor (registry: CodecRegistry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0) {
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0) {
this.registry = registry;
this.#Type = typeToConstructor(registry, Type);
@@ -40,14 +40,14 @@ export class Compact<T extends INumber> implements ICompact<T> {
public static with<T extends INumber> (Type: CodecClass<T> | string): CodecClass<Compact<T>> {
return class extends Compact<T> {
constructor (registry: CodecRegistry, value?: Compact<T> | AnyNumber) {
constructor (registry: Registry, value?: Compact<T> | AnyNumber) {
super(registry, Type, value);
}
};
}
/** @internal */
public static decodeCompact<T extends INumber> (registry: CodecRegistry, Type: CodecClass<T>, value: Compact<T> | AnyNumber): [T, number] {
public static decodeCompact<T extends INumber> (registry: Registry, Type: CodecClass<T>, value: Compact<T> | AnyNumber): [T, number] {
if (value instanceof Compact) {
return [new Type(registry, value.#raw), 0];
} else if (value instanceof Type) {
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, CodecRegistry, IU8a } from '../types';
import type { AnyJson, Codec, CodecClass, IU8a, Registry } from '../types';
/**
* @name DoNotConstruct
@@ -10,13 +10,13 @@ import type { AnyJson, Codec, CodecClass, CodecRegistry, IU8a } from '../types';
* An unknown type that fails on construction with the type info
*/
export class DoNotConstruct implements Codec {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
#neverError: Error;
constructor (registry: CodecRegistry, typeName = 'DoNotConstruct') {
constructor (registry: Registry, typeName = 'DoNotConstruct') {
this.registry = registry;
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
@@ -25,7 +25,7 @@ export class DoNotConstruct implements Codec {
public static with (typeName?: string): CodecClass {
return class extends DoNotConstruct {
constructor (registry: CodecRegistry) {
constructor (registry: Registry) {
super(registry, typeName);
}
};
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import { TypeRegistry } from '@polkadot/types';
import { Enum, Null, Text, U32 } from '@polkadot/types-codec';
@@ -129,7 +129,7 @@ describe('Enum', (): void => {
class B extends Null { }
class C extends Null { }
class Test extends Enum {
constructor (registry: CodecRegistry, value?: string, index?: number) {
constructor (registry: Registry, value?: string, index?: number) {
super(registry, {
a: A,
b: B,
+9 -9
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, CodecRegistry, IEnum, IU8a } from '../types';
import type { AnyJson, Codec, CodecClass, IEnum, IU8a, Registry } from '../types';
import { assert, isHex, isNumber, isObject, isString, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
@@ -11,7 +11,7 @@ import { Null } from './Null';
// export interface, this is used in Enum.with, so required as public by TS
export interface EnumCodecClass<T = Codec> {
new(registry: CodecRegistry, value?: any, index?: number): T;
new(registry: Registry, value?: any, index?: number): T;
}
interface EntryDef {
@@ -38,7 +38,7 @@ function isRustEnum (def: Record<string, string | CodecClass> | Record<string, n
return true;
}
function extractDef (registry: CodecRegistry, _def: Record<string, string | CodecClass> | Record<string, number> | string[]): { def: TypesDef; isBasic: boolean; isIndexed: boolean } {
function extractDef (registry: Registry, _def: Record<string, string | CodecClass> | Record<string, number> | string[]): { def: TypesDef; isBasic: boolean; isIndexed: boolean } {
const def: TypesDef = {};
let isBasic: boolean;
let isIndexed: boolean;
@@ -81,7 +81,7 @@ function extractDef (registry: CodecRegistry, _def: Record<string, string | Code
};
}
function createFromValue (registry: CodecRegistry, def: TypesDef, index = 0, value?: unknown): Decoded {
function createFromValue (registry: Registry, def: TypesDef, index = 0, value?: unknown): Decoded {
const entry = Object.values(def).find((e) => e.index === index);
assert(!isUndefined(entry), () => `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
@@ -94,7 +94,7 @@ function createFromValue (registry: CodecRegistry, def: TypesDef, index = 0, val
};
}
function decodeFromJSON (registry: CodecRegistry, def: TypesDef, key: string, value?: unknown): Decoded {
function decodeFromJSON (registry: Registry, def: TypesDef, key: string, value?: unknown): Decoded {
// JSON comes in the form of { "<type (camelCase)>": "<value for type>" }, here we
// additionally force to lower to ensure forward compat
const keys = Object.keys(def).map((k) => k.toLowerCase());
@@ -110,7 +110,7 @@ function decodeFromJSON (registry: CodecRegistry, def: TypesDef, key: string, va
}
}
function decodeEnum (registry: CodecRegistry, def: TypesDef, value?: unknown, index?: number): Decoded {
function decodeEnum (registry: Registry, def: TypesDef, value?: unknown, index?: number): Decoded {
// NOTE We check the index path first, before looking at values - this allows treating
// the optional indexes before anything else, more-specific > less-specific
if (isNumber(index)) {
@@ -145,7 +145,7 @@ function decodeEnum (registry: CodecRegistry, def: TypesDef, value?: unknown, in
* an extension to enum where the value type is determined by the actual index.
*/
export class Enum implements IEnum {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
@@ -163,7 +163,7 @@ export class Enum implements IEnum {
readonly #raw: Codec;
constructor (registry: CodecRegistry, Types: Record<string, string | CodecClass> | Record<string, number> | string[], value?: unknown, index?: number) {
constructor (registry: Registry, Types: Record<string, string | CodecClass> | Record<string, number> | string[], value?: unknown, index?: number) {
const { def, isBasic, isIndexed } = extractDef(registry, Types);
// shortcut isU8a as used in SCALE decoding
@@ -199,7 +199,7 @@ export class Enum implements IEnum {
}
return class extends Enum {
constructor (registry: CodecRegistry, value?: unknown, index?: number) {
constructor (registry: Registry, value?: unknown, index?: number) {
super(registry, Types, value, index);
objectProperties(this, isKeys, (_, i) => this.type === keys[i]);
+3 -3
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyNumber, CodecClass, CodecRegistry, UIntBitLength } from '../types';
import type { AnyNumber, CodecClass, Registry, UIntBitLength } from '../types';
import { AbstractInt } from '../abstract/AbstractInt';
@@ -16,13 +16,13 @@ import { AbstractInt } from '../abstract/AbstractInt';
* @noInheritDoc
*/
export class Int extends AbstractInt {
constructor (registry: CodecRegistry, value: AnyNumber = 0, bitLength?: UIntBitLength) {
constructor (registry: Registry, value: AnyNumber = 0, bitLength?: UIntBitLength) {
super(registry, value, bitLength, true);
}
public static with (bitLength: UIntBitLength, typeName?: string): CodecClass<Int> {
return class extends Int {
constructor (registry: CodecRegistry, value?: AnyNumber) {
constructor (registry: Registry, value?: AnyNumber) {
super(registry, value, bitLength);
}
+3 -3
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { Codec, CodecRegistry, IU8a } from '../types';
import type { Codec, IU8a, Registry } from '../types';
import { isNull } from '@polkadot/util';
@@ -12,14 +12,14 @@ import { isNull } from '@polkadot/util';
* Implements a type that does not contain anything (apart from `null`)
*/
export class Null implements Codec {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
// Added for compatibility reasons, e.g. see Option
public readonly initialU8aLength = 0;
constructor (registry: CodecRegistry) {
constructor (registry: Registry) {
this.registry = registry;
}
+5 -5
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, CodecRegistry, IOption, IU8a } from '../types';
import type { AnyJson, Codec, CodecClass, IOption, IU8a, Registry } from '../types';
import { assert, isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
@@ -10,7 +10,7 @@ import { typeToConstructor } from '../utils';
import { Null } from './Null';
/** @internal */
function decodeOption (registry: CodecRegistry, Type: CodecClass, value?: unknown): Codec {
function decodeOption (registry: Registry, Type: CodecClass, value?: unknown): Codec {
// In the case of an option, unwrap the inner
if (value instanceof Option) {
value = value.value;
@@ -41,7 +41,7 @@ function decodeOption (registry: CodecRegistry, Type: CodecClass, value?: unknow
* with a value if/as required/found.
*/
export class Option<T extends Codec> implements IOption<T> {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
@@ -51,7 +51,7 @@ export class Option<T extends Codec> implements IOption<T> {
readonly #raw: T;
constructor (registry: CodecRegistry, typeName: CodecClass<T> | string, value?: unknown) {
constructor (registry: Registry, typeName: CodecClass<T> | string, value?: unknown) {
const Type = typeToConstructor(registry, typeName);
const decoded = isU8a(value) && value.length && !isCodec(value)
? value[0] === 0
@@ -70,7 +70,7 @@ export class Option<T extends Codec> implements IOption<T> {
public static with<O extends Codec> (Type: CodecClass<O> | string): CodecClass<Option<O>> {
return class extends Option<O> {
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
super(registry, Type, value);
}
};
+3 -3
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry, IResult } from '../types';
import type { Codec, CodecClass, IResult, Registry } from '../types';
import { assert } from '@polkadot/util';
@@ -13,7 +13,7 @@ import { Enum } from './Enum';
* A Result maps to the Rust Result type, that can either wrap a success or error value
*/
export class Result<O extends Codec, E extends Codec> extends Enum implements IResult<O, E> {
constructor (registry: CodecRegistry, Ok: CodecClass<O> | string, Err: CodecClass<E> | string, value?: unknown) {
constructor (registry: Registry, Ok: CodecClass<O> | string, Err: CodecClass<E> | string, value?: unknown) {
// NOTE This is order-dependent, Ok (with index 0) needs to be first
// eslint-disable-next-line sort-keys
super(registry, { Ok, Err }, value);
@@ -21,7 +21,7 @@ export class Result<O extends Codec, E extends Codec> extends Enum implements IR
public static override with<O extends Codec, E extends Codec> (Types: { Ok: CodecClass<O> | string; Err: CodecClass<E> | string }): CodecClass<Result<O, E>> {
return class extends Result<O, E> {
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
super(registry, Types.Ok, Types.Err, value);
}
};
+4 -4
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyTupleValue, Codec, CodecClass, CodecRegistry, ITuple } from '../types';
import type { AnyTupleValue, Codec, CodecClass, ITuple, Registry } from '../types';
import { isFunction, isHex, isString, isU8a, stringify, u8aConcat, u8aToU8a } from '@polkadot/util';
@@ -19,7 +19,7 @@ type TupleTypes = TupleType[] | {
};
/** @internal */
function decodeTuple (registry: CodecRegistry, Classes: TupleCodecClasss, value?: AnyTupleValue): [Codec[], number] {
function decodeTuple (registry: Registry, Classes: TupleCodecClasss, value?: AnyTupleValue): [Codec[], number] {
if (isU8a(value) || isHex(value)) {
return decodeU8a(registry, u8aToU8a(value), Classes);
}
@@ -55,7 +55,7 @@ function decodeTuple (registry: CodecRegistry, Classes: TupleCodecClasss, value?
export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
#Types: TupleCodecClasss;
constructor (registry: CodecRegistry, Types: TupleTypes | TupleType, value?: AnyTupleValue) {
constructor (registry: Registry, Types: TupleTypes | TupleType, value?: AnyTupleValue) {
const Classes = Array.isArray(Types)
? Types.map((t) => typeToConstructor(registry, t))
: isFunction(Types) || isString(Types)
@@ -72,7 +72,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
public static with (Types: TupleTypes | TupleType): CodecClass<Tuple> {
return class extends Tuple {
constructor (registry: CodecRegistry, value?: AnyTupleValue) {
constructor (registry: Registry, value?: AnyTupleValue) {
super(registry, Types, value);
}
};
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyNumber, CodecClass, CodecRegistry, UIntBitLength } from '../types';
import type { AnyNumber, CodecClass, Registry, UIntBitLength } from '../types';
import { AbstractInt } from '../abstract/AbstractInt';
@@ -18,7 +18,7 @@ import { AbstractInt } from '../abstract/AbstractInt';
export class UInt extends AbstractInt {
public static with (bitLength: UIntBitLength, typeName?: string): CodecClass<UInt> {
return class extends UInt {
constructor (registry: CodecRegistry, value?: AnyNumber) {
constructor (registry: Registry, value?: AnyNumber) {
super(registry, value, bitLength);
}
+4 -4
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { Codec, CodecClass, CodecRegistry } from '../types';
import type { Codec, CodecClass, Registry } from '../types';
import { assert, compactFromU8a, logger, u8aToU8a } from '@polkadot/util';
@@ -13,7 +13,7 @@ const MAX_LENGTH = 64 * 1024;
const l = logger('Vec');
export function decodeVec<T extends Codec> (registry: CodecRegistry, Type: CodecClass<T>, value: Uint8Array | HexString | unknown[], length = -1): [T[], number, number] {
export function decodeVec<T extends Codec> (registry: Registry, Type: CodecClass<T>, value: Uint8Array | HexString | unknown[], length = -1): [T[], number, number] {
if (Array.isArray(value)) {
const result = new Array<T>(value.length);
@@ -59,7 +59,7 @@ export function decodeVec<T extends Codec> (registry: CodecRegistry, Type: Codec
export class Vec<T extends Codec> extends AbstractArray<T> {
#Type: CodecClass<T>;
constructor (registry: CodecRegistry, Type: CodecClass<T> | string, value: Uint8Array | HexString | unknown[] = []) {
constructor (registry: Registry, Type: CodecClass<T> | string, value: Uint8Array | HexString | unknown[] = []) {
const Clazz = typeToConstructor<T>(registry, Type);
const [values, decodedLength] = decodeVec(registry, Clazz, value);
@@ -70,7 +70,7 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
public static with<O extends Codec> (Type: CodecClass<O> | string): CodecClass<Vec<O>> {
return class extends Vec<O> {
constructor (registry: CodecRegistry, value?: any[]) {
constructor (registry: Registry, value?: any[]) {
super(registry, Type, value);
}
};
+4 -4
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { Codec, CodecClass, CodecRegistry } from '../types';
import type { Codec, CodecClass, Registry } from '../types';
import { assert, isU8a, u8aConcat } from '@polkadot/util';
@@ -11,7 +11,7 @@ import { decodeU8aVec, typeToConstructor } from '../utils';
import { decodeVec } from './Vec';
/** @internal */
function decodeVecFixed<T extends Codec> (registry: CodecRegistry, value: Uint8Array | HexString | unknown[], Type: CodecClass<T>, length: number): [T[], number, number] {
function decodeVecFixed<T extends Codec> (registry: Registry, value: Uint8Array | HexString | unknown[], Type: CodecClass<T>, length: number): [T[], number, number] {
const [values, decodedLength, decodedLengthNoOffset] = decodeVec(registry, Type, value, length);
while (values.length < length) {
@@ -31,7 +31,7 @@ function decodeVecFixed<T extends Codec> (registry: CodecRegistry, value: Uint8A
export class VecFixed<T extends Codec> extends AbstractArray<T> {
#Type: CodecClass<T>;
constructor (registry: CodecRegistry, Type: CodecClass<T> | string, length: number, value: Uint8Array | HexString | unknown[] = [] as unknown[]) {
constructor (registry: Registry, Type: CodecClass<T> | string, length: number, value: Uint8Array | HexString | unknown[] = [] as unknown[]) {
const Clazz = typeToConstructor<T>(registry, Type);
const [values,, decodedLengthNoOffset] = isU8a(value)
? decodeU8aVec(registry, value, 0, Clazz, length)
@@ -44,7 +44,7 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
public static with<O extends Codec> (Type: CodecClass<O> | string, length: number): CodecClass<VecFixed<O>> {
return class extends VecFixed<O> {
constructor (registry: CodecRegistry, value?: any[]) {
constructor (registry: Registry, value?: any[]) {
super(registry, Type, length, value);
}
};
@@ -1,14 +1,14 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry } from '../types';
import type { Codec, CodecClass, Registry } from '../types';
import { CodecMap } from './Map';
export class BTreeMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
public static with<K extends Codec, V extends Codec> (keyType: CodecClass<K> | string, valType: CodecClass<V> | string): CodecClass<CodecMap<K, V>> {
return class extends BTreeMap<K, V> {
constructor (registry: CodecRegistry, value?: Uint8Array | string | Map<any, any>) {
constructor (registry: Registry, value?: Uint8Array | string | Map<any, any>) {
super(registry, keyType, valType, value, 'BTreeMap');
}
};
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, CodecRegistry, ISet, IU8a } from '../types';
import type { AnyJson, Codec, CodecClass, ISet, IU8a, Registry } from '../types';
import { compactFromU8a, compactToU8a, isHex, isU8a, logger, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
@@ -11,7 +11,7 @@ import { compareSet, decodeU8aVec, sortSet, typeToConstructor } from '../utils';
const l = logger('BTreeSet');
/** @internal */
function decodeSetFromU8a<V extends Codec> (registry: CodecRegistry, ValClass: CodecClass<V>, u8a: Uint8Array): [Set<V>, number] {
function decodeSetFromU8a<V extends Codec> (registry: Registry, ValClass: CodecClass<V>, u8a: Uint8Array): [Set<V>, number] {
const output = new Set<V>();
const [offset, length] = compactFromU8a(u8a);
const [values, decodedLength] = decodeU8aVec(registry, u8a, offset, ValClass, length.toNumber());
@@ -24,7 +24,7 @@ function decodeSetFromU8a<V extends Codec> (registry: CodecRegistry, ValClass: C
}
/** @internal */
function decodeSetFromSet<V extends Codec> (registry: CodecRegistry, ValClass: CodecClass<V>, value: Set<any> | string[]): [Set<V>, number] {
function decodeSetFromSet<V extends Codec> (registry: Registry, ValClass: CodecClass<V>, value: Set<any> | string[]): [Set<V>, number] {
const output = new Set<V>();
value.forEach((val: any) => {
@@ -54,7 +54,7 @@ function decodeSetFromSet<V extends Codec> (registry: CodecRegistry, ValClass: C
* @param jsonSet
* @internal
*/
function decodeSet<V extends Codec> (registry: CodecRegistry, valType: CodecClass<V> | string, value?: Uint8Array | string | string[] | Set<any>): [Set<V>, number] {
function decodeSet<V extends Codec> (registry: Registry, valType: CodecClass<V> | string, value?: Uint8Array | string | string[] | Set<any>): [Set<V>, number] {
if (!value) {
return [new Set<V>(), 0];
}
@@ -71,7 +71,7 @@ function decodeSet<V extends Codec> (registry: CodecRegistry, valType: CodecClas
}
export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V> {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
@@ -79,7 +79,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
readonly #ValClass: CodecClass<V>;
constructor (registry: CodecRegistry, valType: CodecClass<V> | string, rawValue?: Uint8Array | string | string[] | Set<any>) {
constructor (registry: Registry, valType: CodecClass<V> | string, rawValue?: Uint8Array | string | string[] | Set<any>) {
const [values, decodedLength] = decodeSet(registry, valType, rawValue);
super(sortSet(values));
@@ -91,7 +91,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
public static with<V extends Codec> (valType: CodecClass<V> | string): CodecClass<BTreeSet<V>> {
return class extends BTreeSet<V> {
constructor (registry: CodecRegistry, value?: Uint8Array | string | Set<any>) {
constructor (registry: Registry, value?: Uint8Array | string | Set<any>) {
super(registry, valType, value);
}
};
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyU8a, CodecRegistry } from '../types';
import type { AnyU8a, Registry } from '../types';
import { assert, compactFromU8a, compactToU8a, isString, u8aConcat, u8aToU8a } from '@polkadot/util';
@@ -42,7 +42,7 @@ function decodeBitVec (value?: AnyU8a): [number, Uint8Array] {
export class BitVec extends Raw {
readonly #decodedLength: number;
constructor (registry: CodecRegistry, value?: AnyU8a) {
constructor (registry: Registry, value?: AnyU8a) {
const [decodedLength, u8a] = decodeBitVec(value);
super(registry, u8a);
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyU8a, CodecRegistry } from '../types';
import type { AnyU8a, Registry } from '../types';
import { assert, compactAddLength, compactFromU8a, compactToU8a, isString, isU8a, u8aToU8a } from '@polkadot/util';
@@ -47,7 +47,7 @@ function decodeBytes (value?: AnyU8a): [Uint8Array | undefined, number] {
* as what is found in [[Text]] and [[Vec]])
*/
export class Bytes extends Raw {
constructor (registry: CodecRegistry, value?: AnyU8a) {
constructor (registry: Registry, value?: AnyU8a) {
const [u8a, decodedLength] = decodeBytes(value);
super(registry, u8a, decodedLength);
+2 -2
View File
@@ -1,14 +1,14 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry } from '../types';
import type { Codec, CodecClass, Registry } from '../types';
import { CodecMap } from './Map';
export class HashMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
public static with<K extends Codec, V extends Codec> (keyType: CodecClass<K> | string, valType: CodecClass<V> | string): CodecClass<CodecMap<K, V>> {
return class extends HashMap<K, V> {
constructor (registry: CodecRegistry, value?: Uint8Array | string | Map<any, any>) {
constructor (registry: Registry, value?: Uint8Array | string | Map<any, any>) {
super(registry, keyType, valType, value);
}
};
+4 -4
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { Codec, CodecClass, CodecRegistry } from '../types';
import type { Codec, CodecClass, Registry } from '../types';
import { Option } from '../base/Option';
import { Tuple } from '../base/Tuple';
@@ -18,7 +18,7 @@ const EMPTY = new Uint8Array();
* @description The wrapper for the result from a LinkedMap
*/
export class Linkage<T extends Codec> extends Struct {
constructor (registry: CodecRegistry, Type: CodecClass | string, value?: unknown) {
constructor (registry: Registry, Type: CodecClass | string, value?: unknown) {
super(registry, {
previous: Option.with(Type),
// eslint-disable-next-line sort-keys
@@ -28,7 +28,7 @@ export class Linkage<T extends Codec> extends Struct {
public static withKey<O extends Codec> (Type: CodecClass | string): CodecClass<Linkage<O>> {
return class extends Linkage<O> {
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
super(registry, Type, value);
}
};
@@ -66,7 +66,7 @@ export class Linkage<T extends Codec> extends Struct {
* @description A Linkage keys/Values tuple
*/
export class LinkageResult extends Tuple {
constructor (registry: CodecRegistry, [TypeKey, keys]: TypeWithValues, [TypeValue, values]: TypeWithValues) {
constructor (registry: Registry, [TypeKey, keys]: TypeWithValues, [TypeValue, values]: TypeWithValues) {
super(registry, {
Keys: Vec.with(TypeKey),
Values: Vec.with(TypeValue)
+6 -6
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, CodecRegistry, IMap, IU8a } from '../types';
import type { AnyJson, Codec, CodecClass, IMap, IU8a, Registry } from '../types';
import { compactFromU8a, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
@@ -14,7 +14,7 @@ import { compareMap, decodeU8a, sortMap, typeToConstructor } from '../utils';
const l = logger('Map');
/** @internal */
function decodeMapFromU8a<K extends Codec, V extends Codec> (registry: CodecRegistry, KeyClass: CodecClass<K>, ValClass: CodecClass<V>, u8a: Uint8Array): [Map<K, V>, number] {
function decodeMapFromU8a<K extends Codec, V extends Codec> (registry: Registry, KeyClass: CodecClass<K>, ValClass: CodecClass<V>, u8a: Uint8Array): [Map<K, V>, number] {
const output = new Map<K, V>();
const [offset, length] = compactFromU8a(u8a);
const count = length.toNumber();
@@ -34,7 +34,7 @@ function decodeMapFromU8a<K extends Codec, V extends Codec> (registry: CodecRegi
}
/** @internal */
function decodeMapFromMap<K extends Codec, V extends Codec> (registry: CodecRegistry, KeyClass: CodecClass<K>, ValClass: CodecClass<V>, value: Map<any, any>): [Map<K, V>, number] {
function decodeMapFromMap<K extends Codec, V extends Codec> (registry: Registry, KeyClass: CodecClass<K>, ValClass: CodecClass<V>, value: Map<any, any>): [Map<K, V>, number] {
const output = new Map<K, V>();
for (const [key, val] of value.entries()) {
@@ -76,7 +76,7 @@ function decodeMapFromMap<K extends Codec, V extends Codec> (registry: CodecRegi
* @param jsonMap
* @internal
*/
function decodeMap<K extends Codec, V extends Codec> (registry: CodecRegistry, keyType: CodecClass<K> | string, valType: CodecClass<V> | string, value?: Uint8Array | string | Map<any, any>): [Map<K, V>, number] {
function decodeMap<K extends Codec, V extends Codec> (registry: Registry, keyType: CodecClass<K> | string, valType: CodecClass<V> | string, value?: Uint8Array | string | Map<any, any>): [Map<K, V>, number] {
const KeyClass = typeToConstructor(registry, keyType);
const ValClass = typeToConstructor(registry, valType);
@@ -94,7 +94,7 @@ function decodeMap<K extends Codec, V extends Codec> (registry: CodecRegistry, k
}
export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V> implements IMap<K, V> {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
@@ -106,7 +106,7 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
readonly #type: string;
constructor (registry: CodecRegistry, keyType: CodecClass<K> | string, valType: CodecClass<V> | string, rawValue: Uint8Array | string | Map<any, any> | undefined, type: 'BTreeMap' | 'HashMap' = 'HashMap') {
constructor (registry: Registry, keyType: CodecClass<K> | string, valType: CodecClass<V> | string, rawValue: Uint8Array | string | Map<any, any> | undefined, type: 'BTreeMap' | 'HashMap' = 'HashMap') {
const [decoded, decodedLength] = decodeMap(registry, keyType, valType, rawValue);
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
+5 -5
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyTuple, CodecClass, CodecRegistry, INumber } from '../types';
import type { AnyTuple, CodecClass, INumber, Registry } from '../types';
import { Tuple } from '../base/Tuple';
@@ -15,7 +15,7 @@ type RangeType = 'Range' | 'RangeInclusive';
export class Range<T extends INumber> extends Tuple {
#rangeName: RangeType;
constructor (registry: CodecRegistry, Type: CodecClass<T> | string, value?: AnyTuple, rangeName: RangeType = 'Range') {
constructor (registry: Registry, Type: CodecClass<T> | string, value?: AnyTuple, rangeName: RangeType = 'Range') {
super(registry, {
end: Type,
start: Type
@@ -26,7 +26,7 @@ export class Range<T extends INumber> extends Tuple {
public static override with <T extends INumber> (Types: CodecClass<T> | string): CodecClass<Range<T>> {
return class extends Range<T> {
constructor (registry: CodecRegistry, value?: AnyTuple) {
constructor (registry: Registry, value?: AnyTuple) {
super(registry, Types, value);
}
};
@@ -55,13 +55,13 @@ export class Range<T extends INumber> extends Tuple {
}
export class RangeInclusive<T extends INumber = INumber> extends Range<T> {
constructor (registry: CodecRegistry, Type: CodecClass<T> | string, value?: AnyTuple) {
constructor (registry: Registry, Type: CodecClass<T> | string, value?: AnyTuple) {
super(registry, Type, value, 'RangeInclusive');
}
public static override with <T extends INumber> (Type: CodecClass<T> | string): CodecClass<RangeInclusive<T>> {
return class extends RangeInclusive<T> {
constructor (registry: CodecRegistry, value?: AnyTuple) {
constructor (registry: Registry, value?: AnyTuple) {
super(registry, Type, value);
}
};
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '../types';
import type { Registry } from '../types';
import { Text } from '../native/Text';
import { sanitize } from '../utils';
@@ -14,7 +14,7 @@ import { sanitize } from '../utils';
* i.e. we remove the `T::` prefixes found in some types for consistency across implementation.
*/
export class Type extends Text {
constructor (registry: CodecRegistry, value: Text | Uint8Array | string = '') {
constructor (registry: Registry, value: Text | Uint8Array | string = '') {
super(registry, value);
this.setOverride(sanitize(this.toString()));
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyU8a, CodecClass, CodecRegistry, U8aBitLength } from '../types';
import type { AnyU8a, CodecClass, Registry, U8aBitLength } from '../types';
import { assert, u8aToU8a } from '@polkadot/util';
@@ -28,7 +28,7 @@ function decodeU8aFixed (value: AnyU8a, bitLength: U8aBitLength): [AnyU8a, numbe
* to be used directly, rather is should be subclassed with the specific lengths.
*/
export class U8aFixed extends Raw {
constructor (registry: CodecRegistry, value: AnyU8a = new Uint8Array(), bitLength: U8aBitLength = 256) {
constructor (registry: Registry, value: AnyU8a = new Uint8Array(), bitLength: U8aBitLength = 256) {
const [u8a, decodedLength] = decodeU8aFixed(value, bitLength);
super(registry, u8a, decodedLength);
@@ -36,7 +36,7 @@ export class U8aFixed extends Raw {
public static with (bitLength: U8aBitLength, typeName?: string): CodecClass<U8aFixed> {
return class extends U8aFixed {
constructor (registry: CodecRegistry, value?: AnyU8a) {
constructor (registry: Registry, value?: AnyU8a) {
super(registry, value, bitLength);
}
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyJson, AnyU8a, Codec, CodecClass, CodecRegistry } from '../types';
import type { AnyJson, AnyU8a, Codec, CodecClass, Registry } from '../types';
import { assertReturn, compactStripLength, isHex, isU8a } from '@polkadot/util';
@@ -9,7 +9,7 @@ import { Raw } from '../native/Raw';
import { typeToConstructor } from '../utils';
import { Bytes } from './Bytes';
function decodeRaw<T extends Codec> (registry: CodecRegistry, typeName: CodecClass<T> | string, value?: AnyU8a | Codec): [CodecClass<T>, T | null, AnyU8a] {
function decodeRaw<T extends Codec> (registry: Registry, typeName: CodecClass<T> | string, value?: AnyU8a | Codec): [CodecClass<T>, T | null, AnyU8a] {
const Type = typeToConstructor(registry, typeName);
if (isU8a(value) || isHex(value)) {
@@ -34,7 +34,7 @@ export class WrapperKeepOpaque<T extends Codec> extends Bytes {
readonly #decoded: T | null;
constructor (registry: CodecRegistry, typeName: CodecClass<T> | string, value?: AnyU8a | Codec) {
constructor (registry: Registry, typeName: CodecClass<T> | string, value?: AnyU8a | Codec) {
const [Type, decoded, u8a] = decodeRaw(registry, typeName, value);
super(registry, u8a);
@@ -45,7 +45,7 @@ export class WrapperKeepOpaque<T extends Codec> extends Bytes {
public static with<T extends Codec> (Type: CodecClass<T> | string): CodecClass<WrapperKeepOpaque<T>> {
return class extends WrapperKeepOpaque<T> {
constructor (registry: CodecRegistry, value?: AnyU8a | T) {
constructor (registry: Registry, value?: AnyU8a | T) {
super(registry, Type, value);
}
};
@@ -1,14 +1,14 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry } from '../types';
import type { Codec, CodecClass, Registry } from '../types';
import { compactAddLength, compactStripLength, isU8a } from '@polkadot/util';
import { Base } from '../base/Base';
import { typeToConstructor } from '../utils';
function decodeRaw<T extends Codec> (registry: CodecRegistry, Type: CodecClass<T> | string, value?: unknown): T {
function decodeRaw<T extends Codec> (registry: Registry, Type: CodecClass<T> | string, value?: unknown): T {
const Clazz = typeToConstructor<T>(registry, Type);
if (isU8a(value)) {
@@ -21,13 +21,13 @@ function decodeRaw<T extends Codec> (registry: CodecRegistry, Type: CodecClass<T
}
export class WrapperOpaque<T extends Codec> extends Base<T> {
constructor (registry: CodecRegistry, Type: CodecClass<T> | string, value?: unknown) {
constructor (registry: Registry, Type: CodecClass<T> | string, value?: unknown) {
super(registry, decodeRaw(registry, Type, value));
}
public static with<T extends Codec> (Type: CodecClass<T> | string): CodecClass<WrapperOpaque<T>> {
return class extends WrapperOpaque<T> {
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
super(registry, Type, value);
}
};
+3 -3
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { Codec, CodecRegistry, IU8a } from '../types';
import type { Codec, IU8a, Registry } from '../types';
import { isU8a, u8aToHex } from '@polkadot/util';
@@ -24,12 +24,12 @@ function decodeBool (value: any): boolean {
* @noInheritDoc
*/
export class bool extends Boolean implements Codec {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
// eslint-disable-next-line @typescript-eslint/ban-types
constructor (registry: CodecRegistry, value: bool | Boolean | Uint8Array | boolean | number = false) {
constructor (registry: Registry, value: bool | Boolean | Uint8Array | boolean | number = false) {
super(decodeBool(value));
this.registry = registry;
+3 -3
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyNumber, CodecRegistry, INumber, IU8a, UIntBitLength } from '../types';
import type { AnyNumber, INumber, IU8a, Registry, UIntBitLength } from '../types';
import { BN, bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util';
@@ -33,11 +33,11 @@ function decodeDate (value: CodecDate | Date | AnyNumber): Date {
* @noInheritDoc
*/
export class CodecDate extends Date implements INumber {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
constructor (registry: CodecRegistry, value: CodecDate | Date | AnyNumber = 0) {
constructor (registry: Registry, value: CodecDate | Date | AnyNumber = 0) {
super(decodeDate(value));
this.registry = registry;
+3 -3
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecRegistry, IU8a } from '../types';
import type { AnyJson, Codec, IU8a, Registry } from '../types';
import { isFunction, objectProperties, stringify } from '@polkadot/util';
@@ -22,11 +22,11 @@ function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
* @noInheritDoc
*/
export class Json extends Map<string, any> implements Codec {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
constructor (registry: CodecRegistry, value?: Record<string, unknown> | null) {
constructor (registry: Registry, value?: Record<string, unknown> | null) {
const decoded = decodeJson(value);
super(decoded);
+3 -3
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, AnyU8a, CodecRegistry, IU8a } from '../types';
import type { AnyJson, AnyU8a, IU8a, Registry } from '../types';
import { assert, isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
@@ -16,13 +16,13 @@ import { assert, isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a }
* @noInheritDoc
*/
export class Raw extends Uint8Array implements IU8a {
readonly registry: CodecRegistry;
readonly registry: Registry;
public createdAtHash?: IU8a;
readonly initialU8aLength?: number;
constructor (registry: CodecRegistry, value?: AnyU8a, initialU8aLength?: number) {
constructor (registry: Registry, value?: AnyU8a, initialU8aLength?: number) {
super(u8aToU8a(value));
this.registry = registry;
+4 -4
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { CodecClass, CodecRegistry, ISet, IU8a } from '../types';
import type { CodecClass, ISet, IU8a, Registry } from '../types';
import { assert, BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
@@ -86,7 +86,7 @@ function decodeSet (setValues: SetValues, value: string[] | Set<string> | Uint8A
* a bitwise representation of the values.
*/
export class CodecSet extends Set<string> implements ISet<string> {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
@@ -94,7 +94,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
readonly #byteLength: number;
constructor (registry: CodecRegistry, setValues: SetValues, value?: string[] | Set<string> | Uint8Array | BN | number | string, bitLength = 8) {
constructor (registry: Registry, setValues: SetValues, value?: string[] | Set<string> | Uint8Array | BN | number | string, bitLength = 8) {
super(decodeSet(setValues, value, bitLength));
this.registry = registry;
@@ -111,7 +111,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
}
return class extends CodecSet {
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
super(registry, values, value as undefined, bitLength);
objectProperties(this, isKeys, (_, i) => this.strings.includes(keys[i]));
+6 -6
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, BareOpts, Codec, CodecClass, CodecClassDef, CodecRegistry, IStruct, IU8a } from '../types';
import type { AnyJson, BareOpts, Codec, CodecClass, CodecClassDef, IStruct, IU8a, Registry } from '../types';
import { assert, isBoolean, isFunction, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
@@ -11,7 +11,7 @@ import { compareMap, decodeU8a, mapToTypeMap, typesToMap } from '../utils';
type TypesDef<T = Codec> = Record<string, string | CodecClass<T>>;
/** @internal */
function decodeStructFromObject (registry: CodecRegistry, Types: CodecClassDef, value: any, jsonMap: Map<string, string>): [Iterable<[string, Codec]>, number] {
function decodeStructFromObject (registry: Registry, Types: CodecClassDef, value: any, jsonMap: Map<string, string>): [Iterable<[string, Codec]>, number] {
let jsonObj: Record<string, unknown> | undefined;
const inputKeys = Object.keys(Types);
const typeofArray = Array.isArray(value);
@@ -90,7 +90,7 @@ export class Struct<
V extends { [K in keyof S]: any } = { [K in keyof S]: any },
// type names, mapped by key, name of Class in S
E extends { [K in keyof S]: string } = { [K in keyof S]: string }> extends Map<keyof S, Codec> implements IStruct<keyof S> {
#registry: CodecRegistry;
#registry: Registry;
public createdAtHash?: IU8a;
@@ -100,7 +100,7 @@ export class Struct<
readonly #Types: CodecClassDef;
constructor (registry: CodecRegistry, Types: S, value?: V | Map<unknown, unknown> | unknown[] | HexString | null, jsonMap = new Map<string, string>()) {
constructor (registry: Registry, Types: S, value?: V | Map<unknown, unknown> | unknown[] | HexString | null, jsonMap = new Map<string, string>()) {
const typeMap = mapToTypeMap(registry, Types);
const [decoded, decodedLength] = isU8a(value)
? decodeU8a<Codec, [string, Codec]>(registry, value, typeMap, true)
@@ -122,7 +122,7 @@ export class Struct<
const keys = Object.keys(Types);
return class extends Struct<S> {
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
super(registry, Types, value as HexString, jsonMap);
objectProperties(this, keys, (k) => this.get(k));
@@ -190,7 +190,7 @@ export class Struct<
return this.registry.hash(this.toU8a());
}
public get registry (): CodecRegistry {
public get registry (): Registry {
return this.#registry;
}
+3 -3
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyU8a, Codec, CodecRegistry, IU8a } from '../types';
import type { AnyU8a, Codec, IU8a, Registry } from '../types';
import { assert, compactAddLength, compactFromU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
@@ -48,7 +48,7 @@ function decodeText (value?: null | Text | string | AnyU8a | { toString: () => s
// TODO
// - Strings should probably be trimmed (docs do come through with extra padding)
export class Text extends String implements Codec {
public readonly registry: CodecRegistry;
public readonly registry: Registry;
public createdAtHash?: IU8a;
@@ -56,7 +56,7 @@ export class Text extends String implements Codec {
#override: string | null = null;
constructor (registry: CodecRegistry, value?: null | Text | string | AnyU8a | { toString: () => string }) {
constructor (registry: Registry, value?: null | Text | string | AnyU8a | { toString: () => string }) {
const [str, decodedLength] = decodeText(value);
super(str);
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '../types';
import type { Registry } from '../types';
import { u32 } from './U32';
@@ -13,7 +13,7 @@ import { u32 } from './U32';
* It is not to be used, since it created consensus mismatches.
*/
export class usize extends u32 {
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
super(registry, value);
throw new Error('The `usize` type should not be used. Since it is platform-specific, it creates incompatibilities between native (generally u64) and WASM (always u32) code. Use one of the `u32` or `u64` types explicitly.');
+3 -3
View File
@@ -4,7 +4,7 @@
import type { HexString } from '@polkadot/util/types';
import type { AnyJson } from './helpers';
import type { IU8a } from './interfaces';
import type { CodecRegistry } from './registry';
import type { Registry } from './registry';
export type BareOpts = boolean | Record<string, boolean>;
@@ -39,7 +39,7 @@ export interface Codec {
/**
* @description The registry associated with this object
*/
readonly registry: CodecRegistry;
readonly registry: Registry;
/**
* @description The block at which this value was retrieved/created (set to non-empty when retrieved from storage)
@@ -91,7 +91,7 @@ export interface CodecClass<T = Codec> {
// NOTE: We need the any[] here, unknown[] does not work as expected
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new(registry: CodecRegistry, ...args: any[]): T;
new(registry: Registry, ...args: any[]): T;
}
export type CodecClassDef<T = Codec> = Record<string, CodecClass<T>>;
+4 -4
View File
@@ -47,12 +47,12 @@ export interface CallFunction<A extends AnyTuple = AnyTuple, M = any> extends Ca
(...args: any[]): IMethod<A, M>;
}
export interface CodecRegistry {
export interface Registry {
readonly chainDecimals: number[];
readonly chainSS58: number | undefined;
readonly chainTokens: string[];
// readonly knownTypes: RegisteredTypes;
// readonly lookup: PortableCodecRegistry;
// readonly lookup: PortableRegistry;
// readonly metadata: MetadataLatest;
// readonly unknownTypes: string[];
// readonly signedExtensions: string[];
@@ -88,13 +88,13 @@ export interface CodecRegistry {
hasDef (name: string): boolean;
hasType (name: string): boolean;
hash (data: Uint8Array): IU8a;
// init (): CodecRegistry;
// init (): Registry;
register (type: CodecClass | RegistryTypes): void;
register (name: string, type: CodecClass): void;
register (arg1: string | CodecClass | RegistryTypes, arg2?: CodecClass): void;
// setChainProperties (properties?: ChainProperties): void;
// setHasher (hasher?: IU8aer | null): void;
// setLookup (lookup: PortableCodecRegistry): void;
// setLookup (lookup: PortableRegistry): void;
setMetadata (metadata: unknown, signedExtensions?: string[], userExtensions?: unknown): void;
// setSignedExtensions (signedExtensions?: string[], userExtensions?: ExtDef): void;
}
+4 -4
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry } from '../types';
import type { Codec, CodecClass, Registry } from '../types';
import { u8aToHex } from '@polkadot/util';
@@ -9,7 +9,7 @@ function formatFailure (error: Error, type: string | null, u8a: Uint8Array, key?
return `decodeU8a: failed at ${u8aToHex(u8a)}…${key ? ` on ${key}` : ''}${type ? `: ${type}` : ''}:: ${error.message}`;
}
function getRawType (registry: CodecRegistry, Type: CodecClass): string | null {
function getRawType (registry: Registry, Type: CodecClass): string | null {
try {
return new Type(registry).toRawType();
} catch {
@@ -25,7 +25,7 @@ function getRawType (registry: CodecRegistry, Type: CodecClass): string | null {
* @param result - The result array (will be returned with values pushed)
* @param types - The array of CodecClass to decode the U8a against.
*/
export function decodeU8a <T extends Codec = Codec, E = T> (registry: CodecRegistry, u8a: Uint8Array, types: CodecClass[] | { [index: string]: CodecClass }, withZip?: boolean): [E[], number] {
export function decodeU8a <T extends Codec = Codec, E = T> (registry: Registry, u8a: Uint8Array, types: CodecClass[] | { [index: string]: CodecClass }, withZip?: boolean): [E[], number] {
const [Types, keys]: [CodecClass[], string[]] = Array.isArray(types)
? [types, []]
: [Object.values(types), Object.keys(types)];
@@ -56,7 +56,7 @@ export function decodeU8a <T extends Codec = Codec, E = T> (registry: CodecRegis
// Split from decodeU8a since this is specialized to 1 instance ... yes duplication, but
// since we have to do less checks (and these are intensive anyway), much faster
export function decodeU8aVec <T extends Codec = Codec> (registry: CodecRegistry, u8a: Uint8Array, start: number, Type: CodecClass<T>, count: number): [T[], number, number] {
export function decodeU8aVec <T extends Codec = Codec> (registry: Registry, u8a: Uint8Array, start: number, Type: CodecClass<T>, count: number): [T[], number, number] {
const result = new Array<T>(count);
let offset = start;
@@ -1,14 +1,14 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecClass, CodecRegistry } from '../types';
import type { CodecClass, Registry } from '../types';
import { typeToConstructor } from './typeToConstructor';
/**
* @description takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
*/
export function mapToTypeMap (registry: CodecRegistry, input: Record<string, string | CodecClass>): Record<string, CodecClass> {
export function mapToTypeMap (registry: Registry, input: Record<string, string | CodecClass>): Record<string, CodecClass> {
const entries = Object.entries(input);
const output: Record<string, CodecClass> = {};
@@ -1,11 +1,11 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry } from '../types';
import type { Codec, CodecClass, Registry } from '../types';
import { isString } from '@polkadot/util';
export function typeToConstructor <T extends Codec = Codec> (registry: CodecRegistry, type: string | CodecClass<T>): CodecClass<T> {
export function typeToConstructor <T extends Codec = Codec> (registry: Registry, type: string | CodecClass<T>): CodecClass<T> {
return (
isString(type)
? registry.createClassUnsafe(type)
+2 -2
View File
@@ -1,9 +1,9 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecClass, CodecRegistry } from '../types';
import type { CodecClass, Registry } from '../types';
export function typesToMap (registry: CodecRegistry, Types: Record<string, CodecClass>): Record<string, string> {
export function typesToMap (registry: Registry, Types: Record<string, CodecClass>): Record<string, string> {
const entries = Object.entries(Types);
const result: Record<string, string> = {};
+31 -31
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2022 @polkadot/types-create authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry, U8aBitLength, UIntBitLength } from '@polkadot/types-codec/types';
import type { CreateRegistry, TypeDef } from '../types';
import type { Codec, CodecClass, Registry, U8aBitLength, UIntBitLength } from '@polkadot/types-codec/types';
import type { TypeDef } from '../types';
import { BTreeMap, BTreeSet, Bytes, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Null, Option, Range, RangeInclusive, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed, WrapperKeepOpaque, WrapperOpaque } from '@polkadot/types-codec';
import { assert, isNumber, stringify } from '@polkadot/util';
@@ -63,20 +63,20 @@ function createWithSub (Clazz: { with: (t: string) => CodecClass<Codec> }, value
return Clazz.with(getSubType(value));
}
const infoMapping: Record<TypeDefInfo, (registry: CodecRegistry, value: TypeDef) => CodecClass<Codec>> = {
[TypeDefInfo.BTreeMap]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => CodecClass<Codec>> = {
[TypeDefInfo.BTreeMap]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
createHashMap(BTreeMap, value),
[TypeDefInfo.BTreeSet]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.BTreeSet]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
createWithSub(BTreeSet, value),
[TypeDefInfo.Compact]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.Compact]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
createWithSub(Compact, value),
[TypeDefInfo.DoNotConstruct]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.DoNotConstruct]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
DoNotConstruct.with(value.displayName || value.type),
[TypeDefInfo.Enum]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> => {
[TypeDefInfo.Enum]: (registry: Registry, value: TypeDef): CodecClass<Codec> => {
const subs = getSubDefArray(value);
return Enum.with(
@@ -90,14 +90,14 @@ const infoMapping: Record<TypeDefInfo, (registry: CodecRegistry, value: TypeDef)
);
},
[TypeDefInfo.HashMap]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.HashMap]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
createHashMap(HashMap, value),
[TypeDefInfo.Int]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.Int]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
createInt(Int, value),
// We have circular deps between Linkage & Struct
[TypeDefInfo.Linkage]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> => {
[TypeDefInfo.Linkage]: (registry: Registry, value: TypeDef): CodecClass<Codec> => {
const type = `Option<${getSubType(value)}>`;
// eslint-disable-next-line sort-keys
const Clazz = Struct.with({ previous: type, next: type } as any);
@@ -112,26 +112,26 @@ const infoMapping: Record<TypeDefInfo, (registry: CodecRegistry, value: TypeDef)
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[TypeDefInfo.Null]: (registry: CodecRegistry, _: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.Null]: (registry: Registry, _: TypeDef): CodecClass<Codec> =>
Null,
[TypeDefInfo.Option]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.Option]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
createWithSub(Option, value),
[TypeDefInfo.Plain]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.Plain]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
registry.getOrUnknown(value.type),
[TypeDefInfo.Range]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.Range]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
(value.type.includes('RangeInclusive') ? RangeInclusive : Range).with(getSubType(value)),
[TypeDefInfo.Result]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> => {
[TypeDefInfo.Result]: (registry: Registry, value: TypeDef): CodecClass<Codec> => {
const [Ok, Err] = getTypeClassArray(value);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
return Result.with({ Err, Ok });
},
[TypeDefInfo.Set]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.Set]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
CodecSet.with(
getSubDefArray(value).reduce<Record<string, number>>((result, { index, name }) => {
result[name as string] = index as number;
@@ -141,19 +141,19 @@ const infoMapping: Record<TypeDefInfo, (registry: CodecRegistry, value: TypeDef)
value.length
),
[TypeDefInfo.Si]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
getTypeClass(registry, (registry as CreateRegistry).lookup.getTypeDef(value.type)),
[TypeDefInfo.Si]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
getTypeClass(registry, registry.lookup.getTypeDef(value.type)),
[TypeDefInfo.Struct]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.Struct]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
Struct.with(getTypeClassMap(value), value.alias),
[TypeDefInfo.Tuple]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.Tuple]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
Tuple.with(getTypeClassArray(value)),
[TypeDefInfo.UInt]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.UInt]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
createInt(UInt, value),
[TypeDefInfo.Vec]: (registry: CodecRegistry, { sub }: TypeDef): CodecClass<Codec> => {
[TypeDefInfo.Vec]: (registry: Registry, { sub }: TypeDef): CodecClass<Codec> => {
assert(sub && !Array.isArray(sub), 'Expected type information for vector');
return (
@@ -163,7 +163,7 @@ const infoMapping: Record<TypeDefInfo, (registry: CodecRegistry, value: TypeDef)
);
},
[TypeDefInfo.VecFixed]: (registry: CodecRegistry, { displayName, length, sub }: TypeDef): CodecClass<Codec> => {
[TypeDefInfo.VecFixed]: (registry: Registry, { displayName, length, sub }: TypeDef): CodecClass<Codec> => {
assert(sub && isNumber(length) && !Array.isArray(sub), 'Expected length & type information for fixed vector');
return (
@@ -173,14 +173,14 @@ const infoMapping: Record<TypeDefInfo, (registry: CodecRegistry, value: TypeDef)
);
},
[TypeDefInfo.WrapperKeepOpaque]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.WrapperKeepOpaque]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
createWithSub(WrapperKeepOpaque, value),
[TypeDefInfo.WrapperOpaque]: (registry: CodecRegistry, value: TypeDef): CodecClass<Codec> =>
[TypeDefInfo.WrapperOpaque]: (registry: Registry, value: TypeDef): CodecClass<Codec> =>
createWithSub(WrapperOpaque, value)
};
export function constructTypeClass<T extends Codec = Codec> (registry: CodecRegistry, typeDef: TypeDef): CodecClass<T> {
export function constructTypeClass<T extends Codec = Codec> (registry: Registry, typeDef: TypeDef): CodecClass<T> {
try {
const Type = infoMapping[typeDef.info](registry, typeDef);
@@ -200,15 +200,15 @@ export function constructTypeClass<T extends Codec = Codec> (registry: CodecRegi
}
// Returns the type Class for construction
export function getTypeClass<T extends Codec = Codec> (registry: CodecRegistry, typeDef: TypeDef): CodecClass<T> {
return (registry as CreateRegistry).getUnsafe(typeDef.type, false, typeDef) as CodecClass<T>;
export function getTypeClass<T extends Codec = Codec> (registry: Registry, typeDef: TypeDef): CodecClass<T> {
return registry.getUnsafe(typeDef.type, false, typeDef) as CodecClass<T>;
}
export function createClassUnsafe<T extends Codec = Codec, K extends string = string> (registry: CodecRegistry, type: K): CodecClass<T> {
export function createClassUnsafe<T extends Codec = Codec, K extends string = string> (registry: Registry, type: K): CodecClass<T> {
return getTypeClass(
registry,
registry.isLookupType(type)
? (registry as CreateRegistry).lookup.getTypeDef(type)
? registry.lookup.getTypeDef(type)
: getTypeDef(type)
);
}
+4 -4
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-create authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry, IU8a } from '@polkadot/types-codec/types';
import type { Codec, CodecClass, IU8a, Registry } from '@polkadot/types-codec/types';
import type { CreateOptions } from '../types';
import { Bytes, Option } from '@polkadot/types-codec';
@@ -20,7 +20,7 @@ function checkInstance (created: Codec, matcher: Uint8Array): void {
(
// on a length-prefixed type, just check the actual length
['Bytes', 'Text', 'Type'].includes(rawType) &&
matcher.length === (created as Bytes).length
matcher.length === (created as unknown as Bytes).length
) ||
(
// when the created is empty and matcher is also empty, let it slide...
@@ -44,7 +44,7 @@ function checkPedantic (created: Codec, [value]: unknown[], isPedantic = false):
// Initializes a type with a value. This also checks for fallbacks and in the cases
// where isPedantic is specified (storage decoding), also check the format/structure
function initType<T extends Codec> (registry: CodecRegistry, Type: CodecClass, params: unknown[] = [], { blockHash, isOptional, isPedantic }: CreateOptions = {}): T {
function initType<T extends Codec> (registry: Registry, Type: CodecClass, params: unknown[] = [], { blockHash, isOptional, isPedantic }: CreateOptions = {}): T {
const created = new (isOptional ? Option.with(Type) : Type)(registry, ...params);
checkPedantic(created, params, isPedantic);
@@ -59,7 +59,7 @@ function initType<T extends Codec> (registry: CodecRegistry, Type: CodecClass, p
// An unsafe version of the `createType` below. It's unsafe because the `type`
// argument here can be any string, which, when it cannot parse, will yield a
// runtime error.
export function createTypeUnsafe<T extends Codec = Codec, K extends string = string> (registry: CodecRegistry, type: K, params: unknown[] = [], options: CreateOptions = {}): T {
export function createTypeUnsafe<T extends Codec = Codec, K extends string = string> (registry: Registry, type: K, params: unknown[] = [], options: CreateOptions = {}): T {
let Clazz: CodecClass | null = null;
let firstError: Error | null = null;
@@ -0,0 +1,16 @@
// Copyright 2017-2022 @polkadot/types-create authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, ICompact, INumber } from '@polkadot/types-codec/types';
import type { ILookup, TypeDef } from '@polkadot/types-create/types';
declare module '@polkadot/types-codec/types/registry' {
export interface Registry {
readonly lookup: ILookup;
createLookupType (lookupId: ICompact<INumber> | number): string;
setLookup (lookup: ILookup): void;
getUnsafe <T extends Codec = Codec, K extends string = string> (name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass<T> | undefined;
}
}
+9
View File
@@ -0,0 +1,9 @@
// Copyright 2017-2022 @polkadot/types-create authors & contributors
// SPDX-License-Identifier: Apache-2.0
import './augmentRegistry';
export type { CodecCreateOptions as CreateOptions } from '@polkadot/types-codec/types';
export * from './lookup';
export * from './types';
+14
View File
@@ -0,0 +1,14 @@
// Copyright 2017-2022 @polkadot/types-create authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ICompact, INumber } from '@polkadot/types-codec/types';
import type { TypeDef } from './types';
export interface ILookup {
getSiType (lookupId: ICompact<INumber> | string | number): {
def: {
asTuple: ICompact<INumber>[]
}
},
getTypeDef (lookupId: ICompact<INumber> | string | number): TypeDef;
}
@@ -1,10 +1,6 @@
// Copyright 2017-2022 @polkadot/types-create authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry, ICompact, INumber } from '@polkadot/types-codec/types';
export type { CodecCreateOptions as CreateOptions } from '@polkadot/types-codec/types';
export enum TypeDefInfo {
BTreeMap,
BTreeSet,
@@ -48,21 +44,3 @@ export interface TypeDef {
type: string;
typeName?: string;
}
export interface ILookup {
getSiType (lookupId: ICompact<INumber> | string | number): {
def: {
asTuple: ICompact<INumber>[]
}
},
getTypeDef (lookupId: ICompact<INumber> | string | number): TypeDef;
}
export interface CreateRegistry extends CodecRegistry {
lookup: ILookup;
createLookupType (lookupId: ICompact<INumber> | number): string;
setLookup (lookup: ILookup): void;
getUnsafe <T extends Codec = Codec, K extends string = string> (name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass<T> | undefined;
}
+29 -29
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types-create authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { TypeDef } from '@polkadot/types-create/types';
import { assert, isNumber, isUndefined, objectSpread, stringify } from '@polkadot/util';
@@ -20,7 +20,7 @@ export function paramsNotation <T> (outer: string, inner?: T | T[], transform: (
}`;
}
function encodeWithParams (registry: CodecRegistry, typeDef: TypeDef, outer: string): string {
function encodeWithParams (registry: Registry, typeDef: TypeDef, outer: string): string {
const { info, sub } = typeDef;
switch (info) {
@@ -41,7 +41,7 @@ function encodeWithParams (registry: CodecRegistry, typeDef: TypeDef, outer: str
throw new Error(`Unable to encode ${stringify(typeDef)} with params`);
}
function encodeSubTypes (registry: CodecRegistry, sub: TypeDef[], asEnum?: boolean, extra?: Record<string, unknown>): string {
function encodeSubTypes (registry: Registry, sub: TypeDef[], asEnum?: boolean, extra?: Record<string, unknown>): string {
const names = sub.map(({ name }) => name);
assert(names.every((n) => !!n), () => `Subtypes does not have consistent names, ${names.join(', ')}`);
@@ -63,16 +63,16 @@ function encodeSubTypes (registry: CodecRegistry, sub: TypeDef[], asEnum?: boole
// We setup a record here to ensure we have comprehensive coverage (any item not covered will result
// in a compile-time error with the missing index)
const encoders: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef) => string> = {
[TypeDefInfo.BTreeMap]: (registry: CodecRegistry, typeDef: TypeDef) =>
const encoders: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef) => string> = {
[TypeDefInfo.BTreeMap]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'BTreeMap'),
[TypeDefInfo.BTreeSet]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.BTreeSet]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'BTreeSet'),
[TypeDefInfo.Compact]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.Compact]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'Compact'),
[TypeDefInfo.DoNotConstruct]: (registry: CodecRegistry, { displayName, lookupIndex, lookupName }: TypeDef) =>
[TypeDefInfo.DoNotConstruct]: (registry: Registry, { displayName, lookupIndex, lookupName }: TypeDef) =>
`DoNotConstruct<${lookupName || displayName || (isUndefined(lookupIndex) ? 'Unknown' : registry.createLookupType(lookupIndex))}>`,
[TypeDefInfo.Enum]: (registry: CodecRegistry, { sub }: TypeDef): string => {
[TypeDefInfo.Enum]: (registry: Registry, { sub }: TypeDef): string => {
assert(sub && Array.isArray(sub), 'Unable to encode Enum type');
// c-like enums have all Null entries
@@ -81,26 +81,26 @@ const encoders: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef)
? stringify({ _enum: sub.map(({ name }, index) => `${name || `Empty${index}`}`) })
: encodeSubTypes(registry, sub, true);
},
[TypeDefInfo.HashMap]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.HashMap]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'HashMap'),
[TypeDefInfo.Int]: (registry: CodecRegistry, { length = 32 }: TypeDef) =>
[TypeDefInfo.Int]: (registry: Registry, { length = 32 }: TypeDef) =>
`Int<${length}>`,
[TypeDefInfo.Linkage]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.Linkage]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'Linkage'),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[TypeDefInfo.Null]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.Null]: (registry: Registry, typeDef: TypeDef) =>
'Null',
[TypeDefInfo.Option]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.Option]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'Option'),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[TypeDefInfo.Plain]: (registry: CodecRegistry, { displayName, type }: TypeDef) =>
[TypeDefInfo.Plain]: (registry: Registry, { displayName, type }: TypeDef) =>
displayName || type,
[TypeDefInfo.Range]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.Range]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, typeDef.type.includes('RangeInclusive') ? 'RangeInclusive' : 'Range'),
[TypeDefInfo.Result]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.Result]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'Result'),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[TypeDefInfo.Set]: (registry: CodecRegistry, { length = 8, sub }: TypeDef): string => {
[TypeDefInfo.Set]: (registry: Registry, { length = 8, sub }: TypeDef): string => {
assert(sub && Array.isArray(sub), 'Unable to encode Set type');
return stringify({
@@ -110,9 +110,9 @@ const encoders: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef)
});
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[TypeDefInfo.Si]: (registry: CodecRegistry, { lookupName, type }: TypeDef) =>
[TypeDefInfo.Si]: (registry: Registry, { lookupName, type }: TypeDef) =>
lookupName || type,
[TypeDefInfo.Struct]: (registry: CodecRegistry, { alias, sub }: TypeDef): string => {
[TypeDefInfo.Struct]: (registry: Registry, { alias, sub }: TypeDef): string => {
assert(sub && Array.isArray(sub), 'Unable to encode Struct type');
return encodeSubTypes(registry, sub, false,
@@ -125,33 +125,33 @@ const encoders: Record<TypeDefInfo, (registry: CodecRegistry, typeDef: TypeDef)
: {}
);
},
[TypeDefInfo.Tuple]: (registry: CodecRegistry, { sub }: TypeDef): string => {
[TypeDefInfo.Tuple]: (registry: Registry, { sub }: TypeDef): string => {
assert(sub && Array.isArray(sub), 'Unable to encode Tuple type');
return `(${sub.map((type) => encodeTypeDef(registry, type)).join(',')})`;
},
[TypeDefInfo.UInt]: (registry: CodecRegistry, { length = 32 }: TypeDef) =>
[TypeDefInfo.UInt]: (registry: Registry, { length = 32 }: TypeDef) =>
`UInt<${length}>`,
[TypeDefInfo.Vec]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.Vec]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'Vec'),
[TypeDefInfo.VecFixed]: (registry: CodecRegistry, { length, sub }: TypeDef): string => {
[TypeDefInfo.VecFixed]: (registry: Registry, { length, sub }: TypeDef): string => {
assert(isNumber(length) && !isUndefined(sub) && !Array.isArray(sub), 'Unable to encode VecFixed type');
return `[${sub.type};${length}]`;
},
[TypeDefInfo.WrapperKeepOpaque]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.WrapperKeepOpaque]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'WrapperKeepOpaque'),
[TypeDefInfo.WrapperOpaque]: (registry: CodecRegistry, typeDef: TypeDef) =>
[TypeDefInfo.WrapperOpaque]: (registry: Registry, typeDef: TypeDef) =>
encodeWithParams(registry, typeDef, 'WrapperOpaque')
};
function encodeType (registry: CodecRegistry, typeDef: TypeDef, withLookup = true): string {
function encodeType (registry: Registry, typeDef: TypeDef, withLookup = true): string {
return withLookup && typeDef.lookupName
? typeDef.lookupName
: encoders[typeDef.info](registry, typeDef);
}
export function encodeTypeDef (registry: CodecRegistry, typeDef: TypeDef): string {
export function encodeTypeDef (registry: Registry, typeDef: TypeDef): string {
// In the case of contracts we do have the unfortunate situation where the displayName would
// refer to "Option" when it is an option. For these, string it out, only using when actually
// not a top-level element to be used
@@ -160,7 +160,7 @@ export function encodeTypeDef (registry: CodecRegistry, typeDef: TypeDef): strin
: encodeType(registry, typeDef);
}
export function withTypeString (registry: CodecRegistry, typeDef: Omit<TypeDef, 'type'> & { type?: string }): TypeDef {
export function withTypeString (registry: Registry, typeDef: Omit<TypeDef, 'type'> & { type?: string }): TypeDef {
return objectSpread({}, typeDef, {
type: encodeType(registry, typeDef as TypeDef, false)
});
+2 -2
View File
@@ -1,11 +1,11 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry } from '@polkadot/types-codec/types';
import type { Codec, CodecClass, Registry } from '@polkadot/types-codec/types';
import type { DetectCodec } from '../types';
import { createClassUnsafe } from '@polkadot/types-create';
export function createClass<T extends Codec = Codec, K extends string = string> (registry: CodecRegistry, type: K): CodecClass<DetectCodec<T, K>> {
export function createClass<T extends Codec = Codec, K extends string = string> (registry: Registry, type: K): CodecClass<DetectCodec<T, K>> {
return createClassUnsafe(registry, type);
}
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecRegistry } from '@polkadot/types-codec/types';
import type { Codec, Registry } from '@polkadot/types-codec/types';
import type { DetectCodec } from '../types';
import { createTypeUnsafe } from '@polkadot/types-create';
@@ -12,6 +12,6 @@ import { createTypeUnsafe } from '@polkadot/types-create';
* instance from
* @param params - The value to instantiate the type with
*/
export function createType<T extends Codec = Codec, K extends string = string> (registry: CodecRegistry, type: K, ...params: unknown[]): DetectCodec<T, K> {
export function createType<T extends Codec = Codec, K extends string = string> (registry: Registry, type: K, ...params: unknown[]): DetectCodec<T, K> {
return createTypeUnsafe(registry, type, params);
}
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, CodecRegistry, IU8a } from '@polkadot/types-codec/types';
import type { Codec, CodecClass, IU8a } from '@polkadot/types-codec/types';
import type { CreateOptions, TypeDef } from '@polkadot/types-create/types';
import type { ExtDef } from '../extrinsic/signedExtensions/types';
import type { ChainProperties, DispatchErrorModule, EventMetadataLatest, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types';
@@ -89,7 +89,7 @@ function injectEvents (registry: TypeRegistry, { lookup, pallets }: MetadataLate
const meta = (registry as Registry).createType<EventMetadataLatest>('EventMetadataLatest', objectSpread({}, variant, { args: getFieldArgs(lookup, variant.fields) }));
return class extends GenericEventData {
constructor (registry: CodecRegistry, value: Uint8Array) {
constructor (registry: Registry, value: Uint8Array) {
super(registry, value, meta, stringCamelCase(name), variant.name.toString());
}
};
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyString, AnyU8a, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyString, AnyU8a, Registry } from '@polkadot/types-codec/types';
import { U8aFixed } from '@polkadot/types-codec';
import { hexToU8a, isHex, isString, isU8a, u8aToU8a } from '@polkadot/util';
@@ -28,7 +28,7 @@ function decodeAccountId (value: AnyU8a | AnyString): AnyU8a {
* just a Uint8Array wrapper with a fixed length.
*/
export class GenericEthereumAccountId extends U8aFixed {
constructor (registry: CodecRegistry, value: AnyU8a = new Uint8Array()) {
constructor (registry: Registry, value: AnyU8a = new Uint8Array()) {
super(registry, decodeAccountId(value), 160);
}
+5 -5
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';
@@ -18,7 +18,7 @@ type AnyAddress = bigint | BN | GenericEthereumLookupSource | GenericEthereumAcc
export const ACCOUNT_ID_PREFIX = new Uint8Array([0xff]);
/** @internal */
function decodeString (registry: CodecRegistry, value: string): GenericEthereumAccountId | GenericAccountIndex {
function decodeString (registry: Registry, value: string): GenericEthereumAccountId | GenericAccountIndex {
const decoded = decodeAddress(value);
return decoded.length === 20
@@ -27,7 +27,7 @@ function decodeString (registry: CodecRegistry, value: string): GenericEthereumA
}
/** @internal */
function decodeU8a (registry: CodecRegistry, value: Uint8Array): GenericEthereumAccountId | GenericAccountIndex {
function decodeU8a (registry: Registry, value: Uint8Array): GenericEthereumAccountId | GenericAccountIndex {
// This allows us to instantiate an address with a raw publicKey. Do this first before
// we checking the first byte, otherwise we may split an already-existent valid address
if (value.length === 20) {
@@ -41,7 +41,7 @@ function decodeU8a (registry: CodecRegistry, value: Uint8Array): GenericEthereum
return registry.createTypeUnsafe('AccountIndex', [u8aToBn(value.subarray(offset, offset + length), true)]);
}
function decodeAddressOrIndex (registry: CodecRegistry, value: AnyAddress): GenericEthereumAccountId | GenericAccountIndex {
function decodeAddressOrIndex (registry: Registry, value: AnyAddress): GenericEthereumAccountId | GenericAccountIndex {
return value instanceof GenericEthereumLookupSource
? value.inner
: value instanceof GenericEthereumAccountId || value instanceof GenericAccountIndex
@@ -62,7 +62,7 @@ function decodeAddressOrIndex (registry: CodecRegistry, value: AnyAddress): Gene
* is encoded as `[ <prefix-byte>, ...publicKey/...bytes ]` as per spec
*/
export class GenericEthereumLookupSource extends Base<GenericEthereumAccountId | GenericAccountIndex> {
constructor (registry: CodecRegistry, value: AnyAddress = new Uint8Array()) {
constructor (registry: Registry, value: AnyAddress = new Uint8Array()) {
super(registry, decodeAddressOrIndex(registry, value));
}
+7 -7
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { Compact } from '@polkadot/types-codec';
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, CodecRegistry, IMethod } from '@polkadot/types-codec/types';
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, IMethod } from '@polkadot/types-codec/types';
import type { HexString } from '@polkadot/util/types';
import type { EcdsaSignature, Ed25519Signature, ExtrinsicUnknown, ExtrinsicV4, Sr25519Signature } from '../interfaces/extrinsics';
import type { FunctionMetadataLatest } from '../interfaces/metadata';
@@ -37,7 +37,7 @@ const VERSIONS = [
export { EXTRINSIC_VERSION as LATEST_EXTRINSIC_VERSION } from './v4/Extrinsic';
/** @internal */
function newFromValue (registry: CodecRegistry, value: any, version: number): ExtrinsicVx | ExtrinsicUnknown {
function newFromValue (registry: Registry, value: any, version: number): ExtrinsicVx | ExtrinsicUnknown {
if (value instanceof GenericExtrinsic) {
return value.unwrap();
}
@@ -51,7 +51,7 @@ function newFromValue (registry: CodecRegistry, value: any, version: number): Ex
}
/** @internal */
function decodeExtrinsic (registry: CodecRegistry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, version: number = DEFAULT_VERSION): ExtrinsicVx | ExtrinsicUnknown {
function decodeExtrinsic (registry: Registry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, version: number = DEFAULT_VERSION): ExtrinsicVx | ExtrinsicUnknown {
if (isU8a(value) || Array.isArray(value) || isHex(value)) {
return decodeU8a(registry, u8aToU8a(value), version);
} else if (value instanceof registry.createClassUnsafe('Call')) {
@@ -62,7 +62,7 @@ function decodeExtrinsic (registry: CodecRegistry, value?: GenericExtrinsic | Ex
}
/** @internal */
function decodeU8a (registry: CodecRegistry, value: Uint8Array, version: number): ExtrinsicVx | ExtrinsicUnknown {
function decodeU8a (registry: Registry, value: Uint8Array, version: number): ExtrinsicVx | ExtrinsicUnknown {
if (!value.length) {
return newFromValue(registry, new Uint8Array(), version);
}
@@ -78,7 +78,7 @@ function decodeU8a (registry: CodecRegistry, value: Uint8Array, version: number)
}
abstract class ExtrinsicBase<A extends AnyTuple> extends Base<ExtrinsicVx | ExtrinsicUnknown> {
constructor (registry: CodecRegistry, value: ExtrinsicV4 | ExtrinsicUnknown, initialU8aLength?: number) {
constructor (registry: Registry, value: ExtrinsicV4 | ExtrinsicUnknown, initialU8aLength?: number) {
super(registry, value, initialU8aLength);
const signKeys = Object.keys(registry.getSignedExtensionTypes());
@@ -169,7 +169,7 @@ abstract class ExtrinsicBase<A extends AnyTuple> extends Base<ExtrinsicVx | Extr
}
public override get registry (): Registry {
return super.registry as Registry;
return super.registry;
}
/**
@@ -238,7 +238,7 @@ abstract class ExtrinsicBase<A extends AnyTuple> extends Base<ExtrinsicVx | Extr
export class GenericExtrinsic<A extends AnyTuple = AnyTuple> extends ExtrinsicBase<A> implements IExtrinsic<A> {
#hashCache?: CodecHash;
constructor (registry: CodecRegistry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, { version }: CreateOptions = {}) {
constructor (registry: Registry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, { version }: CreateOptions = {}) {
super(registry, decodeExtrinsic(registry, value, version));
}
+7 -7
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyU8a, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyU8a, Registry } from '@polkadot/types-codec/types';
import type { BN } from '@polkadot/util';
import type { IExtrinsicEra } from '../types';
@@ -37,7 +37,7 @@ function getTrailingZeros (period: number): number {
}
/** @internal */
function decodeMortalEra (registry: CodecRegistry, value?: MortalMethod | Uint8Array | number[] | string): MortalEraValue {
function decodeMortalEra (registry: Registry, value?: MortalMethod | Uint8Array | number[] | string): MortalEraValue {
if (isU8a(value) || isHex(value) || Array.isArray(value)) {
return decodeMortalU8a(registry, u8aToU8a(value));
} else if (!value) {
@@ -50,7 +50,7 @@ function decodeMortalEra (registry: CodecRegistry, value?: MortalMethod | Uint8A
}
/** @internal */
function decodeMortalObject (registry: CodecRegistry, value: MortalMethod): MortalEraValue {
function decodeMortalObject (registry: Registry, value: MortalMethod): MortalEraValue {
const { current, period } = value;
let calPeriod = Math.pow(2, Math.ceil(Math.log2(period)));
@@ -64,7 +64,7 @@ function decodeMortalObject (registry: CodecRegistry, value: MortalMethod): Mort
}
/** @internal */
function decodeMortalU8a (registry: CodecRegistry, value: Uint8Array): MortalEraValue {
function decodeMortalU8a (registry: Registry, value: Uint8Array): MortalEraValue {
if (value.length === 0) {
return [new U64(registry), new U64(registry)];
}
@@ -117,7 +117,7 @@ function decodeExtrinsicEra (value: IExtrinsicEra | MortalMethod | MortalEnumDef
*/
export class ImmortalEra extends Raw {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor (registry: CodecRegistry, value?: AnyU8a) {
constructor (registry: Registry, value?: AnyU8a) {
// For immortals, we always provide the known value (i.e. treated as a
// constant no matter how it is constructed - it is a fixed structure)
super(registry, IMMORTAL_ERA);
@@ -130,7 +130,7 @@ export class ImmortalEra extends Raw {
* The MortalEra for an extrinsic, indicating period and phase
*/
export class MortalEra extends Tuple {
constructor (registry: CodecRegistry, value?: MortalMethod | Uint8Array | number[] | string) {
constructor (registry: Registry, value?: MortalMethod | Uint8Array | number[] | string) {
super(registry, {
period: U64,
phase: U64
@@ -225,7 +225,7 @@ export class MortalEra extends Tuple {
* The era for an extrinsic, indicating either a mortal or immortal extrinsic
*/
export class GenericExtrinsicEra extends Enum implements IExtrinsicEra {
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
super(registry, {
ImmortalEra,
MortalEra
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyJson, BareOpts, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyJson, BareOpts, Registry } from '@polkadot/types-codec/types';
import type { HexString } from '@polkadot/util/types';
import type { ExtrinsicPayloadV4 } from '../interfaces/extrinsics';
import type { Balance, Hash, Index } from '../interfaces/runtime';
@@ -29,7 +29,7 @@ const VERSIONS = [
];
/** @internal */
function decodeExtrinsicPayload (registry: CodecRegistry, value?: GenericExtrinsicPayload | ExtrinsicPayloadValue | Uint8Array | string, version: number = DEFAULT_VERSION): ExtrinsicPayloadVx {
function decodeExtrinsicPayload (registry: Registry, value?: GenericExtrinsicPayload | ExtrinsicPayloadValue | Uint8Array | string, version: number = DEFAULT_VERSION): ExtrinsicPayloadVx {
if (value instanceof GenericExtrinsicPayload) {
return value.unwrap();
}
@@ -44,7 +44,7 @@ function decodeExtrinsicPayload (registry: CodecRegistry, value?: GenericExtrins
* on the contents included
*/
export class GenericExtrinsicPayload extends Base<ExtrinsicPayloadVx> {
constructor (registry: CodecRegistry, value?: Partial<ExtrinsicPayloadValue> | Uint8Array | string, { version }: ExtrinsicPayloadOptions = {}) {
constructor (registry: Registry, value?: Partial<ExtrinsicPayloadValue> | Uint8Array | string, { version }: ExtrinsicPayloadOptions = {}) {
super(registry, decodeExtrinsicPayload(registry, value as ExtrinsicPayloadValue, version));
}
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { ExtrinsicPayloadOptions } from './types';
import { Struct } from '@polkadot/types-codec';
@@ -12,7 +12,7 @@ import { Struct } from '@polkadot/types-codec';
* A default handler for payloads where the version is not known (default throw)
*/
export class GenericExtrinsicPayloadUnknown extends Struct {
constructor (registry: CodecRegistry, value?: unknown, { version = 0 }: Partial<ExtrinsicPayloadOptions> = {}) {
constructor (registry: Registry, value?: unknown, { version = 0 }: Partial<ExtrinsicPayloadOptions> = {}) {
super(registry, {});
throw new Error(`Unsupported extrinsic payload version ${version}`);
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { ExtrinsicOptions } from './types';
import { Struct } from '@polkadot/types-codec';
@@ -14,7 +14,7 @@ import { UNMASK_VERSION } from './constants';
* A default handler for extrinsics where the version is not known (default throw)
*/
export class GenericExtrinsicUnknown extends Struct {
constructor (registry: CodecRegistry, value?: unknown, { isSigned = false, version = 0 }: Partial<ExtrinsicOptions> = {}) {
constructor (registry: Registry, value?: unknown, { isSigned = false, version = 0 }: Partial<ExtrinsicOptions> = {}) {
super(registry, {});
throw new Error(`Unsupported ${isSigned ? '' : 'un'}signed extrinsic version ${version & UNMASK_VERSION}`);
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { HexString } from '@polkadot/util/types';
import type { Address, Balance, BlockNumber, Call, ExtrinsicEra, Hash, Index, RuntimeVersion } from '../interfaces';
import type { Codec, ISignerPayload, SignerPayloadJSON, SignerPayloadRaw } from '../types';
@@ -45,7 +45,7 @@ const knownTypes: Record<string, string> = {
export class GenericSignerPayload extends Struct implements ISignerPayload, SignerPayloadType {
readonly #extraTypes: Record<string, string>;
constructor (registry: CodecRegistry, value?: HexString | { [x: string]: unknown; } | Map<unknown, unknown> | unknown[]) {
constructor (registry: Registry, value?: HexString | { [x: string]: unknown; } | Map<unknown, unknown> | unknown[]) {
const extensionTypes = objectSpread<Record<string, string>>({}, registry.getSignedExtensionTypes(), registry.getSignedExtensionExtra());
super(registry, objectSpread<Record<string, string>>({}, extensionTypes, knownTypes), value);
+2 -2
View File
@@ -2,11 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
import type { SignOptions } from '@polkadot/keyring/types';
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { IKeyringPair } from '../types';
// a helper function for both types of payloads, Raw and metadata-known
export function sign (registry: CodecRegistry, signerPair: IKeyringPair, u8a: Uint8Array, options?: SignOptions): Uint8Array {
export function sign (registry: Registry, signerPair: IKeyringPair, u8a: Uint8Array, options?: SignOptions): Uint8Array {
const encoded = u8a.length > 256
? registry.hash(u8a)
: u8a;
+3 -4
View File
@@ -1,7 +1,6 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { HexString } from '@polkadot/util/types';
import type { ExtrinsicSignatureV4 } from '../../interfaces/extrinsics';
import type { Address, Call } from '../../interfaces/runtime';
@@ -24,7 +23,7 @@ export interface ExtrinsicValueV4 {
* The third generation of compact extrinsics
*/
export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl {
constructor (registry: CodecRegistry, value?: Uint8Array | ExtrinsicValueV4 | Call, { isSigned }: Partial<ExtrinsicOptions> = {}) {
constructor (registry: Registry, value?: Uint8Array | ExtrinsicValueV4 | Call, { isSigned }: Partial<ExtrinsicOptions> = {}) {
super(registry, {
signature: 'ExtrinsicSignatureV4',
// eslint-disable-next-line sort-keys
@@ -33,7 +32,7 @@ export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl {
}
/** @internal */
public static decodeExtrinsic (registry: CodecRegistry, value?: Call | Uint8Array | ExtrinsicValueV4, isSigned = false): ExtrinsicValueV4 {
public static decodeExtrinsic (registry: Registry, value?: Call | Uint8Array | ExtrinsicValueV4, isSigned = false): ExtrinsicValueV4 {
if (value instanceof GenericExtrinsicV4) {
return value;
} else if (value instanceof registry.createClassUnsafe('Call')) {
@@ -67,7 +66,7 @@ export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl {
}
public override get registry (): Registry {
return super.registry as Registry;
return super.registry;
}
/**
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { SignOptions } from '@polkadot/keyring/types';
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { HexString } from '@polkadot/util/types';
import type { ExtrinsicEra } from '../../interfaces/extrinsics';
import type { AssetId, Balance, Hash, Index } from '../../interfaces/runtime';
@@ -22,7 +22,7 @@ import { sign } from '../util';
export class GenericExtrinsicPayloadV4 extends Struct {
#signOptions: SignOptions;
constructor (registry: CodecRegistry, value?: ExtrinsicPayloadValue | Uint8Array | HexString) {
constructor (registry: Registry, value?: ExtrinsicPayloadValue | Uint8Array | HexString) {
super(registry, objectSpread(
{ method: 'Bytes' },
registry.getSignedExtensionTypes(),
@@ -1,7 +1,6 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { HexString } from '@polkadot/util/types';
import type { EcdsaSignature, Ed25519Signature, ExtrinsicEra, ExtrinsicSignature, Sr25519Signature } from '../../interfaces/extrinsics';
import type { Address, Balance, Call, Index } from '../../interfaces/runtime';
@@ -17,7 +16,7 @@ import { GenericExtrinsicPayloadV4 } from './ExtrinsicPayload';
// Ensure we have enough data for all types of signatures
const FAKE_SIGNATURE = new Uint8Array(256).fill(1);
function toAddress (registry: CodecRegistry, address: Address | Uint8Array | string): Address {
function toAddress (registry: Registry, address: Address | Uint8Array | string): Address {
return registry.createTypeUnsafe('Address', [isU8a(address) ? u8aToHex(address) : address]);
}
@@ -29,7 +28,7 @@ function toAddress (registry: CodecRegistry, address: Address | Uint8Array | str
export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSignature {
#signKeys: string[];
constructor (registry: CodecRegistry, value?: GenericExtrinsicSignatureV4 | Uint8Array, { isSigned }: ExtrinsicSignatureOptions = {}) {
constructor (registry: Registry, value?: GenericExtrinsicSignatureV4 | Uint8Array, { isSigned }: ExtrinsicSignatureOptions = {}) {
const signTypes = registry.getSignedExtensionTypes();
super(
@@ -91,7 +90,7 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
}
public override get registry (): Registry {
return super.registry as Registry;
return super.registry;
}
/**
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyString, AnyU8a, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyString, AnyU8a, Registry } from '@polkadot/types-codec/types';
import { U8aFixed } from '@polkadot/types-codec';
import { assert, hexToU8a, isHex, isString, isU8a, u8aToU8a } from '@polkadot/util';
@@ -30,7 +30,7 @@ function decodeAccountId (value?: AnyU8a | AnyString): Uint8Array {
* just a Uint8Array wrapper with a fixed length.
*/
export class GenericAccountId extends U8aFixed {
constructor (registry: CodecRegistry, value?: AnyU8a) {
constructor (registry: Registry, value?: AnyU8a) {
const decoded = decodeAccountId(value);
// Part of stream containing >= 32 bytes or a all empty (defaults)
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyNumber, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyNumber, Registry } from '@polkadot/types-codec/types';
import { u32 } from '@polkadot/types-codec';
import { BN, bnToBn, isBigInt, isBn, isHex, isNumber, isU8a } from '@polkadot/util';
@@ -36,7 +36,7 @@ function decodeAccountIndex (value: AnyNumber): BN | bigint | Uint8Array | numbe
* for an Account. We extends from [[U32]] to provide the number-like properties.
*/
export class GenericAccountIndex extends u32 {
constructor (registry: CodecRegistry, value: AnyNumber = new BN(0)) {
constructor (registry: Registry, value: AnyNumber = new BN(0)) {
super(registry, decodeAccountIndex(value));
}
+2 -2
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { Vec } from '@polkadot/types-codec';
import type { AnyNumber, AnyU8a, CodecRegistry, IU8a } from '@polkadot/types-codec/types';
import type { AnyNumber, AnyU8a, IU8a, Registry } from '@polkadot/types-codec/types';
import type { GenericExtrinsic } from '../extrinsic/Extrinsic';
import type { Digest, DigestItem, Header } from '../interfaces/runtime';
@@ -27,7 +27,7 @@ export interface BlockValue {
* A block encoded with header and extrinsics
*/
export class GenericBlock extends Struct {
constructor (registry: CodecRegistry, value?: BlockValue | Uint8Array) {
constructor (registry: Registry, value?: BlockValue | Uint8Array) {
super(registry, {
header: 'Header',
// eslint-disable-next-line sort-keys
+12 -12
View File
@@ -1,9 +1,9 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, Codec, CodecRegistry, IMethod } from '@polkadot/types-codec/types';
import type { AnyJson, AnyTuple, AnyU8a, ArgsDef, Codec, IMethod, Registry } from '@polkadot/types-codec/types';
import type { FunctionMetadataLatest } from '../interfaces/metadata';
import type { CallBase, CallFunction, InterfaceTypes, Registry } from '../types';
import type { CallBase, CallFunction, InterfaceTypes } from '../types';
import { Struct, U8aFixed } from '@polkadot/types-codec';
import { isHex, isObject, isU8a, objectSpread, u8aToU8a } from '@polkadot/util';
@@ -26,7 +26,7 @@ interface DecodedMethod extends DecodeMethodInput {
* @param meta - The function metadata used to get the definition.
* @internal
*/
function getArgsDef (registry: CodecRegistry, meta: FunctionMetadataLatest): ArgsDef {
function getArgsDef (registry: Registry, meta: FunctionMetadataLatest): ArgsDef {
return meta.fields.reduce((result, { name, type }, index): ArgsDef => {
result[name.unwrapOr(`param${index}`).toString()] = registry.createLookupType(type) as keyof InterfaceTypes;
@@ -35,7 +35,7 @@ function getArgsDef (registry: CodecRegistry, meta: FunctionMetadataLatest): Arg
}
/** @internal */
function decodeCallViaObject (registry: CodecRegistry, value: DecodedMethod, _meta?: FunctionMetadataLatest): DecodedMethod {
function decodeCallViaObject (registry: Registry, value: DecodedMethod, _meta?: FunctionMetadataLatest): DecodedMethod {
// we only pass args/methodsIndex out
const { args, callIndex } = value;
@@ -46,7 +46,7 @@ function decodeCallViaObject (registry: CodecRegistry, value: DecodedMethod, _me
: callIndex;
// Find metadata with callIndex
const meta = _meta || (registry as Registry).findMetaCall(lookupIndex).meta;
const meta = _meta || registry.findMetaCall(lookupIndex).meta;
return {
args,
@@ -57,14 +57,14 @@ function decodeCallViaObject (registry: CodecRegistry, value: DecodedMethod, _me
}
/** @internal */
function decodeCallViaU8a (registry: CodecRegistry, value: Uint8Array, _meta?: FunctionMetadataLatest): DecodedMethod {
function decodeCallViaU8a (registry: Registry, value: Uint8Array, _meta?: FunctionMetadataLatest): DecodedMethod {
// We need 2 bytes for the callIndex
const callIndex = new Uint8Array(2);
callIndex.set(value.subarray(0, 2), 0);
// Find metadata with callIndex
const meta = _meta || (registry as Registry).findMetaCall(callIndex).meta;
const meta = _meta || registry.findMetaCall(callIndex).meta;
return {
args: value.subarray(2),
@@ -85,7 +85,7 @@ function decodeCallViaU8a (registry: CodecRegistry, value: Uint8Array, _meta?: F
* necessary.
* @internal
*/
function decodeCall (registry: CodecRegistry, value: unknown | DecodedMethod | Uint8Array | string = new Uint8Array(), _meta?: FunctionMetadataLatest): DecodedMethod {
function decodeCall (registry: Registry, value: unknown | DecodedMethod | Uint8Array | string = new Uint8Array(), _meta?: FunctionMetadataLatest): DecodedMethod {
if (isU8a(value) || isHex(value)) {
return decodeCallViaU8a(registry, u8aToU8a(value), _meta);
} else if (isObject(value) && value.callIndex && value.args) {
@@ -101,7 +101,7 @@ function decodeCall (registry: CodecRegistry, value: unknown | DecodedMethod | U
* A wrapper around the `[sectionIndex, methodIndex]` value that uniquely identifies a method
*/
export class GenericCallIndex extends U8aFixed {
constructor (registry: CodecRegistry, value?: AnyU8a) {
constructor (registry: Registry, value?: AnyU8a) {
super(registry, value, 16);
}
}
@@ -114,7 +114,7 @@ export class GenericCallIndex extends U8aFixed {
export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implements CallBase<A> {
protected _meta: FunctionMetadataLatest;
constructor (registry: CodecRegistry, value: unknown, meta?: FunctionMetadataLatest) {
constructor (registry: Registry, value: unknown, meta?: FunctionMetadataLatest) {
const decoded = decodeCall(registry, value, meta);
try {
@@ -127,7 +127,7 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
let method = 'unknown.unknown';
try {
const c = (registry as Registry).findMetaCall(decoded.callIndex);
const c = (registry).findMetaCall(decoded.callIndex);
method = `${c.section}.${c.method}`;
} catch (error) {
@@ -190,7 +190,7 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
}
public override get registry (): Registry {
return super.registry as Registry;
return super.registry;
}
/**
@@ -1,13 +1,13 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { Codec } from '../types';
import { Json, Option, Text, u32, Vec } from '@polkadot/types-codec';
import { isFunction, isNull, isUndefined } from '@polkadot/util';
function createValue (registry: CodecRegistry, type: string, value: unknown, asArray = true): Option<Codec> {
function createValue (registry: Registry, type: string, value: unknown, asArray = true): Option<Codec> {
// We detect codec here as well - when found, generally this is constructed from itself
if (value && isFunction((value as Option<Codec>).unwrapOrDefault)) {
return value as Option<Codec>;
@@ -27,7 +27,7 @@ function createValue (registry: CodecRegistry, type: string, value: unknown, asA
);
}
function decodeValue (registry: CodecRegistry, key: string, value: unknown): unknown {
function decodeValue (registry: Registry, key: string, value: unknown): unknown {
return key === 'ss58Format'
? createValue(registry, 'Option<u32>', value, false)
: key === 'tokenDecimals'
@@ -37,7 +37,7 @@ function decodeValue (registry: CodecRegistry, key: string, value: unknown): unk
: value;
}
function decode (registry: CodecRegistry, value?: Map<string, unknown> | Record<string, unknown> | null): Record<string, unknown> {
function decode (registry: Registry, value?: Map<string, unknown> | Record<string, unknown> | null): Record<string, unknown> {
return (
// allow decoding from a map as well (ourselves)
value && isFunction((value as Map<string, unknown>).entries)
@@ -55,7 +55,7 @@ function decode (registry: CodecRegistry, value?: Map<string, unknown> | Record<
}
export class GenericChainProperties extends Json {
constructor (registry: CodecRegistry, value?: Map<string, unknown> | Record<string, unknown> | null) {
constructor (registry: Registry, value?: Map<string, unknown> | Record<string, unknown> | null) {
super(registry, decode(registry, value));
}
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyU8a, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyU8a, Registry } from '@polkadot/types-codec/types';
import type { AccountId, RawAuraPreDigest, RawBabePreDigestCompat } from '../interfaces';
import { Bytes, U8aFixed, u32 } from '@polkadot/types-codec';
@@ -12,7 +12,7 @@ export const CID_BABE = stringToU8a('BABE');
export const CID_GRPA = stringToU8a('FRNK');
export const CID_POW = stringToU8a('pow_');
function getAuraAuthor (registry: CodecRegistry, bytes: Bytes, sessionValidators: AccountId[]): AccountId {
function getAuraAuthor (registry: Registry, bytes: Bytes, sessionValidators: AccountId[]): AccountId {
return sessionValidators[
registry.createTypeUnsafe<RawAuraPreDigest>('RawAuraPreDigest', [bytes.toU8a(true)])
.slotNumber
@@ -21,7 +21,7 @@ function getAuraAuthor (registry: CodecRegistry, bytes: Bytes, sessionValidators
];
}
function getBabeAuthor (registry: CodecRegistry, bytes: Bytes, sessionValidators: AccountId[]): AccountId {
function getBabeAuthor (registry: Registry, bytes: Bytes, sessionValidators: AccountId[]): AccountId {
const digest = registry.createTypeUnsafe<RawBabePreDigestCompat>('RawBabePreDigestCompat', [bytes.toU8a(true)]);
return sessionValidators[
@@ -29,7 +29,7 @@ function getBabeAuthor (registry: CodecRegistry, bytes: Bytes, sessionValidators
];
}
function getBytesAsAuthor (registry: CodecRegistry, bytes: Bytes): AccountId {
function getBytesAsAuthor (registry: Registry, bytes: Bytes): AccountId {
return registry.createTypeUnsafe('AccountId', [bytes]);
}
@@ -39,7 +39,7 @@ function getBytesAsAuthor (registry: CodecRegistry, bytes: Bytes): AccountId {
* A 4-byte identifier identifying the engine
*/
export class GenericConsensusEngineId extends U8aFixed {
constructor (registry: CodecRegistry, value?: AnyU8a) {
constructor (registry: Registry, value?: AnyU8a) {
super(
registry,
isNumber(value)
+7 -7
View File
@@ -1,11 +1,11 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyJson, Codec, CodecClass, CodecRegistry } from '@polkadot/types-codec/types';
import type { CreateRegistry, TypeDef } from '@polkadot/types-create/types';
import type { AnyJson, Codec, CodecClass } from '@polkadot/types-codec/types';
import type { TypeDef } from '@polkadot/types-create/types';
import type { EventMetadataLatest } from '../interfaces/metadata';
import type { EventId } from '../interfaces/system';
import type { IEvent, IEventData, InterfaceTypes } from '../types';
import type { IEvent, IEventData, InterfaceTypes, Registry } from '../types';
import { Null, Struct, Tuple } from '@polkadot/types-codec';
import { objectSpread } from '@polkadot/util';
@@ -19,7 +19,7 @@ interface Decoded {
}
/** @internal */
function decodeEvent (registry: CodecRegistry, value?: Uint8Array): Decoded {
function decodeEvent (registry: Registry, value?: Uint8Array): Decoded {
if (!value || !value.length) {
return { DataType: Null };
}
@@ -49,7 +49,7 @@ export class GenericEventData extends Tuple implements IEventData {
readonly #typeDef: TypeDef[];
constructor (registry: CodecRegistry, value: Uint8Array, meta: EventMetadataLatest, section = '<unknown>', method = '<unknown>') {
constructor (registry: Registry, value: Uint8Array, meta: EventMetadataLatest, section = '<unknown>', method = '<unknown>') {
const fields = meta?.fields || [];
super(registry, fields.map(({ type }) => registry.createLookupType(type) as keyof InterfaceTypes), value);
@@ -57,7 +57,7 @@ export class GenericEventData extends Tuple implements IEventData {
this.#meta = meta;
this.#method = method;
this.#section = section;
this.#typeDef = fields.map(({ type }) => (registry as CreateRegistry).lookup.getTypeDef(type));
this.#typeDef = fields.map(({ type }) => (registry).lookup.getTypeDef(type));
}
/**
@@ -98,7 +98,7 @@ export class GenericEventData extends Tuple implements IEventData {
export class GenericEvent extends Struct implements IEvent<Codec[]> {
// Currently we _only_ decode from Uint8Array, since we expect it to
// be used via EventRecord
constructor (registry: CodecRegistry, _value?: Uint8Array) {
constructor (registry: Registry, _value?: Uint8Array) {
const { DataType, value } = decodeEvent(registry, _value);
super(registry, {
+5 -5
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';
@@ -18,7 +18,7 @@ type AnyAddress = bigint | BN | GenericLookupSource | GenericAccountId | Generic
export const ACCOUNT_ID_PREFIX = new Uint8Array([0xff]);
/** @internal */
function decodeString (registry: CodecRegistry, value: string): GenericAccountId | GenericAccountIndex {
function decodeString (registry: Registry, value: string): GenericAccountId | GenericAccountIndex {
const decoded = decodeAddress(value);
return decoded.length === 32
@@ -27,7 +27,7 @@ function decodeString (registry: CodecRegistry, value: string): GenericAccountId
}
/** @internal */
function decodeU8a (registry: CodecRegistry, value: Uint8Array): GenericAccountId | GenericAccountIndex {
function decodeU8a (registry: Registry, value: Uint8Array): GenericAccountId | GenericAccountIndex {
// This allows us to instantiate an address with a raw publicKey. Do this first before
// we checking the first byte, otherwise we may split an already-existent valid address
if (value.length === 32) {
@@ -42,7 +42,7 @@ function decodeU8a (registry: CodecRegistry, value: Uint8Array): GenericAccountI
}
/** @internal */
function decodeAddressOrIndex (registry: CodecRegistry, value: AnyAddress): GenericAccountId | GenericAccountIndex {
function decodeAddressOrIndex (registry: Registry, value: AnyAddress): GenericAccountId | GenericAccountIndex {
return value instanceof GenericLookupSource
? value.inner
: value instanceof GenericAccountId || value instanceof GenericAccountIndex
@@ -63,7 +63,7 @@ function decodeAddressOrIndex (registry: CodecRegistry, value: AnyAddress): Gene
* is encoded as `[ <prefix-byte>, ...publicKey/...bytes ]` as per spec
*/
export class GenericLookupSource extends Base<GenericAccountId | GenericAccountIndex> {
constructor (registry: CodecRegistry, value: AnyAddress = new Uint8Array()) {
constructor (registry: Registry, value: AnyAddress = new Uint8Array()) {
super(registry, decodeAddressOrIndex(registry, value));
}
+4 -4
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import { Enum } from '@polkadot/types-codec';
import { isBn, isNumber, isString, isU8a } from '@polkadot/util';
@@ -10,7 +10,7 @@ import { decodeAddress } from '@polkadot/util-crypto';
import { GenericAccountId } from './AccountId';
import { GenericAccountIndex } from './AccountIndex';
function decodeU8a (registry: CodecRegistry, u8a: Uint8Array): unknown {
function decodeU8a (registry: Registry, u8a: Uint8Array): unknown {
if ([0, 32].includes(u8a.length)) {
return { Id: u8a };
} else if (u8a.length === 20) {
@@ -22,7 +22,7 @@ function decodeU8a (registry: CodecRegistry, u8a: Uint8Array): unknown {
return u8a;
}
function decodeMultiAny (registry: CodecRegistry, value?: unknown): unknown {
function decodeMultiAny (registry: Registry, value?: unknown): unknown {
if (value instanceof GenericAccountId) {
return { Id: value };
} else if (isU8a(value)) {
@@ -40,7 +40,7 @@ function decodeMultiAny (registry: CodecRegistry, value?: unknown): unknown {
}
export class GenericMultiAddress extends Enum {
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
super(registry, {
Id: 'AccountId',
Index: 'Compact<AccountIndex>',
+4 -4
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyJson, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyJson, Registry } from '@polkadot/types-codec/types';
import type { Conviction } from '../interfaces/democracy';
import type { AllConvictions } from '../interfaces/democracy/definitions';
import type { ArrayElementType } from '../types';
@@ -38,7 +38,7 @@ function decodeVoteU8a (value: Uint8Array): Uint8Array {
}
/** @internal */
function decodeVoteType (registry: CodecRegistry, value: VoteType): Uint8Array {
function decodeVoteType (registry: Registry, value: VoteType): Uint8Array {
return new Uint8Array([
(
new Bool(registry, value.aye).isTrue
@@ -50,7 +50,7 @@ function decodeVoteType (registry: CodecRegistry, value: VoteType): Uint8Array {
}
/** @internal */
function decodeVote (registry: CodecRegistry, value?: InputTypes): Uint8Array {
function decodeVote (registry: Registry, value?: InputTypes): Uint8Array {
if (isU8a(value)) {
return decodeVoteU8a(value);
} else if (isUndefined(value) || value instanceof Boolean || isBoolean(value)) {
@@ -72,7 +72,7 @@ export class GenericVote extends U8aFixed {
#conviction: Conviction;
constructor (registry: CodecRegistry, value?: InputTypes) {
constructor (registry: Registry, value?: InputTypes) {
// decoded is just 1 byte
// Aye: Most Significant Bit
// Conviction: 0000 - 0101
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyNumber, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyNumber, Registry } from '@polkadot/types-codec/types';
import { U32 } from '@polkadot/types-codec';
import { assert } from '@polkadot/util';
@@ -9,7 +9,7 @@ import { assert } from '@polkadot/util';
export const MAGIC_NUMBER = 0x6174656d; // `meta`, reversed for Little Endian encoding
export class MagicNumber extends U32 {
constructor (registry: CodecRegistry, value?: AnyNumber) {
constructor (registry: Registry, value?: AnyNumber) {
super(registry, value);
if (!this.isEmpty) {
+3 -3
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { HexString } from '@polkadot/util/types';
import { isHex, isU8a, u8aToU8a } from '@polkadot/util';
@@ -22,7 +22,7 @@ function toU8a (value: Uint8Array | HexString): Uint8Array {
: value;
}
function decodeU8a (registry: CodecRegistry, value: Uint8Array): MetadataVersioned {
function decodeU8a (registry: Registry, value: Uint8Array): MetadataVersioned {
try {
return new MetadataVersioned(registry, value);
} catch (error) {
@@ -45,7 +45,7 @@ function decodeU8a (registry: CodecRegistry, value: Uint8Array): MetadataVersion
* The versioned runtime metadata as a decoded structure
*/
export class Metadata extends MetadataVersioned {
constructor (registry: CodecRegistry, value?: Uint8Array | HexString | Map<string, unknown> | Record<string, unknown>) {
constructor (registry: Registry, value?: Uint8Array | HexString | Map<string, unknown> | Record<string, unknown>) {
super(
registry,
isU8a(value) || isHex(value)
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyJson, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyJson } from '@polkadot/types-codec/types';
import type { MetadataAll, MetadataLatest, MetadataV9, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14 } from '../interfaces/metadata';
import type { Registry } from '../types';
@@ -31,7 +31,7 @@ const LATEST_VERSION = 14;
export class MetadataVersioned extends Struct {
readonly #converted = new Map<MetaVersions, MetaMapped>();
constructor (registry: CodecRegistry, value?: unknown) {
constructor (registry: Registry, value?: unknown) {
// console.time('MetadataVersioned')
super(registry, {
@@ -48,7 +48,7 @@ export class MetadataVersioned extends Struct {
return this.version === version;
};
#getVersion = <T extends MetaMapped, F extends MetaMapped>(version: MetaVersions, fromPrev: (registry: CodecRegistry, input: F, metaVersion: number) => T): T => {
#getVersion = <T extends MetaMapped, F extends MetaMapped>(version: MetaVersions, fromPrev: (registry: Registry, input: F, metaVersion: number) => T): T => {
const asCurr = `asV${version}` as MetaAsX;
const asPrev = version === 'latest'
? `asV${LATEST_VERSION}` as MetaAsX
@@ -73,7 +73,7 @@ export class MetadataVersioned extends Struct {
};
public override get registry (): Registry {
return super.registry as Registry;
return super.registry;
}
/**
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { Text, Type, Vec } from '@polkadot/types-codec';
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { ILookup, TypeDef } from '@polkadot/types-create/types';
import type { PortableType } from '../../interfaces/metadata';
import type { SiField, SiLookupTypeId, SiPath, SiType, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '../../interfaces/scaleInfo';
@@ -326,7 +326,7 @@ export class PortableRegistry extends Struct implements ILookup {
#typeDefs: Record<number, TypeDef> = {};
#types: Record<number, PortableType>;
constructor (registry: CodecRegistry, value?: Uint8Array) {
constructor (registry: Registry, value?: Uint8Array) {
// console.time('PortableRegistry')
super(registry, {
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { MetadataLatest, PalletConstantMetadataLatest } from '../../../interfaces';
import type { ConstantCodec, Constants } from '../types';
@@ -11,7 +11,7 @@ import { objectNameToCamel } from '../util';
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function decorateConstants (registry: CodecRegistry, { pallets }: MetadataLatest, _version: number): Constants {
export function decorateConstants (registry: Registry, { pallets }: MetadataLatest, _version: number): Constants {
const result: Constants = {};
for (let i = 0; i < pallets.length; i++) {
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { Text, u8 } from '@polkadot/types-codec';
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { DispatchErrorModule, MetadataLatest, SiField, SiVariant } from '../../../interfaces';
import type { PortableRegistry } from '../../../metadata';
import type { Errors, IsError } from '../types';
@@ -28,7 +28,7 @@ export function variantToMeta (lookup: PortableRegistry, variant: SiVariant): It
}
/** @internal */
export function decorateErrors (registry: CodecRegistry, { lookup, pallets }: MetadataLatest, version: number): Errors {
export function decorateErrors (registry: Registry, { lookup, pallets }: MetadataLatest, version: number): Errors {
const result: Errors = {};
for (let i = 0; i < pallets.length; i++) {
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyTuple, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyTuple, Registry } from '@polkadot/types-codec/types';
import type { MetadataLatest, PalletMetadataLatest, SiVariant } from '../../../interfaces';
import type { IEvent } from '../../../types';
import type { Events, IsEvent } from '../types';
@@ -17,7 +17,7 @@ export function filterEventsSome ({ events }: PalletMetadataLatest): boolean {
}
/** @internal */
export function decorateEvents (registry: CodecRegistry, { lookup, pallets }: MetadataLatest, version: number): Events {
export function decorateEvents (registry: Registry, { lookup, pallets }: MetadataLatest, version: number): Events {
const result: Events = {};
const filtered = pallets.filter(filterEventsSome);
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyJson, AnyTuple, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyJson, AnyTuple, Registry } from '@polkadot/types-codec/types';
import type { Call, FunctionMetadataLatest } from '../../../interfaces';
import type { CallFunction, IMethod } from '../../../types';
@@ -12,7 +12,7 @@ function isTx <A extends AnyTuple> (tx: IMethod<AnyTuple>, callIndex: Uint8Array
}
/** @internal */
export function createUnchecked (registry: CodecRegistry, section: string, callIndex: Uint8Array, callMetadata: FunctionMetadataLatest): CallFunction {
export function createUnchecked (registry: Registry, section: string, callIndex: Uint8Array, callMetadata: FunctionMetadataLatest): CallFunction {
const expectedArgs = callMetadata.fields;
const funcName = stringCamelCase(callMetadata.name);
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { MetadataLatest, PalletMetadataLatest, SiVariant } from '../../../interfaces';
import type { PortableRegistry } from '../../../metadata';
import type { CallFunction } from '../../../types';
@@ -18,7 +18,7 @@ export function filterCallsSome ({ calls }: PalletMetadataLatest): boolean {
return calls.isSome;
}
export function createCallFunction (registry: CodecRegistry, lookup: PortableRegistry, variant: SiVariant, sectionName: string, sectionIndex: number): CallFunction {
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);
@@ -45,7 +45,7 @@ export function createCallFunction (registry: CodecRegistry, lookup: PortableReg
}
/** @internal */
export function decorateExtrinsics (registry: CodecRegistry, { lookup, pallets }: MetadataLatest, version: number): Extrinsics {
export function decorateExtrinsics (registry: Registry, { lookup, pallets }: MetadataLatest, version: number): Extrinsics {
const result: Extrinsics = {};
const filtered = pallets.filter(filterCallsSome);
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { DecoratedMeta } from './types';
import { assert } from '@polkadot/util';
@@ -16,7 +16,7 @@ import { decorateStorage } from './storage';
/**
* Expands the metadata by decoration into consts, query and tx sections
*/
export function expandMetadata (registry: CodecRegistry, metadata: Metadata): DecoratedMeta {
export function expandMetadata (registry: Registry, metadata: Metadata): DecoratedMeta {
assert(metadata instanceof Metadata, 'You need to pass a valid Metadata instance to Decorated');
const latest = metadata.asLatest;
@@ -1,10 +1,10 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry, ICompact, INumber } from '@polkadot/types-codec/types';
import type { CreateRegistry } from '@polkadot/types-create/types';
import type { ICompact, INumber } from '@polkadot/types-codec/types';
import type { StorageEntryMetadataLatest, StorageHasher } from '../../../interfaces/metadata';
import type { StorageEntry } from '../../../primitive/types';
import type { Registry } from '../../../types';
import { Raw } from '@polkadot/types-codec';
import { assert, compactAddLength, compactStripLength, isUndefined, objectSpread, stringCamelCase, stringLowerFirst, u8aConcat, u8aToU8a } from '@polkadot/util';
@@ -46,7 +46,7 @@ export const NO_RAW_ARGS: RawArgs = {
};
/** @internal */
export function createKeyRaw (registry: CodecRegistry, itemFn: CreateItemBase, { args, hashers, keys }: RawArgs): Uint8Array {
export function createKeyRaw (registry: Registry, itemFn: CreateItemBase, { args, hashers, keys }: RawArgs): Uint8Array {
const extra = new Array<Uint8Array>(keys.length);
for (let i = 0; i < keys.length; i++) {
@@ -68,7 +68,7 @@ function filterDefined (a: unknown): boolean {
}
/** @internal */
function createKey (registry: CodecRegistry, itemFn: CreateItemFn, { args, hashers, keys }: RawArgs): Uint8Array {
function createKey (registry: Registry, itemFn: CreateItemFn, { args, hashers, keys }: RawArgs): Uint8Array {
const { method, section } = itemFn;
assert(Array.isArray(args), () => `Call to ${stringCamelCase(section || 'unknown')}.${stringCamelCase(method || 'unknown')} needs ${keys.length} arguments`);
@@ -81,7 +81,7 @@ function createKey (registry: CodecRegistry, itemFn: CreateItemFn, { args, hashe
}
/** @internal */
function createWStorageFn (registry: CodecRegistry, itemFn: CreateItemFn, options: CreateItemOptions): (...args: unknown[]) => Uint8Array {
function createWStorageFn (registry: Registry, itemFn: CreateItemFn, options: CreateItemOptions): (...args: unknown[]) => Uint8Array {
const { meta: { type } } = itemFn;
let cacheKey: Uint8Array | null = null;
@@ -104,12 +104,12 @@ function createWStorageFn (registry: CodecRegistry, itemFn: CreateItemFn, option
return hashers.length === 1
? createKey(registry, itemFn, { args, hashers, keys: [key] })
: createKey(registry, itemFn, { args, hashers, keys: (registry as CreateRegistry).lookup.getSiType(key).def.asTuple });
: createKey(registry, itemFn, { args, hashers, keys: (registry).lookup.getSiType(key).def.asTuple });
};
}
/** @internal */
function createWithMeta (registry: CodecRegistry, itemFn: CreateItemFn, options: CreateItemOptions): StorageEntry {
function createWithMeta (registry: Registry, itemFn: CreateItemFn, options: CreateItemOptions): StorageEntry {
const { meta, method, prefix, section } = itemFn;
const storageFn = createWStorageFn(registry, itemFn, options) as StorageEntry;
@@ -126,7 +126,7 @@ function createWithMeta (registry: CodecRegistry, itemFn: CreateItemFn, options:
}
/** @internal */
function extendHeadMeta (registry: CodecRegistry, { meta: { docs, name, type }, section }: CreateItemFn, { method }: StorageEntry, iterFn: (...args: unknown[]) => Raw): (...args: unknown[]) => StorageKey {
function extendHeadMeta (registry: Registry, { meta: { docs, name, type }, section }: CreateItemFn, { method }: StorageEntry, iterFn: (...args: unknown[]) => Raw): (...args: unknown[]) => StorageKey {
const outputType = registry.createLookupType(type.asMap.key);
// metadata with a fallback value using the type of the key, the normal
@@ -145,7 +145,7 @@ function extendHeadMeta (registry: CodecRegistry, { meta: { docs, name, type },
}
/** @internal */
function extendPrefixedMap (registry: CodecRegistry, itemFn: CreateItemFn, storageFn: StorageEntry): StorageEntry {
function extendPrefixedMap (registry: Registry, itemFn: CreateItemFn, storageFn: StorageEntry): StorageEntry {
const { meta: { type }, method, section } = itemFn;
storageFn.iterKey = extendHeadMeta(registry, itemFn, storageFn, (...args: unknown[]): Raw => {
@@ -162,7 +162,7 @@ function extendPrefixedMap (registry: CodecRegistry, itemFn: CreateItemFn, stora
const { hashers, key } = type.asMap;
const keysVec = hashers.length === 1
? [key]
: (registry as CreateRegistry).lookup.getSiType(key).def.asTuple;
: (registry).lookup.getSiType(key).def.asTuple;
return new Raw(registry, createKeyRaw(registry, itemFn, { args, hashers: hashers.slice(0, args.length), keys: keysVec.slice(0, args.length) }));
}
@@ -175,7 +175,7 @@ function extendPrefixedMap (registry: CodecRegistry, itemFn: CreateItemFn, stora
}
/** @internal */
export function createFunction (registry: CodecRegistry, itemFn: CreateItemFn, options: CreateItemOptions): StorageEntry {
export function createFunction (registry: Registry, itemFn: CreateItemFn, options: CreateItemOptions): StorageEntry {
const { meta: { type } } = itemFn;
const storageFn = createWithMeta(registry, itemFn, options);
@@ -1,14 +1,14 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { StorageEntry } from '../../../primitive/types';
import type { Storage } from '../types';
import { substrate } from './substrate';
/** @internal */
export function getStorage (registry: CodecRegistry): Storage {
export function getStorage (registry: Registry): Storage {
const storage: Record<string, StorageEntry> = {};
const entries = Object.entries(substrate);
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { MetadataLatest, StorageEntryMetadataLatest } from '../../../interfaces';
import type { Storage } from '../types';
@@ -18,7 +18,7 @@ const VERSION_DOCS = { docs: 'Returns the current pallet version from storage',
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function decorateStorage (registry: CodecRegistry, { pallets }: MetadataLatest, _metaVersion: number): Storage {
export function decorateStorage (registry: Registry, { pallets }: MetadataLatest, _metaVersion: number): Storage {
const result: Storage = getStorage(registry);
for (let i = 0; i < pallets.length; i++) {
@@ -1,13 +1,13 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { StorageEntry } from '../../../primitive/types';
import type { ManualMetadata } from './util';
import { createRuntimeFunction } from './util';
type Creator = (registry: CodecRegistry) => StorageEntry;
type Creator = (registry: Registry) => StorageEntry;
const prefix = 'Substrate';
const section = 'substrate';
@@ -1,7 +1,6 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { PortableType } from '../../../interfaces';
import type { StorageEntry } from '../../../primitive/types';
import type { Registry } from '../../../types';
@@ -61,15 +60,15 @@ function findSiType (registry: Registry, orig: string): PortableType | undefined
// Small helper function to factorize code on this page.
/** @internal */
export function createRuntimeFunction ({ method, prefix, section }: ManualDefinition, key: Uint8Array | string, { docs, type }: ManualMetadata): (registry: CodecRegistry) => StorageEntry {
return (registry: CodecRegistry): StorageEntry =>
export function createRuntimeFunction ({ method, prefix, section }: ManualDefinition, key: Uint8Array | string, { docs, type }: ManualMetadata): (registry: Registry) => StorageEntry {
return (registry: Registry): StorageEntry =>
createFunction(registry, {
meta: registry.createTypeUnsafe('StorageEntryMetadataLatest', [{
docs: registry.createTypeUnsafe('Vec<Text>', [[docs]]),
modifier: registry.createTypeUnsafe('StorageEntryModifierLatest', ['Required']),
name: registry.createTypeUnsafe('Text', [method]),
toJSON: (): any => key,
type: registry.createTypeUnsafe('StorageEntryTypeLatest', [{ Plain: findSiType(registry as Registry, type)?.id || 0 }])
type: registry.createTypeUnsafe('StorageEntryTypeLatest', [{ Plain: findSiType(registry, type)?.id || 0 }])
}]),
method,
prefix,
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyTuple, Codec, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyTuple, Codec, Registry } from '@polkadot/types-codec/types';
import type { DispatchErrorModule, ErrorMetadataLatest, EventMetadataLatest, PalletConstantMetadataLatest } from '../../interfaces';
import type { StorageEntry } from '../../primitive/types';
import type { CallFunction, IEvent } from '../../types';
@@ -47,6 +47,6 @@ export interface DecoratedMeta {
readonly errors: Errors;
readonly events: Events;
readonly query: Storage;
readonly registry: CodecRegistry;
readonly registry: Registry;
readonly tx: Extrinsics
}
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { MetadataLatest, SiLookupTypeId } from '../../interfaces';
import type { PortableRegistry } from '../../metadata';
@@ -62,6 +62,6 @@ function getPalletNames ({ lookup, pallets }: MetadataLatest): string[][][] {
}
/** @internal */
export function getUniqTypes (registry: CodecRegistry, meta: MetadataLatest, throwError: boolean): string[] {
export function getUniqTypes (registry: Registry, meta: MetadataLatest, throwError: boolean): string[] {
return validateTypes(registry, throwError, flattenUniq(getPalletNames(meta)));
}
+5 -5
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { Check } from './types';
import fs from 'fs';
@@ -23,7 +23,7 @@ function writeJson (json: unknown, version: number, type: string, sub: 'json' |
}
/** @internal */
export function decodeLatestMeta (registry: CodecRegistry, type: string, version: number, { compare, data, types }: Check): void {
export function decodeLatestMeta (registry: Registry, type: string, version: number, { compare, data, types }: Check): void {
const metadata = new Metadata(registry, data);
registry.setMetadata(metadata);
@@ -68,7 +68,7 @@ export function decodeLatestMeta (registry: CodecRegistry, type: string, version
}
/** @internal */
export function toLatest (registry: CodecRegistry, version: number, { data }: Check, withThrow = true): void {
export function toLatest (registry: Registry, version: number, { data }: Check, withThrow = true): void {
it(`converts v${version} to latest`, (): void => {
const metadata = new Metadata(registry, data);
@@ -83,7 +83,7 @@ export function toLatest (registry: CodecRegistry, version: number, { data }: Ch
}
/** @internal */
export function defaultValues (registry: CodecRegistry, { data, fails = [] }: Check, withThrow = true, withFallbackCheck = false): void {
export function defaultValues (registry: Registry, { data, fails = [] }: Check, withThrow = true, withFallbackCheck = false): void {
describe('storage with default values', (): void => {
const metadata = new Metadata(registry, data);
const { pallets } = metadata.asLatest;
@@ -125,7 +125,7 @@ export function defaultValues (registry: CodecRegistry, { data, fails = [] }: Ch
});
}
function serialize (registry: CodecRegistry, { data }: Check): void {
function serialize (registry: Registry, { data }: Check): void {
const metadata = new Metadata(registry, data);
it('serializes to hex in the same form as retrieved', (): void => {
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyJson, CodecRegistry } from '@polkadot/types-codec/types';
import type { AnyJson, Registry } from '@polkadot/types-codec/types';
import type { MetadataLatest, PalletCallMetadataLatest } from '../../interfaces/metadata';
import { Option, Text, u8 } from '@polkadot/types-codec';
@@ -22,7 +22,7 @@ function trimDocs (docs: Text[]): string[] {
}
/** @internal */
export function toCallsOnly (registry: CodecRegistry, { extrinsic, lookup, pallets }: MetadataLatest): AnyJson {
export function toCallsOnly (registry: Registry, { extrinsic, lookup, pallets }: MetadataLatest): AnyJson {
return registry.createTypeUnsafe('MetadataLatest', [{
extrinsic,
lookup: {
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecRegistry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import { logger } from '@polkadot/util';
@@ -11,7 +11,7 @@ import { flattenUniq } from './flattenUniq';
const l = logger('metadata');
/** @internal */
export function validateTypes (registry: CodecRegistry, throwError: boolean, types: string[]): string[] {
export function validateTypes (registry: Registry, throwError: boolean, types: string[]): string[] {
const missing = flattenUniq(extractTypes(types))
.filter((type) => !registry.hasType(type))
.sort();

Some files were not shown because too many files have changed in this diff Show More