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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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>',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// 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 { MetadataV10, MetadataV11 } from '../../interfaces/metadata';
|
||||
|
||||
/** @internal */
|
||||
export function toV11 (registry: CodecRegistry, { modules }: MetadataV10): MetadataV11 {
|
||||
export function toV11 (registry: Registry, { modules }: MetadataV10): MetadataV11 {
|
||||
return registry.createTypeUnsafe('MetadataV11', [{
|
||||
// This is new in V11, pass V0 here - something non-existing, telling the API to use
|
||||
// the fallback for this information (on-chain detection)
|
||||
|
||||
@@ -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 { MetadataV11, MetadataV12, ModuleMetadataV12 } from '../../interfaces/metadata';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
**/
|
||||
export function toV12 (registry: CodecRegistry, { extrinsic, modules }: MetadataV11): MetadataV12 {
|
||||
export function toV12 (registry: Registry, { extrinsic, modules }: MetadataV11): MetadataV12 {
|
||||
return registry.createTypeUnsafe('MetadataV12', [{
|
||||
extrinsic,
|
||||
modules: modules.map((mod): ModuleMetadataV12 =>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// 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 { MetadataV12, MetadataV13 } from '../../interfaces/metadata';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
**/
|
||||
export function toV13 (registry: CodecRegistry, metadata: MetadataV12): MetadataV13 {
|
||||
export function toV13 (registry: Registry, metadata: MetadataV12): MetadataV13 {
|
||||
return registry.createTypeUnsafe('MetadataV13', [metadata]);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Text, Type } from '@polkadot/types-codec';
|
||||
import type { CodecRegistry } from '@polkadot/types-codec/types';
|
||||
import type { ErrorMetadataV13, EventMetadataV13, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionMetadataV13, MetadataV13, MetadataV14, ModuleConstantMetadataV13, ModuleMetadataV13, PalletCallMetadataV14, PalletConstantMetadataV14, PalletErrorMetadataV14, PalletEventMetadataV14, PalletMetadataV14, PalletStorageMetadataV14, StorageEntryMetadataV14, StorageEntryTypeV14, StorageHasherV13, StorageMetadataV13 } from '../../interfaces/metadata';
|
||||
import type { SiVariant } from '../../interfaces/scaleInfo';
|
||||
import type { OverrideModuleType, Registry } from '../../types';
|
||||
@@ -73,7 +72,7 @@ function makeVariantType (modName: Text, variantType: string, compatTypes: TypeS
|
||||
* @internal
|
||||
* generate & register the OriginCaller type
|
||||
**/
|
||||
function registerOriginCaller (registry: CodecRegistry, modules: ModuleMetadataV13[], metaVersion: number): void {
|
||||
function registerOriginCaller (registry: Registry, modules: ModuleMetadataV13[], metaVersion: number): void {
|
||||
registry.register({
|
||||
OriginCaller: {
|
||||
_enum: modules
|
||||
@@ -127,7 +126,7 @@ function setTypeOverride (sectionTypes: OverrideModuleType, types: Type[]): void
|
||||
* Apply module-specific type overrides (always be done as part of toV14)
|
||||
* @internal
|
||||
**/
|
||||
function convertCalls (compatTypes: TypeSpec[], registry: CodecRegistry, modName: Text, calls: FunctionMetadataV13[], sectionTypes: OverrideModuleType): PalletCallMetadataV14 {
|
||||
function convertCalls (compatTypes: TypeSpec[], registry: Registry, modName: Text, calls: FunctionMetadataV13[], sectionTypes: OverrideModuleType): PalletCallMetadataV14 {
|
||||
const variants = calls.map(({ args, docs, name }, index): SiVariant => {
|
||||
setTypeOverride(sectionTypes, args.map(({ type }) => type));
|
||||
|
||||
@@ -150,7 +149,7 @@ function convertCalls (compatTypes: TypeSpec[], registry: CodecRegistry, modName
|
||||
* Apply module-specific type overrides (always be done as part of toV14)
|
||||
* @internal
|
||||
*/
|
||||
function convertConstants (compatTypes: TypeSpec[], registry: CodecRegistry, constants: ModuleConstantMetadataV13[], sectionTypes: OverrideModuleType): PalletConstantMetadataV14[] {
|
||||
function convertConstants (compatTypes: TypeSpec[], registry: Registry, constants: ModuleConstantMetadataV13[], sectionTypes: OverrideModuleType): PalletConstantMetadataV14[] {
|
||||
return constants.map(({ docs, name, type, value }): PalletConstantMetadataV14 => {
|
||||
setTypeOverride(sectionTypes, [type]);
|
||||
|
||||
@@ -168,7 +167,7 @@ function convertConstants (compatTypes: TypeSpec[], registry: CodecRegistry, con
|
||||
* @internal
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function convertErrors (compatTypes: TypeSpec[], registry: CodecRegistry, modName: Text, errors: ErrorMetadataV13[], _sectionTypes: OverrideModuleType): PalletErrorMetadataV14 {
|
||||
function convertErrors (compatTypes: TypeSpec[], registry: Registry, modName: Text, errors: ErrorMetadataV13[], _sectionTypes: OverrideModuleType): PalletErrorMetadataV14 {
|
||||
const variants = errors.map(({ docs, name }, index): SiVariant =>
|
||||
registry.createTypeUnsafe('SiVariant', [{
|
||||
docs,
|
||||
@@ -187,7 +186,7 @@ function convertErrors (compatTypes: TypeSpec[], registry: CodecRegistry, modNam
|
||||
* Apply module-specific type overrides (always be done as part of toV14)
|
||||
* @internal
|
||||
**/
|
||||
function convertEvents (compatTypes: TypeSpec[], registry: CodecRegistry, modName: Text, events: EventMetadataV13[], sectionTypes: OverrideModuleType): PalletEventMetadataV14 {
|
||||
function convertEvents (compatTypes: TypeSpec[], registry: Registry, modName: Text, events: EventMetadataV13[], sectionTypes: OverrideModuleType): PalletEventMetadataV14 {
|
||||
const variants = events.map(({ args, docs, name }, index): SiVariant => {
|
||||
setTypeOverride(sectionTypes, args);
|
||||
|
||||
@@ -206,7 +205,7 @@ function convertEvents (compatTypes: TypeSpec[], registry: CodecRegistry, modNam
|
||||
}]);
|
||||
}
|
||||
|
||||
function createMapEntry (compatTypes: TypeSpec[], registry: CodecRegistry, sectionTypes: OverrideModuleType, { hashers, keys, value }: MapDef): StorageEntryTypeV14 {
|
||||
function createMapEntry (compatTypes: TypeSpec[], registry: Registry, sectionTypes: OverrideModuleType, { hashers, keys, value }: MapDef): StorageEntryTypeV14 {
|
||||
setTypeOverride(sectionTypes, [value, ...(Array.isArray(keys) ? keys : [keys])]);
|
||||
|
||||
return registry.createTypeUnsafe('StorageEntryTypeV14', [{
|
||||
@@ -224,7 +223,7 @@ function createMapEntry (compatTypes: TypeSpec[], registry: CodecRegistry, secti
|
||||
* Apply module-specific storage type overrides (always part of toV14)
|
||||
* @internal
|
||||
**/
|
||||
function convertStorage (compatTypes: TypeSpec[], registry: CodecRegistry, { items, prefix }: StorageMetadataV13, sectionTypes: OverrideModuleType): PalletStorageMetadataV14 {
|
||||
function convertStorage (compatTypes: TypeSpec[], registry: Registry, { items, prefix }: StorageMetadataV13, sectionTypes: OverrideModuleType): PalletStorageMetadataV14 {
|
||||
return registry.createTypeUnsafe('PalletStorageMetadataV14', [{
|
||||
items: items.map(({ docs, fallback, modifier, name, type }): StorageEntryMetadataV14 => {
|
||||
let entryType: StorageEntryTypeV14;
|
||||
@@ -277,7 +276,7 @@ function convertStorage (compatTypes: TypeSpec[], registry: CodecRegistry, { ite
|
||||
|
||||
/** @internal */
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function convertExtrinsic (registry: CodecRegistry, { signedExtensions, version }: ExtrinsicMetadataV13): ExtrinsicMetadataV14 {
|
||||
function convertExtrinsic (registry: Registry, { signedExtensions, version }: ExtrinsicMetadataV13): ExtrinsicMetadataV14 {
|
||||
return registry.createTypeUnsafe('ExtrinsicMetadataV14', [{
|
||||
signedExtensions: signedExtensions.map((identifier) => ({
|
||||
identifier,
|
||||
@@ -289,8 +288,8 @@ function convertExtrinsic (registry: CodecRegistry, { signedExtensions, version
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function createPallet (compatTypes: TypeSpec[], registry: CodecRegistry, mod: ModuleMetadataV13, { calls, constants, errors, events, storage }: { calls: FunctionMetadataV13[] | null, constants: ModuleConstantMetadataV13[], errors: ErrorMetadataV13[] | null, events: EventMetadataV13[] | null, storage: StorageMetadataV13 | null }): PalletMetadataV14 {
|
||||
const sectionTypes = getAliasTypes(registry as Registry, stringCamelCase(mod.name));
|
||||
function createPallet (compatTypes: TypeSpec[], registry: Registry, mod: ModuleMetadataV13, { calls, constants, errors, events, storage }: { calls: FunctionMetadataV13[] | null, constants: ModuleConstantMetadataV13[], errors: ErrorMetadataV13[] | null, events: EventMetadataV13[] | null, storage: StorageMetadataV13 | null }): PalletMetadataV14 {
|
||||
const sectionTypes = getAliasTypes(registry, stringCamelCase(mod.name));
|
||||
|
||||
return registry.createTypeUnsafe('PalletMetadataV14', [{
|
||||
calls: calls && convertCalls(compatTypes, registry, mod.name, calls, sectionTypes),
|
||||
@@ -307,7 +306,7 @@ function createPallet (compatTypes: TypeSpec[], registry: CodecRegistry, mod: Mo
|
||||
* Convert the Metadata to v14
|
||||
* @internal
|
||||
**/
|
||||
export function toV14 (registry: CodecRegistry, v13: MetadataV13, metaVersion: number): MetadataV14 {
|
||||
export function toV14 (registry: Registry, v13: MetadataV13, metaVersion: number): MetadataV14 {
|
||||
const compatTypes: TypeSpec[] = [];
|
||||
|
||||
compatType(compatTypes, 'Null'); // position 0 always has Null
|
||||
|
||||
@@ -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, MetadataV14 } from '../../interfaces/metadata';
|
||||
|
||||
/**
|
||||
@@ -9,6 +9,6 @@ import type { MetadataLatest, MetadataV14 } from '../../interfaces/metadata';
|
||||
* @internal
|
||||
**/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export function toLatest (registry: CodecRegistry, v14: MetadataV14, _metaVersion: number): MetadataLatest {
|
||||
export function toLatest (registry: Registry, v14: MetadataV14, _metaVersion: number): MetadataLatest {
|
||||
return v14;
|
||||
}
|
||||
|
||||
@@ -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 { MetadataV9, MetadataV10, ModuleMetadataV9, ModuleMetadataV10, StorageEntryMetadataV9, StorageEntryTypeV9, StorageHasherV9, StorageHasherV10 } from '../../interfaces/metadata';
|
||||
|
||||
// migrate a storage hasher type
|
||||
// see https://github.com/paritytech/substrate/pull/4462
|
||||
/** @internal */
|
||||
function createStorageHasher (registry: CodecRegistry, hasher: StorageHasherV9): StorageHasherV10 {
|
||||
function createStorageHasher (registry: Registry, hasher: StorageHasherV9): StorageHasherV10 {
|
||||
// Blake2_128_Concat has been added at index 2, so we increment all the
|
||||
// indexes greater than 2
|
||||
if (hasher.toNumber() >= 2) {
|
||||
@@ -18,7 +18,7 @@ function createStorageHasher (registry: CodecRegistry, hasher: StorageHasherV9):
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function createStorageType (registry: CodecRegistry, entryType: StorageEntryTypeV9): [any, number] {
|
||||
function createStorageType (registry: Registry, entryType: StorageEntryTypeV9): [any, number] {
|
||||
if (entryType.isMap) {
|
||||
return [{
|
||||
...entryType.asMap,
|
||||
@@ -38,7 +38,7 @@ function createStorageType (registry: CodecRegistry, entryType: StorageEntryType
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function convertModule (registry: CodecRegistry, mod: ModuleMetadataV9): ModuleMetadataV10 {
|
||||
function convertModule (registry: Registry, mod: ModuleMetadataV9): ModuleMetadataV10 {
|
||||
const storage = mod.storage.unwrapOr(null);
|
||||
|
||||
return registry.createTypeUnsafe('ModuleMetadataV10', [{
|
||||
@@ -56,7 +56,7 @@ function convertModule (registry: CodecRegistry, mod: ModuleMetadataV9): ModuleM
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function toV10 (registry: CodecRegistry, { modules }: MetadataV9): MetadataV10 {
|
||||
export function toV10 (registry: Registry, { modules }: MetadataV9): MetadataV10 {
|
||||
return registry.createTypeUnsafe('MetadataV10', [{
|
||||
modules: modules.map((mod) => convertModule(registry, mod))
|
||||
}]);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
// Copyright 2017-2022 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { CodecRegistry, IU8a } from '@polkadot/types-codec/types';
|
||||
import type { IU8a, Registry } from '@polkadot/types-codec/types';
|
||||
import type { H256 } from '../interfaces/runtime';
|
||||
|
||||
import { Bytes, Enum } from '@polkadot/types-codec';
|
||||
import { assert, isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
/** @internal */
|
||||
function decodeDataU8a (registry: CodecRegistry, value: Uint8Array): [undefined | Uint8Array, number | undefined] {
|
||||
function decodeDataU8a (registry: Registry, value: Uint8Array): [undefined | Uint8Array, number | undefined] {
|
||||
const indicator = value[0];
|
||||
|
||||
if (!indicator) {
|
||||
@@ -27,7 +27,7 @@ function decodeDataU8a (registry: CodecRegistry, value: Uint8Array): [undefined
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeData (registry: CodecRegistry, value?: Record<string, any> | Uint8Array | Enum | string): [any, number | undefined] {
|
||||
function decodeData (registry: Registry, value?: Record<string, any> | Uint8Array | Enum | string): [any, number | undefined] {
|
||||
if (isU8a(value) || isString(value)) {
|
||||
return decodeDataU8a(registry, u8aToU8a(value));
|
||||
} else if (!value) {
|
||||
@@ -44,7 +44,7 @@ function decodeData (registry: CodecRegistry, value?: Record<string, any> | Uint
|
||||
* A [[Data]] container with node, raw or hashed data
|
||||
*/
|
||||
export class Data extends Enum {
|
||||
constructor (registry: CodecRegistry, value?: Record<string, any> | Uint8Array | Enum | string) {
|
||||
constructor (registry: Registry, value?: Record<string, any> | Uint8Array | Enum | string) {
|
||||
super(registry, {
|
||||
None: 'Null', // 0
|
||||
Raw: 'Bytes', // 1
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
// Copyright 2017-2022 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyJson, AnyTuple, Codec, CodecRegistry, ICompact, INumber } from '@polkadot/types-codec/types';
|
||||
import type { CreateRegistry } from '@polkadot/types-create/types';
|
||||
import type { AnyJson, AnyTuple, Codec, ICompact, INumber } from '@polkadot/types-codec/types';
|
||||
import type { StorageEntryMetadataLatest, StorageEntryTypeLatest, StorageHasher } from '../interfaces/metadata';
|
||||
import type { AllHashers } from '../interfaces/metadata/definitions';
|
||||
import type { SiLookupTypeId } from '../interfaces/scaleInfo';
|
||||
import type { InterfaceTypes, IStorageKey } from '../types';
|
||||
import type { InterfaceTypes, IStorageKey, Registry } from '../types';
|
||||
import type { StorageEntry } from './types';
|
||||
|
||||
import { Bytes } from '@polkadot/types-codec';
|
||||
@@ -44,8 +43,8 @@ export function unwrapStorageSi (type: StorageEntryTypeLatest): SiLookupTypeId {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function unwrapStorageType (registry: CodecRegistry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
|
||||
const outputType = getSiName((registry as CreateRegistry).lookup, unwrapStorageSi(type));
|
||||
export function unwrapStorageType (registry: Registry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
|
||||
const outputType = getSiName((registry).lookup, unwrapStorageSi(type));
|
||||
|
||||
return isOptional
|
||||
? `Option<${outputType}>` as unknown as keyof InterfaceTypes
|
||||
@@ -91,7 +90,7 @@ function decodeStorageKey (value?: string | Uint8Array | StorageKey | StorageEnt
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeHashers <A extends AnyTuple> (registry: CodecRegistry, value: Uint8Array, hashers: [StorageHasher, ICompact<INumber>][]): A {
|
||||
function decodeHashers <A extends AnyTuple> (registry: Registry, value: Uint8Array, hashers: [StorageHasher, ICompact<INumber>][]): A {
|
||||
// the storage entry is xxhashAsU8a(prefix, 128) + xxhashAsU8a(method, 128), 256 bits total
|
||||
let offset = 32;
|
||||
const result = new Array<Codec>(hashers.length);
|
||||
@@ -111,7 +110,7 @@ function decodeHashers <A extends AnyTuple> (registry: CodecRegistry, value: Uin
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeArgsFromMeta <A extends AnyTuple> (registry: CodecRegistry, value: Uint8Array, meta?: StorageEntryMetadataLatest): A {
|
||||
function decodeArgsFromMeta <A extends AnyTuple> (registry: Registry, value: Uint8Array, meta?: StorageEntryMetadataLatest): A {
|
||||
if (!meta || !meta.type.isMap) {
|
||||
return [] as unknown as A;
|
||||
}
|
||||
@@ -119,7 +118,7 @@ function decodeArgsFromMeta <A extends AnyTuple> (registry: CodecRegistry, value
|
||||
const { hashers, key } = meta.type.asMap;
|
||||
const keys = hashers.length === 1
|
||||
? [key]
|
||||
: (registry as CreateRegistry).lookup.getSiType(key).def.asTuple;
|
||||
: (registry).lookup.getSiType(key).def.asTuple;
|
||||
|
||||
return decodeHashers(registry, value, hashers.map((h, i) => [h, keys[i]]));
|
||||
}
|
||||
@@ -140,7 +139,7 @@ function getMeta (value: StorageKey | StorageEntry | [StorageEntry, unknown[]?])
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function getType (registry: CodecRegistry, value: StorageKey | StorageEntry | [StorageEntry, unknown[]?]): string {
|
||||
function getType (registry: Registry, value: StorageKey | StorageEntry | [StorageEntry, unknown[]?]): string {
|
||||
if (value instanceof StorageKey) {
|
||||
return value.outputType;
|
||||
} else if (isFunction(value)) {
|
||||
@@ -176,7 +175,7 @@ export class StorageKey<A extends AnyTuple = AnyTuple> extends Bytes implements
|
||||
|
||||
#section?: string;
|
||||
|
||||
constructor (registry: CodecRegistry, value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?], override: Partial<StorageKeyExtra> = {}) {
|
||||
constructor (registry: Registry, value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?], override: Partial<StorageKeyExtra> = {}) {
|
||||
const { key, method, section } = decodeStorageKey(value);
|
||||
|
||||
super(registry, key);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2017-2022 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Vec } from '@polkadot/types-codec';
|
||||
import type { TypeDef } from '@polkadot/types-create/types';
|
||||
import type { PortableType } from '../interfaces/metadata';
|
||||
import type { SiLookupTypeId, SiType } from '../interfaces/scaleInfo';
|
||||
|
||||
declare module '@polkadot/types-create/types/lookup' {
|
||||
export interface ILookup {
|
||||
readonly names: string[];
|
||||
readonly types: Vec<PortableType>;
|
||||
|
||||
getName (lookupId: SiLookupTypeId | string | number): string | undefined;
|
||||
getSiType (lookupId: SiLookupTypeId | string | number): SiType;
|
||||
getTypeDef (lookupId: SiLookupTypeId | string | number): TypeDef;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// Copyright 2017-2022 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import '@polkadot/types-create/types/augmentRegistry';
|
||||
|
||||
import type { Codec, CodecClass } from '@polkadot/types-codec/types';
|
||||
import type { TypeDef } from '@polkadot/types-create/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ExtDef } from '../extrinsic/signedExtensions/types';
|
||||
import type { MetadataLatest } from '../interfaces/metadata';
|
||||
import type { SiField, SiLookupTypeId } from '../interfaces/scaleInfo';
|
||||
import type { ChainProperties } from '../interfaces/system';
|
||||
import type { Metadata, PortableRegistry } from '../metadata';
|
||||
import type { CallFunction as CallFunctionExt } from './calls';
|
||||
import type { DetectCodec } from './detect';
|
||||
import type { CodecHasher, RegisteredTypes } from './registry';
|
||||
|
||||
declare module '@polkadot/types-codec/types/registry' {
|
||||
export interface RegistryError {
|
||||
fields: SiField[];
|
||||
}
|
||||
|
||||
export interface Registry {
|
||||
// readonly chainDecimals: number[];
|
||||
// readonly chainSS58: number | undefined;
|
||||
// readonly chainTokens: string[];
|
||||
readonly knownTypes: RegisteredTypes;
|
||||
// readonly lookup: PortableRegistry;
|
||||
readonly metadata: MetadataLatest;
|
||||
readonly unknownTypes: string[];
|
||||
readonly signedExtensions: string[];
|
||||
|
||||
// createdAtHash?: Hash;
|
||||
|
||||
findMetaCall (callIndex: Uint8Array): CallFunctionExt;
|
||||
findMetaError (errorIndex: Uint8Array | { error: BN, index: BN }): RegistryError;
|
||||
// due to same circular imports where types don't really want to import from EventData,
|
||||
// keep this as a generic Codec, however the actual impl. returns the correct
|
||||
// findMetaEvent (eventIndex: Uint8Array): CodecClass<any>;
|
||||
|
||||
// isLookupType (value: string): boolean;
|
||||
createLookupType (lookupId: SiLookupTypeId | number): string;
|
||||
|
||||
createClass <T extends Codec = Codec, K extends string = string> (type: K): CodecClass<DetectCodec<T, K>>;
|
||||
createType <T extends Codec = Codec, K extends string = string> (type: K, ...params: unknown[]): DetectCodec<T, K>;
|
||||
|
||||
get <T extends Codec = Codec, K extends string = string> (name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass<DetectCodec<T, K>> | undefined;
|
||||
getChainProperties (): ChainProperties | undefined;
|
||||
// getClassName (clazz: Constructor): string | undefined;
|
||||
getDefinition (typeName: string): string | undefined;
|
||||
getModuleInstances (specName: string, moduleName: string): string[] | undefined;
|
||||
|
||||
// getOrThrow <T extends Codec = Codec, K extends string = string> (name: K, msg?: string): CodecClass<DetectCodec<T, K>>;
|
||||
// getOrUnknown <T extends Codec = Codec, K extends string = string> (name: K): CodecClass<DetectCodec<T, K>>;
|
||||
|
||||
setKnownTypes (types: RegisteredTypes): void;
|
||||
// getSignedExtensionExtra (): Record<string, string>;
|
||||
// getSignedExtensionTypes (): Record<string, string>;
|
||||
|
||||
// hasClass (name: string): boolean;
|
||||
// hasDef (name: string): boolean;
|
||||
// hasType (name: string): boolean;
|
||||
// hash (data: Uint8Array): IU8a;
|
||||
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?: CodecHasher | null): void;
|
||||
setLookup (lookup: PortableRegistry): void;
|
||||
setMetadata (metadata: Metadata, signedExtensions?: string[], userExtensions?: ExtDef): void;
|
||||
setSignedExtensions (signedExtensions?: string[], userExtensions?: ExtDef): void;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
// Copyright 2017-2022 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './augmentLookup';
|
||||
import './augmentRegistry';
|
||||
|
||||
// used inside augmented definitions
|
||||
export type { Observable } from 'rxjs';
|
||||
export * from '@polkadot/types/types/registry';
|
||||
|
||||
@@ -3,24 +3,18 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { BitVec, Bool, bool, Bytes, I8, i8, I16, i16, I32, i32, I64, i64, I128, i128, I256, i256, Json, Null, Raw, Text, Type, U8, u8, U16, u16, U32, u32, U64, u64, U128, u128, U256, u256, USize, usize } from '@polkadot/types-codec';
|
||||
import type { Codec, CodecClass, RegistryError as RegistryErrorBase, RegistryTypes } from '@polkadot/types-codec/types';
|
||||
import type { CreateRegistry, TypeDef } from '@polkadot/types-create/types';
|
||||
import type { RegistryTypes } from '@polkadot/types-codec/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { GenericExtrinsic, GenericExtrinsicEra, GenericExtrinsicPayload, GenericSignerPayload } from '../extrinsic';
|
||||
import type { ExtDef } from '../extrinsic/signedExtensions/types';
|
||||
import type { GenericCall } from '../generic';
|
||||
import type { MetadataLatest } from '../interfaces/metadata';
|
||||
import type { HeaderPartial } from '../interfaces/runtime';
|
||||
import type { SiField, SiLookupTypeId } from '../interfaces/scaleInfo';
|
||||
import type { RuntimeVersionPartial } from '../interfaces/state';
|
||||
import type { ChainProperties } from '../interfaces/system';
|
||||
import type { Metadata, PortableRegistry } from '../metadata';
|
||||
import type { Data, StorageKey } from '../primitive';
|
||||
import type { CallFunction } from './calls';
|
||||
import type { DefinitionRpc, DefinitionRpcSub } from './definitions';
|
||||
import type { DetectCodec } from './detect';
|
||||
|
||||
export type { RegistryTypes } from '@polkadot/types-codec/types';
|
||||
export type { Registry, RegistryError, RegistryTypes } from '@polkadot/types-codec/types';
|
||||
|
||||
export interface InterfaceTypes {
|
||||
// base codec
|
||||
@@ -50,17 +44,6 @@ export interface ChainUpgrades {
|
||||
versions: ChainUpgradeVersion[];
|
||||
}
|
||||
|
||||
export interface RegistryError extends RegistryErrorBase {
|
||||
args: string[];
|
||||
docs: string[];
|
||||
fields: SiField[];
|
||||
index: number;
|
||||
// compat
|
||||
method: string;
|
||||
name: string;
|
||||
section: string;
|
||||
}
|
||||
|
||||
export interface OverrideVersionedType {
|
||||
// min (v >= min) and max (v <= max)
|
||||
minmax: [number | undefined | null, number | undefined | null] | [number?, number?] | (number | undefined | null)[];
|
||||
@@ -115,56 +98,3 @@ export interface RegisteredTypes {
|
||||
*/
|
||||
typesSpec?: Record<string, RegistryTypes>;
|
||||
}
|
||||
|
||||
// Note the commented interfaces here are directly from CodecRegistry
|
||||
export interface Registry extends CreateRegistry {
|
||||
// readonly chainDecimals: number[];
|
||||
// readonly chainSS58: number | undefined;
|
||||
// readonly chainTokens: string[];
|
||||
readonly knownTypes: RegisteredTypes;
|
||||
readonly lookup: PortableRegistry;
|
||||
readonly metadata: MetadataLatest;
|
||||
readonly unknownTypes: string[];
|
||||
readonly signedExtensions: string[];
|
||||
|
||||
// createdAtHash?: Hash;
|
||||
|
||||
findMetaCall (callIndex: Uint8Array): CallFunction;
|
||||
findMetaError (errorIndex: Uint8Array | { error: BN, index: BN }): RegistryError;
|
||||
// due to same circular imports where types don't really want to import from EventData,
|
||||
// keep this as a generic Codec, however the actual impl. returns the correct
|
||||
// findMetaEvent (eventIndex: Uint8Array): CodecClass<any>;
|
||||
|
||||
// isLookupType (value: string): boolean;
|
||||
createLookupType (lookupId: SiLookupTypeId | number): string;
|
||||
|
||||
createClass <T extends Codec = Codec, K extends string = string> (type: K): CodecClass<DetectCodec<T, K>>;
|
||||
createType <T extends Codec = Codec, K extends string = string> (type: K, ...params: unknown[]): DetectCodec<T, K>;
|
||||
|
||||
get <T extends Codec = Codec, K extends string = string> (name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass<DetectCodec<T, K>> | undefined;
|
||||
getChainProperties (): ChainProperties | undefined;
|
||||
// getClassName (clazz: Constructor): string | undefined;
|
||||
getDefinition (typeName: string): string | undefined;
|
||||
getModuleInstances (specName: string, moduleName: string): string[] | undefined;
|
||||
|
||||
// getOrThrow <T extends Codec = Codec, K extends string = string> (name: K, msg?: string): CodecClass<DetectCodec<T, K>>;
|
||||
// getOrUnknown <T extends Codec = Codec, K extends string = string> (name: K): CodecClass<DetectCodec<T, K>>;
|
||||
|
||||
setKnownTypes (types: RegisteredTypes): void;
|
||||
// getSignedExtensionExtra (): Record<string, string>;
|
||||
// getSignedExtensionTypes (): Record<string, string>;
|
||||
|
||||
// hasClass (name: string): boolean;
|
||||
// hasDef (name: string): boolean;
|
||||
// hasType (name: string): boolean;
|
||||
// hash (data: Uint8Array): IU8a;
|
||||
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?: CodecHasher | null): void;
|
||||
setLookup (lookup: PortableRegistry): void;
|
||||
setMetadata (metadata: Metadata, signedExtensions?: string[], userExtensions?: ExtDef): void;
|
||||
setSignedExtensions (signedExtensions?: string[], userExtensions?: ExtDef): void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user