From dd6826fadd2b1c80d74529e8ffd695363838ec22 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 19 Jan 2023 13:54:34 +0200 Subject: [PATCH] Rename Code .registry to .$registry (#5428) * Adapt $registry getter, deprecate registry * warnGet adjustments * Additional adjustments --- packages/api-derive/src/chain/getBlock.ts | 2 +- packages/api-derive/src/chain/getHeader.ts | 2 +- .../api-derive/src/chain/subscribeNewHeads.ts | 2 +- packages/api/src/base/Decorate.ts | 2 +- packages/api/src/submittable/createClass.ts | 6 +-- packages/typegen/src/generate/consts.ts | 2 +- packages/typegen/src/generate/events.ts | 2 +- packages/typegen/src/generate/lookup.ts | 2 +- packages/typegen/src/generate/runtime.ts | 2 +- packages/typegen/src/metadataMd.ts | 2 +- packages/types-codec/src/abstract/Array.ts | 12 +++-- packages/types-codec/src/abstract/Base.ts | 12 +++-- packages/types-codec/src/abstract/Int.ts | 16 ++++--- packages/types-codec/src/base/Compact.ts | 14 +++--- .../types-codec/src/base/DoNotConstruct.ts | 9 +++- packages/types-codec/src/base/Enum.ts | 13 ++++-- packages/types-codec/src/base/Null.ts | 10 +++-- packages/types-codec/src/base/Option.ts | 15 ++++--- packages/types-codec/src/base/Tuple.ts | 4 +- packages/types-codec/src/base/Vec.ts | 4 +- packages/types-codec/src/base/VecFixed.ts | 2 +- packages/types-codec/src/extended/BTreeSet.ts | 13 ++++-- packages/types-codec/src/extended/Map.ts | 13 ++++-- .../src/extended/WrapperKeepOpaque.ts | 2 +- packages/types-codec/src/native/Bool.ts | 11 +++-- packages/types-codec/src/native/Date.ts | 11 +++-- packages/types-codec/src/native/Float.ts | 12 +++-- packages/types-codec/src/native/Json.ts | 11 +++-- packages/types-codec/src/native/Raw.ts | 11 +++-- packages/types-codec/src/native/Set.ts | 11 +++-- packages/types-codec/src/native/Struct.ts | 15 ++++--- packages/types-codec/src/native/Text.ts | 11 +++-- packages/types-codec/src/types/codec.ts | 15 ++++--- packages/types-codec/src/utils/warnGet.ts | 2 +- .../types/src/extrinsic/ExtrinsicPayload.ts | 8 ++-- packages/types/src/extrinsic/SignerPayload.ts | 2 +- .../src/extrinsic/v4/ExtrinsicPayload.ts | 2 +- .../src/extrinsic/v4/ExtrinsicSignature.ts | 16 +++---- packages/types/src/generic/AccountId.ts | 2 +- packages/types/src/generic/AccountIndex.ts | 4 +- packages/types/src/generic/Block.ts | 2 +- packages/types/src/generic/Call.ts | 8 ++-- .../types/src/generic/ConsensusEngineId.ts | 6 +-- packages/types/src/generic/Vote.ts | 2 +- .../types/src/metadata/MetadataVersioned.ts | 8 ++-- .../PortableRegistry/PortableRegistry.ts | 44 +++++++++---------- packages/types/src/primitive/StorageKey.ts | 4 +- 47 files changed, 235 insertions(+), 146 deletions(-) diff --git a/packages/api-derive/src/chain/getBlock.ts b/packages/api-derive/src/chain/getBlock.ts index 70049f5018..dc691e7a12 100644 --- a/packages/api-derive/src/chain/getBlock.ts +++ b/packages/api-derive/src/chain/getBlock.ts @@ -38,7 +38,7 @@ export function getBlock (instanceId: string, api: DeriveApi): (hash: Uint8Array ]) ), map(([signedBlock, events, [, validators, author]]) => - createSignedBlockExtended(events.registry, signedBlock, events, validators, author) + createSignedBlockExtended(events.$registry, signedBlock, events, validators, author) ) ) ); diff --git a/packages/api-derive/src/chain/getHeader.ts b/packages/api-derive/src/chain/getHeader.ts index 56bd1e5b55..28b6a3b526 100644 --- a/packages/api-derive/src/chain/getHeader.ts +++ b/packages/api-derive/src/chain/getHeader.ts @@ -35,7 +35,7 @@ export function getHeader (instanceId: string, api: DeriveApi): (blockHash: Uint getAuthorDetails(header, queryAt) ), map(([header, validators, author]) => - createHeaderExtended((validators || header).registry, header, validators, author) + createHeaderExtended((validators || header).$registry, header, validators, author) ) ) ); diff --git a/packages/api-derive/src/chain/subscribeNewHeads.ts b/packages/api-derive/src/chain/subscribeNewHeads.ts index 090e961f1a..53e6e5b7b5 100644 --- a/packages/api-derive/src/chain/subscribeNewHeads.ts +++ b/packages/api-derive/src/chain/subscribeNewHeads.ts @@ -39,7 +39,7 @@ export function subscribeNewHeads (instanceId: string, api: DeriveApi): () => Ob map(([header, validators, author]): HeaderExtended => { header.$createdAtHash = header.hash; - return createHeaderExtended(header.registry, header, validators, author); + return createHeaderExtended(header.$registry, header, validators, author); }) ) ); diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index 1993f980f5..6610cef2e4 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -712,7 +712,7 @@ export abstract class Decorate extends Events { decorated.sizeAt = decorateMethod((blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable => getQueryAt(blockHash).pipe( switchMap((q) => - this._rpcCore.state.getStorageSize(getArgs(args, q.creator.meta.registry), blockHash)))); + this._rpcCore.state.getStorageSize(getArgs(args, q.creator.meta.$registry), blockHash)))); // .keys() & .entries() only available on map types if (creator.iterKey && creator.meta.type.isMap) { diff --git a/packages/api/src/submittable/createClass.ts b/packages/api/src/submittable/createClass.ts index 5f31808ef2..f1fc6a0119 100644 --- a/packages/api/src/submittable/createClass.ts +++ b/packages/api/src/submittable/createClass.ts @@ -160,7 +160,7 @@ export function createClass ({ api, apiType, blockHas first(), switchMap((signingInfo): Observable => { // setup our options (same way as in signAndSend) - const eraOptions = makeEraOptions(api, this.registry, allOptions, signingInfo); + const eraOptions = makeEraOptions(api, this.$registry, allOptions, signingInfo); const signOptions = makeSignOptions(api, eraOptions, {}); const u8a = this.isSigned ? api.tx(this).signFake(address, signOptions).toU8a() @@ -244,7 +244,7 @@ export function createClass ({ api, apiType, blockHas return api.derive.tx.signingInfo(address, options.nonce, options.era).pipe( first(), mergeMap(async (signingInfo): Promise => { - const eraOptions = makeEraOptions(api, this.registry, options, signingInfo); + const eraOptions = makeEraOptions(api, this.$registry, options, signingInfo); let updateId = -1; if (isKeyringPair(account)) { @@ -316,7 +316,7 @@ export function createClass ({ api, apiType, blockHas throw new Error('No signer specified, either via api.setSigner or via sign options. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.'); } - const payload = this.registry.createTypeUnsafe('SignerPayload', [objectSpread({}, options, { + const payload = this.$registry.createTypeUnsafe('SignerPayload', [objectSpread({}, options, { address, blockNumber: header ? header.number : 0, method: this.method diff --git a/packages/typegen/src/generate/consts.ts b/packages/typegen/src/generate/consts.ts index 907936309c..1e7489197b 100644 --- a/packages/typegen/src/generate/consts.ts +++ b/packages/typegen/src/generate/consts.ts @@ -33,7 +33,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => { return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs); }, {}); - const { lookup, pallets, registry } = meta.asLatest; + const { $registry: registry, lookup, pallets } = meta.asLatest; const modules = pallets .filter(({ constants }) => constants.length > 0) diff --git a/packages/typegen/src/generate/events.ts b/packages/typegen/src/generate/events.ts index 17fcf7ce0a..447dcf1b14 100644 --- a/packages/typegen/src/generate/events.ts +++ b/packages/typegen/src/generate/events.ts @@ -77,7 +77,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => { return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs); }, {}); - const { lookup, pallets, registry } = meta.asLatest; + const { $registry: registry, lookup, pallets } = meta.asLatest; const modules = pallets .filter(({ events }) => events.isSome) .map(({ events, name }) => ({ diff --git a/packages/typegen/src/generate/lookup.ts b/packages/typegen/src/generate/lookup.ts index 577f855bf2..6d92e6be0a 100644 --- a/packages/typegen/src/generate/lookup.ts +++ b/packages/typegen/src/generate/lookup.ts @@ -240,7 +240,7 @@ function generateRegistry (registry: Registry, filtered: [PortableType, TypeDef] function generateLookup (destDir: string, entries: [string, HexString][]): void { entries.reduce((exclude, [subPath, staticMeta]): string[] => { - const { lookup, registry } = initMeta(staticMeta).metadata.asLatest; + const { $registry: registry, lookup } = initMeta(staticMeta).metadata.asLatest; const filtered = getFilteredTypes(lookup, exclude); generateLookupDefs(registry, filtered, destDir, subPath); diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index e6d492488e..e97c3057c9 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -83,7 +83,7 @@ export function generateCallTypes (meta: Metadata, dest: string, extraTypes: Ext // find the system.Version in metadata let apis: Apis | null = null; - const { pallets, registry } = meta.asLatest; + const { $registry: registry, pallets } = meta.asLatest; const sysp = pallets.find(({ name }) => name.eq('System')); if (sysp) { diff --git a/packages/typegen/src/metadataMd.ts b/packages/typegen/src/metadataMd.ts index 86c004f7ec..e55c6c95f3 100644 --- a/packages/typegen/src/metadataMd.ts +++ b/packages/typegen/src/metadataMd.ts @@ -256,7 +256,7 @@ function addConstants ({ lookup, pallets }: MetadataLatest): string { } /** @internal */ -function addStorage ({ lookup, pallets, registry }: MetadataLatest): string { +function addStorage ({ $registry: registry, lookup, pallets }: MetadataLatest): string { const { substrate } = getSubstrateStorage(registry); const moduleSections = pallets .sort(sortByName) diff --git a/packages/types-codec/src/abstract/Array.ts b/packages/types-codec/src/abstract/Array.ts index 1ba8aa73be..10b65e21bb 100644 --- a/packages/types-codec/src/abstract/Array.ts +++ b/packages/types-codec/src/abstract/Array.ts @@ -16,11 +16,10 @@ import { compareArray, warnGet } from '../utils'; * @noInheritDoc */ export abstract class AbstractArray extends Array implements IVec { - readonly registry: Registry; - public $createdAtHash?: IU8a; public $initialU8aLength?: number; public $isStorageFallback?: boolean; + readonly $registry: Registry; /** * @description This ensures that operators such as clice, filter, map, etc. return @@ -33,7 +32,7 @@ export abstract class AbstractArray extends Array implements protected constructor (registry: Registry, length: number) { super(length); - this.registry = registry; + this.$registry = registry; } /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ @@ -56,6 +55,11 @@ export abstract class AbstractArray extends Array implements return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** * @description The length of the value when encoded as a Uint8Array */ @@ -75,7 +79,7 @@ export abstract class AbstractArray extends Array implements * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** diff --git a/packages/types-codec/src/abstract/Base.ts b/packages/types-codec/src/abstract/Base.ts index c0ee09ced5..a539666b65 100644 --- a/packages/types-codec/src/abstract/Base.ts +++ b/packages/types-codec/src/abstract/Base.ts @@ -11,18 +11,17 @@ import { warnGet } from '../utils'; * @description A type extends the Base class, when it holds a value */ export abstract class AbstractBase implements Codec { - readonly registry: Registry; - public $createdAtHash?: IU8a; public $initialU8aLength?: number; public $isStorageFallback?: boolean; + readonly $registry: Registry; readonly #raw: T; protected constructor (registry: Registry, value: T, initialU8aLength?: number) { this.$initialU8aLength = initialU8aLength; this.#raw = value; - this.registry = registry; + this.$registry = registry; } /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ @@ -45,6 +44,11 @@ export abstract class AbstractBase implements Codec { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** * @description The length of the value when encoded as a Uint8Array */ @@ -56,7 +60,7 @@ export abstract class AbstractBase implements Codec { * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } public get inner (): T { diff --git a/packages/types-codec/src/abstract/Int.ts b/packages/types-codec/src/abstract/Int.ts index 4ee277bee1..3ad32dcaa7 100644 --- a/packages/types-codec/src/abstract/Int.ts +++ b/packages/types-codec/src/abstract/Int.ts @@ -74,13 +74,12 @@ function decodeAbstractInt (value: Exclude | Record type === rawType) || []; @@ -267,7 +271,7 @@ export abstract class AbstractInt extends BN implements INumber { // NOTE In the case of balances, which have a special meaning on the UI // and can be interpreted differently, return a specific value for it so // underlying it always matches (no matter which length it actually is) - return this instanceof this.registry.createClassUnsafe('Balance') + return this instanceof this.$registry.createClassUnsafe('Balance') ? 'Balance' : `${this.$isUnsigned ? 'u' : 'i'}${this.bitLength()}`; } diff --git a/packages/types-codec/src/base/Compact.ts b/packages/types-codec/src/base/Compact.ts index 81e6930f35..cfe490721c 100644 --- a/packages/types-codec/src/base/Compact.ts +++ b/packages/types-codec/src/base/Compact.ts @@ -47,17 +47,16 @@ function decodeCompact (registry: Registry, Type: CodecClass< * a number and making the compact representation thereof */ export class Compact implements ICompact { - readonly registry: Registry; - public $createdAtHash?: IU8a; public $initialU8aLength?: number; public $isStorageFallback?: boolean; + readonly $registry: Registry; readonly #Type: CodecClass; readonly #raw: T; constructor (registry: Registry, Type: CodecClass | string, value: Compact | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: Options = {}) { - this.registry = registry; + this.$registry = registry; this.#Type = definition || setDefinition(typeToConstructor(registry, Type)); const [raw, decodedLength] = decodeCompact(registry, this.#Type, value); @@ -86,6 +85,11 @@ export class Compact implements ICompact { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + public static with (Type: CodecClass | string): CodecClass> { let definition: CodecClass | undefined; @@ -111,7 +115,7 @@ export class Compact implements ICompact { * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** @@ -201,7 +205,7 @@ export class Compact implements ICompact { * @description Returns the base runtime type name for this instance */ public toRawType (): string { - return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`; + return `Compact<${this.$registry.getClassName(this.#Type) || this.#raw.toRawType()}>`; } /** diff --git a/packages/types-codec/src/base/DoNotConstruct.ts b/packages/types-codec/src/base/DoNotConstruct.ts index 6e9f2e96c5..9e5bb8e294 100644 --- a/packages/types-codec/src/base/DoNotConstruct.ts +++ b/packages/types-codec/src/base/DoNotConstruct.ts @@ -12,7 +12,7 @@ import { warnGet } from '../utils'; * An unknown type that fails on construction with the type info */ export class DoNotConstruct implements Codec { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; public $isStorageFallback?: boolean; @@ -20,7 +20,7 @@ export class DoNotConstruct implements Codec { #neverError: Error; constructor (registry: Registry, typeName = 'DoNotConstruct') { - this.registry = registry; + this.$registry = registry; this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`); throw this.#neverError; @@ -46,6 +46,11 @@ export class DoNotConstruct implements Codec { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + public static with (typeName?: string): CodecClass { return class extends DoNotConstruct { constructor (registry: Registry) { diff --git a/packages/types-codec/src/base/Enum.ts b/packages/types-codec/src/base/Enum.ts index daf3584f2f..89922e76de 100644 --- a/packages/types-codec/src/base/Enum.ts +++ b/packages/types-codec/src/base/Enum.ts @@ -183,7 +183,7 @@ function decodeEnum (registry: Registry, def: TypesDef, value?: unknown, index?: * an extension to enum where the value type is determined by the actual index. */ export class Enum implements IEnum { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; public $initialU8aLength?: number; @@ -206,7 +206,7 @@ export class Enum implements IEnum { this.$isBasic = isBasic; - this.registry = registry; + this.$registry = registry; this.#def = def; this.#isIndexed = isIndexed; this.#indexes = Object.values(def).map(({ index }) => index); @@ -233,6 +233,11 @@ export class Enum implements IEnum { return warnGet(this, 'initialU8aLength'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** @deprecated Use $isBasic instead. This getter will be removed in a future version */ public get isBasic (): boolean { return warnGet(this, 'isBasic'); @@ -300,7 +305,7 @@ export class Enum implements IEnum { * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** @@ -455,7 +460,7 @@ export class Enum implements IEnum { const entries = Object.entries(this.#def); - return typesToMap(this.registry, entries.reduce<[CodecClass[], string[]]>((out, [key, { Type }], i) => { + return typesToMap(this.$registry, entries.reduce<[CodecClass[], string[]]>((out, [key, { Type }], i) => { out[0][i] = Type; out[1][i] = key; diff --git a/packages/types-codec/src/base/Null.ts b/packages/types-codec/src/base/Null.ts index b6912359b7..5f9ce2bf76 100644 --- a/packages/types-codec/src/base/Null.ts +++ b/packages/types-codec/src/base/Null.ts @@ -14,16 +14,15 @@ import { warnGet } from '../utils'; * Implements a type that does not contain anything (apart from `null`) */ export class Null implements Codec { - readonly registry: Registry; - public $createdAtHash?: IU8a; readonly $encodedLength = 0; public $initialU8aLength = 0; public $isStorageFallback?: boolean; readonly $isEmpty = true; + readonly $registry: Registry; constructor (registry: Registry) { - this.registry = registry; + this.$registry = registry; } /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ @@ -46,6 +45,11 @@ export class Null implements Codec { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** * @description returns a hash of the contents */ diff --git a/packages/types-codec/src/base/Option.ts b/packages/types-codec/src/base/Option.ts index f77f7877c4..08988e82eb 100644 --- a/packages/types-codec/src/base/Option.ts +++ b/packages/types-codec/src/base/Option.ts @@ -66,7 +66,7 @@ function decodeOption (registry: Registry, Type: CodecClass, value?: unknown): C * with a value if/as required/found. */ export class Option implements IOption { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; public $initialU8aLength?: number; @@ -83,7 +83,7 @@ export class Option implements IOption { : new Type(registry, value.subarray(1)) : decodeOption(registry, Type, value); - this.registry = registry; + this.$registry = registry; this.#Type = Type; this.#raw = decoded as T; @@ -112,6 +112,11 @@ export class Option implements IOption { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + public static with (Type: CodecClass | string): CodecClass> { let definition: CodecClass | undefined; @@ -140,7 +145,7 @@ export class Option implements IOption { * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** @@ -238,7 +243,7 @@ export class Option implements IOption { * @description Returns the base runtime type name for this instance */ public toRawType (isBare?: boolean): string { - const wrapped = this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType(); + const wrapped = this.$registry.getClassName(this.#Type) || new this.#Type(this.$registry).toRawType(); return isBare ? wrapped @@ -299,6 +304,6 @@ export class Option implements IOption { public unwrapOrDefault (): T { return this.isSome ? this.unwrap() - : new this.#Type(this.registry); + : new this.#Type(this.$registry); } } diff --git a/packages/types-codec/src/base/Tuple.ts b/packages/types-codec/src/base/Tuple.ts index 5b6a482e20..6a4fd0e7f5 100644 --- a/packages/types-codec/src/base/Tuple.ts +++ b/packages/types-codec/src/base/Tuple.ts @@ -109,7 +109,7 @@ export class Tuple extends AbstractArray implements ITuple { public get Types (): string[] { return this.#Types[1].length ? this.#Types[1] - : this.#Types[0].map((T) => new T(this.registry).toRawType()); + : this.#Types[0].map((T) => new T(this.$registry).toRawType()); } /** @@ -126,7 +126,7 @@ export class Tuple extends AbstractArray implements ITuple { */ public toRawType (): string { const types = this.#Types[0].map((T) => - this.registry.getClassName(T) || new T(this.registry).toRawType() + this.$registry.getClassName(T) || new T(this.$registry).toRawType() ); return `(${types.join(',')})`; diff --git a/packages/types-codec/src/base/Vec.ts b/packages/types-codec/src/base/Vec.ts index 7bb7de5afa..6408e529a7 100644 --- a/packages/types-codec/src/base/Vec.ts +++ b/packages/types-codec/src/base/Vec.ts @@ -115,7 +115,7 @@ export class Vec extends AbstractArray { // convert type first, this removes overhead from the eq const other = _other instanceof this.#Type ? _other - : new this.#Type(this.registry, _other); + : new this.#Type(this.$registry, _other); for (let i = 0; i < this.length; i++) { if (other.eq(this[i])) { @@ -130,6 +130,6 @@ export class Vec extends AbstractArray { * @description Returns the base runtime type name for this instance */ public toRawType (): string { - return `Vec<${this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType()}>`; + return `Vec<${this.$registry.getClassName(this.#Type) || new this.#Type(this.$registry).toRawType()}>`; } } diff --git a/packages/types-codec/src/base/VecFixed.ts b/packages/types-codec/src/base/VecFixed.ts index aef423849d..bedaaff626 100644 --- a/packages/types-codec/src/base/VecFixed.ts +++ b/packages/types-codec/src/base/VecFixed.ts @@ -57,7 +57,7 @@ export class VecFixed extends AbstractArray { * @description The type for the items */ public get Type (): string { - return new this.#Type(this.registry).toRawType(); + return new this.#Type(this.$registry).toRawType(); } /** diff --git a/packages/types-codec/src/extended/BTreeSet.ts b/packages/types-codec/src/extended/BTreeSet.ts index 169774631b..7fbadeb88c 100644 --- a/packages/types-codec/src/extended/BTreeSet.ts +++ b/packages/types-codec/src/extended/BTreeSet.ts @@ -70,7 +70,7 @@ function decodeSet (registry: Registry, valType: CodecClass } export class BTreeSet extends Set implements ISet { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; public $initialU8aLength?: number; @@ -83,7 +83,7 @@ export class BTreeSet extends Set implements ISet super(sortSet(values)); - this.registry = registry; + this.$registry = registry; this.$initialU8aLength = decodedLength; this.#ValClass = ValClass; } @@ -108,6 +108,11 @@ export class BTreeSet extends Set implements ISet return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + public static with (valType: CodecClass | string): CodecClass> { return class extends BTreeSet { constructor (registry: Registry, value?: Uint8Array | string | Set) { @@ -133,7 +138,7 @@ export class BTreeSet extends Set implements ISet * @description Returns a hash of the value */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** @@ -210,7 +215,7 @@ export class BTreeSet extends Set implements ISet * @description Returns the base runtime type name for this instance */ public toRawType (): string { - return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`; + return `BTreeSet<${this.$registry.getClassName(this.#ValClass) || new this.#ValClass(this.$registry).toRawType()}>`; } /** diff --git a/packages/types-codec/src/extended/Map.ts b/packages/types-codec/src/extended/Map.ts index a7677ed9ea..b0b1cb1d88 100644 --- a/packages/types-codec/src/extended/Map.ts +++ b/packages/types-codec/src/extended/Map.ts @@ -94,7 +94,7 @@ function decodeMap (registry: Registry, keyTyp } export class CodecMap extends Map implements IMap { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; public $initialU8aLength?: number; @@ -109,7 +109,7 @@ export class CodecMap extends super(type === 'BTreeMap' ? sortMap(decoded) : decoded); - this.registry = registry; + this.$registry = registry; this.$initialU8aLength = decodedLength; this.#KeyClass = KeyClass; this.#ValClass = ValClass; @@ -136,6 +136,11 @@ export class CodecMap extends return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** * @description The length of the value when encoded as a Uint8Array */ @@ -153,7 +158,7 @@ export class CodecMap extends * @description Returns a hash of the value */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** @@ -245,7 +250,7 @@ export class CodecMap extends * @description Returns the base runtime type name for this instance */ public toRawType (): string { - return `${this.#type}<${this.registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`; + return `${this.#type}<${this.$registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.$registry).toRawType()},${this.$registry.getClassName(this.#ValClass) || new this.#ValClass(this.$registry).toRawType()}>`; } /** diff --git a/packages/types-codec/src/extended/WrapperKeepOpaque.ts b/packages/types-codec/src/extended/WrapperKeepOpaque.ts index c8d572d715..62a3d94e77 100644 --- a/packages/types-codec/src/extended/WrapperKeepOpaque.ts +++ b/packages/types-codec/src/extended/WrapperKeepOpaque.ts @@ -103,7 +103,7 @@ export class WrapperKeepOpaque extends Bytes { * @description Returns the base runtime type name for this instance */ public override toRawType (): string { - return `${this.#opaqueName}<${this.registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.registry).toRawType())}>`; + return `${this.#opaqueName}<${this.$registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.$registry).toRawType())}>`; } /** diff --git a/packages/types-codec/src/native/Bool.ts b/packages/types-codec/src/native/Bool.ts index 722085a5a8..ebe434664a 100644 --- a/packages/types-codec/src/native/Bool.ts +++ b/packages/types-codec/src/native/Bool.ts @@ -15,7 +15,7 @@ import { warnGet } from '../utils'; * @noInheritDoc */ export class bool extends Boolean implements Codec { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; readonly $encodedLength = 1; @@ -31,7 +31,7 @@ export class bool extends Boolean implements Codec { : !!value ); - this.registry = registry; + this.$registry = registry; } /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ @@ -54,11 +54,16 @@ export class bool extends Boolean implements Codec { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** diff --git a/packages/types-codec/src/native/Date.ts b/packages/types-codec/src/native/Date.ts index d0b087aecb..dbbb7f9656 100644 --- a/packages/types-codec/src/native/Date.ts +++ b/packages/types-codec/src/native/Date.ts @@ -36,7 +36,7 @@ function decodeDate (value: CodecDate | Date | AnyNumber): Date { * @noInheritDoc */ export class CodecDate extends Date implements INumber { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; readonly $encodedLength = BITLENGTH / 8; @@ -46,7 +46,7 @@ export class CodecDate extends Date implements INumber { constructor (registry: Registry, value: CodecDate | Date | AnyNumber = 0) { super(decodeDate(value)); - this.registry = registry; + this.$registry = registry; } /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ @@ -69,11 +69,16 @@ export class CodecDate extends Date implements INumber { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** diff --git a/packages/types-codec/src/native/Float.ts b/packages/types-codec/src/native/Float.ts index 09cfd81ba0..6c9bc3708c 100644 --- a/packages/types-codec/src/native/Float.ts +++ b/packages/types-codec/src/native/Float.ts @@ -21,12 +21,11 @@ interface Options { * in some eth_* RPCs */ export class Float extends Number implements IFloat { - readonly registry: Registry; - public $createdAtHash?: IU8a; readonly $encodedLength: number; public $initialU8aLength?: number; public $isStorageFallback?: boolean; + readonly $registry: Registry; readonly #bitLength: 32 | 64; @@ -42,7 +41,7 @@ export class Float extends Number implements IFloat { this.#bitLength = bitLength; this.$encodedLength = bitLength / 8; this.$initialU8aLength = this.$encodedLength; - this.registry = registry; + this.$registry = registry; } /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ @@ -65,6 +64,11 @@ export class Float extends Number implements IFloat { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + public static with (bitLength: 32 | 64): CodecClass { return class extends Float { constructor (registry: Registry, value?: AnyFloat) { @@ -77,7 +81,7 @@ export class Float extends Number implements IFloat { * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** diff --git a/packages/types-codec/src/native/Json.ts b/packages/types-codec/src/native/Json.ts index 6722532790..7adfb65b47 100644 --- a/packages/types-codec/src/native/Json.ts +++ b/packages/types-codec/src/native/Json.ts @@ -22,7 +22,7 @@ function decodeJson (value?: Record | null): [string, any][] { * @noInheritDoc */ export class Json extends Map implements Codec { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; readonly $encodedLength = 0; @@ -34,7 +34,7 @@ export class Json extends Map implements Codec { super(decoded); - this.registry = registry; + this.$registry = registry; objectProperties(this, decoded.map(([k]) => k), (k) => this.get(k)); } @@ -59,11 +59,16 @@ export class Json extends Map implements Codec { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** diff --git a/packages/types-codec/src/native/Raw.ts b/packages/types-codec/src/native/Raw.ts index 3eb9fed3df..1e9190698f 100644 --- a/packages/types-codec/src/native/Raw.ts +++ b/packages/types-codec/src/native/Raw.ts @@ -18,7 +18,7 @@ import { warnGet } from '../utils'; * @noInheritDoc */ export class Raw extends Uint8Array implements IU8a { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; public $initialU8aLength?: number; @@ -35,7 +35,7 @@ export class Raw extends Uint8Array implements IU8a { constructor (registry: Registry, value?: AnyU8a, initialU8aLength?: number) { super(u8aToU8a(value)); - this.registry = registry; + this.$registry = registry; this.$initialU8aLength = initialU8aLength; } @@ -59,6 +59,11 @@ export class Raw extends Uint8Array implements IU8a { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** * @description The length of the value when encoded as a Uint8Array */ @@ -70,7 +75,7 @@ export class Raw extends Uint8Array implements IU8a { * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** diff --git a/packages/types-codec/src/native/Set.ts b/packages/types-codec/src/native/Set.ts index e587c31998..4828ea21be 100644 --- a/packages/types-codec/src/native/Set.ts +++ b/packages/types-codec/src/native/Set.ts @@ -92,7 +92,7 @@ function decodeSet (setValues: SetValues, value: string[] | Set | Uint8A * a bitwise representation of the values. */ export class CodecSet extends Set implements ISet { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; public $initialU8aLength?: number; @@ -104,7 +104,7 @@ export class CodecSet extends Set implements ISet { constructor (registry: Registry, setValues: SetValues, value?: string[] | Set | Uint8Array | BN | number | string, bitLength = 8) { super(decodeSet(setValues, value, bitLength)); - this.registry = registry; + this.$registry = registry; this.#allowed = setValues; this.#byteLength = bitLength / 8; } @@ -129,6 +129,11 @@ export class CodecSet extends Set implements ISet { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + public static with (values: SetValues, bitLength?: number): CodecClass { return class extends CodecSet { static { @@ -161,7 +166,7 @@ export class CodecSet extends Set implements ISet { * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** diff --git a/packages/types-codec/src/native/Struct.ts b/packages/types-codec/src/native/Struct.ts index c71b6481d7..5b501d76a2 100644 --- a/packages/types-codec/src/native/Struct.ts +++ b/packages/types-codec/src/native/Struct.ts @@ -103,7 +103,7 @@ export class Struct< V extends { [K in keyof S]: any } = { [K in keyof S]: any }, // type names, mapped by key, name of Class in S E extends { [K in keyof S]: string } = { [K in keyof S]: string }> extends Map implements IStruct { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; public $initialU8aLength?: number; @@ -123,7 +123,7 @@ export class Struct< super(decoded); this.$initialU8aLength = decodedLength; - this.registry = registry; + this.$registry = registry; this.#jsonMap = jsonMap; this.#Types = typeMap; } @@ -148,6 +148,11 @@ export class Struct< return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + public static with (Types: S, jsonMap?: Map): CodecClass> { let definition: Definition | undefined; @@ -207,7 +212,7 @@ export class Struct< * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** @@ -218,7 +223,7 @@ export class Struct< const [Types, keys] = this.#Types; for (let i = 0; i < keys.length; i++) { - result[keys[i]] = new Types[i](this.registry).toRawType(); + result[keys[i]] = new Types[i](this.$registry).toRawType(); } return result as E; @@ -340,7 +345,7 @@ export class Struct< * @description Returns the base runtime type name for this instance */ public toRawType (): string { - return stringify(typesToMap(this.registry, this.#Types)); + return stringify(typesToMap(this.$registry, this.#Types)); } /** diff --git a/packages/types-codec/src/native/Text.ts b/packages/types-codec/src/native/Text.ts index 4106463fcd..3010cc1613 100644 --- a/packages/types-codec/src/native/Text.ts +++ b/packages/types-codec/src/native/Text.ts @@ -50,7 +50,7 @@ function decodeText (value?: null | AnyString | AnyU8a | { toString: () => strin * @noInheritDoc */ export class Text extends String implements IText { - readonly registry: Registry; + readonly $registry: Registry; public $createdAtHash?: IU8a; public $initialU8aLength?: number; @@ -63,7 +63,7 @@ export class Text extends String implements IText { super(str); - this.registry = registry; + this.$registry = registry; this.$initialU8aLength = decodedLength; } @@ -87,6 +87,11 @@ export class Text extends String implements IText { return warnGet(this, 'isEmpty'); } + /** @deprecated Use $registry instead. This getter will be removed in a future version */ + public get registry (): Registry { + return warnGet(this, 'registry'); + } + /** * @description The length of the value when encoded as a Uint8Array */ @@ -98,7 +103,7 @@ export class Text extends String implements IText { * @description returns a hash of the contents */ public get hash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** diff --git a/packages/types-codec/src/types/codec.ts b/packages/types-codec/src/types/codec.ts index e43828af8d..73c4669cac 100644 --- a/packages/types-codec/src/types/codec.ts +++ b/packages/types-codec/src/types/codec.ts @@ -26,6 +26,9 @@ interface CodecDeprecated { /** @deprecated Use $isEmpty instead. This getter will be removed in a future version. */ readonly isEmpty: boolean; + + /** @deprecated Use $registry instead. This getter will be removed in a future version. */ + readonly registry: Registry; } /** @@ -75,16 +78,18 @@ export interface Codec extends CodecDeprecated { */ $isStorageFallback?: boolean; + /** + * @description + * The type registry associated with this object, as available when this type + * was initially created. + */ + readonly $registry: Registry; + /** * @description Returns a hash of the value */ readonly hash: IU8a; - /** - * @description The registry associated with this object - */ - readonly registry: Registry; - /** * @description Compares the value of the input to see if there is a match */ diff --git a/packages/types-codec/src/utils/warnGet.ts b/packages/types-codec/src/utils/warnGet.ts index 2097895bb5..d7d279ec08 100644 --- a/packages/types-codec/src/utils/warnGet.ts +++ b/packages/types-codec/src/utils/warnGet.ts @@ -1,7 +1,7 @@ // Copyright 2017-2023 @polkadot/types-codec authors & contributors // SPDX-License-Identifier: Apache-2.0 -type Getters = 'createdAtHash' | 'encodedLength' | 'initialU8aLength' | 'isBasic' | 'isEmpty' | 'isNone' | 'isUnsigned'; +type Getters = 'createdAtHash' | 'encodedLength' | 'hash' | 'initialU8aLength' | 'isBasic' | 'isEmpty' | 'isNone' | 'isUnsigned' | 'registry'; const hasWarned: Record = {}; diff --git a/packages/types/src/extrinsic/ExtrinsicPayload.ts b/packages/types/src/extrinsic/ExtrinsicPayload.ts index 2d6fc1a068..c17c9f6426 100644 --- a/packages/types/src/extrinsic/ExtrinsicPayload.ts +++ b/packages/types/src/extrinsic/ExtrinsicPayload.ts @@ -67,7 +67,7 @@ export class GenericExtrinsicPayload extends AbstractBase { */ public get genesisHash (): BlockHash { // NOTE only v3+ - return this.inner.genesisHash || this.registry.createTypeUnsafe('Hash', []); + return this.inner.genesisHash || this.$registry.createTypeUnsafe('Hash', []); } /** @@ -89,7 +89,7 @@ export class GenericExtrinsicPayload extends AbstractBase { */ public get specVersion (): INumber { // NOTE only v3+ - return this.inner.specVersion || this.registry.createTypeUnsafe('u32', []); + return this.inner.specVersion || this.$registry.createTypeUnsafe('u32', []); } /** @@ -97,7 +97,7 @@ export class GenericExtrinsicPayload extends AbstractBase { */ public get tip (): ICompact { // NOTE from v2+ - return this.inner.tip || this.registry.createTypeUnsafe('Compact', []); + return this.inner.tip || this.$registry.createTypeUnsafe('Compact', []); } /** @@ -105,7 +105,7 @@ export class GenericExtrinsicPayload extends AbstractBase { */ public get transactionVersion (): INumber { // NOTE only v4+ - return this.inner.transactionVersion || this.registry.createTypeUnsafe('u32', []); + return this.inner.transactionVersion || this.$registry.createTypeUnsafe('u32', []); } /** diff --git a/packages/types/src/extrinsic/SignerPayload.ts b/packages/types/src/extrinsic/SignerPayload.ts index 6097d5f155..587f03b622 100644 --- a/packages/types/src/extrinsic/SignerPayload.ts +++ b/packages/types/src/extrinsic/SignerPayload.ts @@ -150,7 +150,7 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign public toRaw (): SignerPayloadRaw { const payload = this.toPayload(); const data = u8aToHex( - this.registry + this.$registry .createTypeUnsafe('ExtrinsicPayload', [payload, { version: payload.version }]) // NOTE Explicitly pass the bare flag so the method is encoded un-prefixed (non-decodable, for signing only) .toU8a({ method: true }) diff --git a/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts b/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts index a0654f6e57..379fa971a4 100644 --- a/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts +++ b/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts @@ -116,6 +116,6 @@ export class GenericExtrinsicPayloadV4 extends Struct { // means that the data-as-signed is un-decodable, but is also doesn't need // the extra information, only the pure data (and is not decoded) ... // The same applies to V1..V3, if we have a V5, carry this comment - return sign(this.registry, signerPair, this.toU8a({ method: true }), this.#signOptions); + return sign(this.$registry, signerPair, this.toU8a({ method: true }), this.#signOptions); } } diff --git a/packages/types/src/extrinsic/v4/ExtrinsicSignature.ts b/packages/types/src/extrinsic/v4/ExtrinsicSignature.ts index 0a696cfea0..4eef330c39 100644 --- a/packages/types/src/extrinsic/v4/ExtrinsicSignature.ts +++ b/packages/types/src/extrinsic/v4/ExtrinsicSignature.ts @@ -141,9 +141,9 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig */ public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | HexString, payload: ExtrinsicPayloadValue | Uint8Array | HexString): IExtrinsicSignature { return this._injectSignature( - toAddress(this.registry, signer), - this.registry.createTypeUnsafe('ExtrinsicSignature', [signature]), - new GenericExtrinsicPayloadV4(this.registry, payload) + toAddress(this.$registry, signer), + this.$registry.createTypeUnsafe('ExtrinsicSignature', [signature]), + new GenericExtrinsicPayloadV4(this.$registry, payload) ); } @@ -153,7 +153,7 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig public createPayload (method: Call, options: SignatureOptions): GenericExtrinsicPayloadV4 { const { era, runtimeVersion: { specVersion, transactionVersion } } = options; - return new GenericExtrinsicPayloadV4(this.registry, objectSpread({}, options, { + return new GenericExtrinsicPayloadV4(this.$registry, objectSpread({}, options, { era: era || IMMORTAL_ERA, method: method.toHex(), specVersion, @@ -172,8 +172,8 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig const payload = this.createPayload(method, options); return this._injectSignature( - toAddress(this.registry, account.addressRaw), - this.registry.createTypeUnsafe('ExtrinsicSignature', [payload.sign(account)]), + toAddress(this.$registry, account.addressRaw), + this.$registry.createTypeUnsafe('ExtrinsicSignature', [payload.sign(account)]), payload ); } @@ -189,8 +189,8 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig const payload = this.createPayload(method, options); return this._injectSignature( - toAddress(this.registry, address), - this.registry.createTypeUnsafe('ExtrinsicSignature', [FAKE_SIGNATURE]), + toAddress(this.$registry, address), + this.$registry.createTypeUnsafe('ExtrinsicSignature', [FAKE_SIGNATURE]), payload ); } diff --git a/packages/types/src/generic/AccountId.ts b/packages/types/src/generic/AccountId.ts index 83bcda91aa..247c499c09 100644 --- a/packages/types/src/generic/AccountId.ts +++ b/packages/types/src/generic/AccountId.ts @@ -67,7 +67,7 @@ class BaseAccountId extends U8aFixed { * @description Returns the string representation of the value */ public override toString (): string { - return encodeAddress(this, this.registry.chainSS58); + return encodeAddress(this, this.$registry.chainSS58); } /** diff --git a/packages/types/src/generic/AccountIndex.ts b/packages/types/src/generic/AccountIndex.ts index 9cce6f457b..9ab5791e9c 100644 --- a/packages/types/src/generic/AccountIndex.ts +++ b/packages/types/src/generic/AccountIndex.ts @@ -87,7 +87,7 @@ export class GenericAccountIndex extends u32 { } // convert and compare - return super.eq(this.registry.createTypeUnsafe('AccountIndex', [other])); + return super.eq(this.$registry.createTypeUnsafe('AccountIndex', [other])); } /** @@ -117,7 +117,7 @@ export class GenericAccountIndex extends u32 { public override toString (): string { const length = GenericAccountIndex.calcLength(this); - return encodeAddress(this.toU8a().subarray(0, length), this.registry.chainSS58); + return encodeAddress(this.toU8a().subarray(0, length), this.$registry.chainSS58); } /** diff --git a/packages/types/src/generic/Block.ts b/packages/types/src/generic/Block.ts index aaf4dda287..80bb0a25b3 100644 --- a/packages/types/src/generic/Block.ts +++ b/packages/types/src/generic/Block.ts @@ -39,7 +39,7 @@ export class GenericBlock extends Struct { * @description Encodes a content [[Hash]] for the block */ public get contentHash (): IU8a { - return this.registry.hash(this.toU8a()); + return this.$registry.hash(this.toU8a()); } /** diff --git a/packages/types/src/generic/Call.ts b/packages/types/src/generic/Call.ts index ef13bafb48..54dbbf8e2c 100644 --- a/packages/types/src/generic/Call.ts +++ b/packages/types/src/generic/Call.ts @@ -158,7 +158,7 @@ export class GenericCall extends Struct implement * @description The argument definitions */ public get argsDef (): ArgsDef { - return getArgsDef(this.registry, this.meta); + return getArgsDef(this.$registry, this.meta); } /** @@ -193,14 +193,14 @@ export class GenericCall extends Struct implement * @description Returns the name of the method */ public get method (): string { - return this.registry.findMetaCall(this.callIndex).method; + return this.$registry.findMetaCall(this.callIndex).method; } /** * @description Returns the module containing the method */ public get section (): string { - return this.registry.findMetaCall(this.callIndex).section; + return this.$registry.findMetaCall(this.callIndex).section; } /** @@ -217,7 +217,7 @@ export class GenericCall extends Struct implement let call: CallFunction | undefined; try { - call = this.registry.findMetaCall(this.callIndex); + call = this.$registry.findMetaCall(this.callIndex); } catch (error) { // swallow } diff --git a/packages/types/src/generic/ConsensusEngineId.ts b/packages/types/src/generic/ConsensusEngineId.ts index 4c8fbe319f..48c271bd1a 100644 --- a/packages/types/src/generic/ConsensusEngineId.ts +++ b/packages/types/src/generic/ConsensusEngineId.ts @@ -83,15 +83,15 @@ export class GenericConsensusEngineId extends U8aFixed { public extractAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId | undefined { if (sessionValidators?.length) { if (this.isAura) { - return getAuraAuthor(this.registry, bytes, sessionValidators); + return getAuraAuthor(this.$registry, bytes, sessionValidators); } else if (this.isBabe) { - return getBabeAuthor(this.registry, bytes, sessionValidators); + return getBabeAuthor(this.$registry, bytes, sessionValidators); } } // For pow & Moonbeam, the bytes are the actual author if (this.isPow || bytes.length === 20) { - return getBytesAsAuthor(this.registry, bytes); + return getBytesAsAuthor(this.$registry, bytes); } return undefined; diff --git a/packages/types/src/generic/Vote.ts b/packages/types/src/generic/Vote.ts index 21a8abf984..2c9ea78b17 100644 --- a/packages/types/src/generic/Vote.ts +++ b/packages/types/src/generic/Vote.ts @@ -80,7 +80,7 @@ export class GenericVote extends U8aFixed { super(registry, decoded, 8); this.#aye = (decoded[0] & AYE_BITS) === AYE_BITS; - this.#conviction = this.registry.createTypeUnsafe('Conviction', [decoded[0] & CON_MASK]); + this.#conviction = this.$registry.createTypeUnsafe('Conviction', [decoded[0] & CON_MASK]); } /** diff --git a/packages/types/src/metadata/MetadataVersioned.ts b/packages/types/src/metadata/MetadataVersioned.ts index 19e61c9798..94aef281fa 100644 --- a/packages/types/src/metadata/MetadataVersioned.ts +++ b/packages/types/src/metadata/MetadataVersioned.ts @@ -65,7 +65,7 @@ export class MetadataVersioned extends Struct { } if (!this.#converted.has(version)) { - this.#converted.set(version, fromPrev(this.registry, this[asPrev] as F, this.version)); + this.#converted.set(version, fromPrev(this.$registry, this[asPrev] as F, this.version)); } return this.#converted.get(version) as T; @@ -82,9 +82,9 @@ export class MetadataVersioned extends Struct { * @description Returns the wrapped metadata as a limited calls-only (latest) version */ public get asCallsOnly (): MetadataVersioned { - return new MetadataVersioned(this.registry, { + return new MetadataVersioned(this.$registry, { magicNumber: this.magicNumber, - metadata: this.registry.createTypeUnsafe('MetadataAll', [toCallsOnly(this.registry, this.asLatest), LATEST_VERSION]) + metadata: this.$registry.createTypeUnsafe('MetadataAll', [toCallsOnly(this.$registry, this.asLatest), LATEST_VERSION]) }); } @@ -154,7 +154,7 @@ export class MetadataVersioned extends Struct { } public getUniqTypes (throwError: boolean): string[] { - return getUniqTypes(this.registry, this.asLatest, throwError); + return getUniqTypes(this.$registry, this.asLatest, throwError); } /** diff --git a/packages/types/src/metadata/PortableRegistry/PortableRegistry.ts b/packages/types/src/metadata/PortableRegistry/PortableRegistry.ts index ef59b0468d..f7f9fdda20 100644 --- a/packages/types/src/metadata/PortableRegistry/PortableRegistry.ts +++ b/packages/types/src/metadata/PortableRegistry/PortableRegistry.ts @@ -388,7 +388,7 @@ function removeDupeNames (lookup: PortableRegistry, portable: PortableType[], na /** @internal */ function registerTypes (lookup: PortableRegistry, lookups: Record, names: Record, params: Record): void { // Register the types we extracted - lookup.registry.register(lookups); + lookup.$registry.register(lookups); // Try and extract the AccountId/Address/Signature type from UncheckedExtrinsic if (params.SpRuntimeUncheckedExtrinsic) { @@ -408,7 +408,7 @@ function registerTypes (lookup: PortableRegistry, lookups: Record], where length <= 2048'); } - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.VecFixed, length, sub: this.#createSiDef(type) @@ -735,7 +735,7 @@ export class PortableRegistry extends Struct implements ILookup { } #extractCompact (_: number, { type }: SiTypeDefCompact): TypeDef { - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.Compact, sub: this.#createSiDef(type) }); @@ -751,7 +751,7 @@ export class PortableRegistry extends Struct implements ILookup { throw new Error(`BTreeMap requires 2 parameters, found ${params.length}`); } - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.BTreeMap, sub: params.map(({ type }) => this.#createSiDef(type.unwrap())) }); @@ -760,7 +760,7 @@ export class PortableRegistry extends Struct implements ILookup { throw new Error(`BTreeSet requires 1 parameter, found ${params.length}`); } - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.BTreeSet, sub: this.#createSiDef(params[0].type.unwrap()) }); @@ -769,7 +769,7 @@ export class PortableRegistry extends Struct implements ILookup { throw new Error(`Range requires 1 parameter, found ${params.length}`); } - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: pathFirst === 'Range' ? TypeDefInfo.Range : TypeDefInfo.RangeInclusive, @@ -781,7 +781,7 @@ export class PortableRegistry extends Struct implements ILookup { throw new Error(`WrapperOpaque requires 1 parameter, found ${params.length}`); } - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: pathLast === 'WrapperKeepOpaque' ? TypeDefInfo.WrapperKeepOpaque : TypeDefInfo.WrapperOpaque, @@ -801,9 +801,9 @@ export class PortableRegistry extends Struct implements ILookup { throw new Error('Set handling expects param/field as single entries'); } - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.Set, - length: this.registry.createTypeUnsafe(this.registry.createLookupType(fields[0].type), []).bitLength(), + length: this.$registry.createTypeUnsafe(this.$registry.createLookupType(fields[0].type), []).bitLength(), sub: this.getSiType(params[0].type.unwrap()).def.asVariant.variants.map(({ index, name }): TypeDef => ({ // This will be an issue > 2^53 - 1 ... don't have those (yet) index: index.toNumber(), @@ -855,7 +855,7 @@ export class PortableRegistry extends Struct implements ILookup { const [sub, alias] = this.#extractFieldsAlias(fields); - return withTypeString(this.registry, objectSpread( + return withTypeString(this.$registry, objectSpread( { info: isTuple // Tuple check first ? TypeDefInfo.Tuple @@ -940,7 +940,7 @@ export class PortableRegistry extends Struct implements ILookup { }; } - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.Vec, lookupIndex, lookupName: this.#names[lookupIndex], @@ -960,7 +960,7 @@ export class PortableRegistry extends Struct implements ILookup { const sub = ids.map((t) => this.#createSiDef(t)); - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.Tuple, lookupIndex, lookupName: this.#names[lookupIndex], @@ -979,13 +979,13 @@ export class PortableRegistry extends Struct implements ILookup { // NOTE This is opt-in (unhandled), not by default // if (sub.type === 'bool') { - // return withTypeString(this.registry, { + // return withTypeString(this.$registry, { // info: TypeDefInfo.Plain, // type: 'OptionBool' // }); // } - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.Option, sub: this.#createSiDef(params[0].type.unwrap()) }); @@ -994,7 +994,7 @@ export class PortableRegistry extends Struct implements ILookup { throw new Error(`Result requires 2 parameters, found ${params.length}`); } - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.Result, sub: params.map(({ type }, index) => objectSpread({ @@ -1043,7 +1043,7 @@ export class PortableRegistry extends Struct implements ILookup { ); }); - return withTypeString(this.registry, { + return withTypeString(this.$registry, { info: TypeDefInfo.Enum, lookupIndex, lookupName: this.#names[lookupIndex], diff --git a/packages/types/src/primitive/StorageKey.ts b/packages/types/src/primitive/StorageKey.ts index 5c9f3fdf6f..07a09d19e5 100644 --- a/packages/types/src/primitive/StorageKey.ts +++ b/packages/types/src/primitive/StorageKey.ts @@ -236,11 +236,11 @@ export class StorageKey extends Bytes implements this.#section = section || this.#section; if (meta) { - this.#outputType = unwrapStorageType(this.registry, meta.type); + this.#outputType = unwrapStorageType(this.$registry, meta.type); } try { - this.#args = decodeArgsFromMeta(this.registry, this.toU8a(true), meta); + this.#args = decodeArgsFromMeta(this.$registry, this.toU8a(true), meta); } catch (error) { // ignore... }