diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c03a72d89..395afa4f29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,9 @@ ## master -- **Breaking change** The `Codec.inspect()` call has been renamed to `Codec.inspectU8a()`. This should not only have a minor impact on (very limited) users since the functionality is not used in general operation, but rather only in specialized tools that wish the inspect the actual bytes encoding. - Changes: -- Add `$isStorageFallback` on the `Codec` interface. (`true` if entry was created from a metadata fallback value from an empty storage item) -- Prefix `isEmpty/initialU8aLength/createdAtHash` with `$` on the `Codec` interface, e.g. `$isEmpty`. (The original interface getters has been marked as deprecated, aill warn, but is available) -- Rename `inspect()` to `inspectU8a()` on `Codec` interfaces +- Add `isStorageFallback` on the `Codec` interface. (`true` if entry was created from a metadata fallback value from an empty storage item) ## 9.11.3 Jan 15, 2023 diff --git a/packages/api-contract/src/Abi/index.ts b/packages/api-contract/src/Abi/index.ts index a57dc0aaec..84774123b2 100644 --- a/packages/api-contract/src/Abi/index.ts +++ b/packages/api-contract/src/Abi/index.ts @@ -76,17 +76,11 @@ function parseJson (json: Record, chainProperties?: ChainProper export class Abi { readonly events: AbiEvent[]; - readonly constructors: AbiConstructor[]; - readonly info: ContractProjectInfo; - readonly json: Record; - readonly messages: AbiMessage[]; - readonly metadata: ContractMetadataLatest; - readonly registry: Registry; constructor (abiJson: Record | string, chainProperties?: ChainProperties) { @@ -239,7 +233,7 @@ export class Abi { return args.map(({ type: { lookupName, type } }): Codec => { const value = this.registry.createType(lookupName || type, data.subarray(offset)); - offset += value.$encodedLength; + offset += value.encodedLength; return value; }); diff --git a/packages/api-contract/src/base/Base.ts b/packages/api-contract/src/base/Base.ts index 95c810ae21..2ce70f194d 100644 --- a/packages/api-contract/src/base/Base.ts +++ b/packages/api-contract/src/base/Base.ts @@ -12,11 +12,9 @@ import { Abi } from '../Abi'; export abstract class Base { readonly abi: Abi; - readonly api: ApiBase; protected readonly _decorateMethod: DecorateMethod; - protected readonly _isWeightV1: boolean; constructor (api: ApiBase, abi: string | Record | Abi, decorateMethod: DecorateMethod) { diff --git a/packages/api-derive/src/balances/account.ts b/packages/api-derive/src/balances/account.ts index 9117d1ac10..2f39ea7e32 100644 --- a/packages/api-derive/src/balances/account.ts +++ b/packages/api-derive/src/balances/account.ts @@ -116,7 +116,7 @@ function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable - 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 28b6a3b526..56bd1e5b55 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/subscribeFinalizedBlocks.ts b/packages/api-derive/src/chain/subscribeFinalizedBlocks.ts index ddd3026ac8..ef6a099af1 100644 --- a/packages/api-derive/src/chain/subscribeFinalizedBlocks.ts +++ b/packages/api-derive/src/chain/subscribeFinalizedBlocks.ts @@ -17,7 +17,7 @@ export function subscribeFinalizedBlocks (instanceId: string, api: DeriveApi): ( return memo(instanceId, (): Observable => api.derive.chain.subscribeFinalizedHeads().pipe( switchMap((header) => - api.derive.chain.getBlock(header.$createdAtHash || header.hash) + api.derive.chain.getBlock(header.createdAtHash || header.hash) ) ) ); diff --git a/packages/api-derive/src/chain/subscribeFinalizedHeads.ts b/packages/api-derive/src/chain/subscribeFinalizedHeads.ts index 4e72d39621..d7f03d7dc4 100644 --- a/packages/api-derive/src/chain/subscribeFinalizedHeads.ts +++ b/packages/api-derive/src/chain/subscribeFinalizedHeads.ts @@ -41,7 +41,7 @@ export function subscribeFinalizedHeads (instanceId: string, api: DeriveApi): () const endHash = prevHash; const startHash = header.parentHash; - prevHash = header.$createdAtHash = header.hash; + prevHash = header.createdAtHash = header.hash; return endHash === null || startHash.eq(endHash) ? of(header) diff --git a/packages/api-derive/src/chain/subscribeNewBlocks.ts b/packages/api-derive/src/chain/subscribeNewBlocks.ts index b0165431eb..43047f057c 100644 --- a/packages/api-derive/src/chain/subscribeNewBlocks.ts +++ b/packages/api-derive/src/chain/subscribeNewBlocks.ts @@ -17,7 +17,7 @@ export function subscribeNewBlocks (instanceId: string, api: DeriveApi): () => O return memo(instanceId, (): Observable => api.derive.chain.subscribeNewHeads().pipe( switchMap((header) => - api.derive.chain.getBlock(header.$createdAtHash || header.hash) + api.derive.chain.getBlock(header.createdAtHash || header.hash) ) ) ); diff --git a/packages/api-derive/src/chain/subscribeNewHeads.ts b/packages/api-derive/src/chain/subscribeNewHeads.ts index 53e6e5b7b5..290d457945 100644 --- a/packages/api-derive/src/chain/subscribeNewHeads.ts +++ b/packages/api-derive/src/chain/subscribeNewHeads.ts @@ -37,9 +37,9 @@ export function subscribeNewHeads (instanceId: string, api: DeriveApi): () => Ob getAuthorDetails(header, queryAt) ), map(([header, validators, author]): HeaderExtended => { - header.$createdAtHash = header.hash; + header.createdAtHash = header.hash; - return createHeaderExtended(header.$registry, header, validators, author); + return createHeaderExtended(header.registry, header, validators, author); }) ) ); diff --git a/packages/api-derive/src/crowdloan/contributions.ts b/packages/api-derive/src/crowdloan/contributions.ts index fb67e31228..1243317599 100644 --- a/packages/api-derive/src/crowdloan/contributions.ts +++ b/packages/api-derive/src/crowdloan/contributions.ts @@ -33,7 +33,7 @@ function _getUpdates (api: DeriveApi, paraId: string | number | BN): Observable< added = added.concat(...changes.added); removed = removed.concat(...changes.removed); - return of({ added, addedDelta: changes.added, blockHash: events.$createdAtHash?.toHex() || '-', removed, removedDelta: changes.removed }); + return of({ added, addedDelta: changes.added, blockHash: events.createdAtHash?.toHex() || '-', removed, removedDelta: changes.removed }); } return EMPTY; @@ -52,7 +52,7 @@ function _eventTriggerAll (api: DeriveApi, paraId: string | number | BN): Observ ); return items.length - ? of(events.$createdAtHash?.toHex() || '-') + ? of(events.createdAtHash?.toHex() || '-') : EMPTY; }), startWith('-') diff --git a/packages/api-derive/src/crowdloan/util.ts b/packages/api-derive/src/crowdloan/util.ts index 88c8291e1e..b4ce5e71e9 100644 --- a/packages/api-derive/src/crowdloan/util.ts +++ b/packages/api-derive/src/crowdloan/util.ts @@ -29,5 +29,5 @@ export function extractContributed (paraId: string | number | BN, events: Vec, Balance]> | ITuple function parse ([proposals, images, optDepositors]: Result): DeriveProposal[] { return proposals .filter(([, , proposer], index): boolean => - !!(optDepositors[index]?.isSome) && !proposer.$isEmpty + !!(optDepositors[index]?.isSome) && !proposer.isEmpty ) .map(([index, hash, proposer], proposalIndex): DeriveProposal => { const depositors = optDepositors[proposalIndex].unwrap(); diff --git a/packages/api-derive/src/imOnline/receivedHeartbeats.ts b/packages/api-derive/src/imOnline/receivedHeartbeats.ts index beadda6220..1decaad614 100644 --- a/packages/api-derive/src/imOnline/receivedHeartbeats.ts +++ b/packages/api-derive/src/imOnline/receivedHeartbeats.ts @@ -19,7 +19,7 @@ function mapResult ([result, validators, heartbeats, numBlocks]: [DeriveHeartbea validators.forEach((validator, index): void => { const validatorId = validator.toString(); const blockCount = numBlocks[index]; - const hasMessage = !heartbeats[index].$isEmpty; + const hasMessage = !heartbeats[index].isEmpty; const prev = result[validatorId]; if (!prev || prev.hasMessage !== hasMessage || !prev.blockCount.eq(blockCount)) { diff --git a/packages/api-derive/src/tx/signingInfo.ts b/packages/api-derive/src/tx/signingInfo.ts index 64c7ec07dd..597518413d 100644 --- a/packages/api-derive/src/tx/signingInfo.ts +++ b/packages/api-derive/src/tx/signingInfo.ts @@ -37,7 +37,7 @@ function signingHeader (api: DeriveApi): Observable
{ switchMap((header) => // check for chains at genesis (until block 1 is produced, e.g. 6s), since // we do need to allow transactions at chain start (also dev/seal chains) - header.parentHash.$isEmpty + header.parentHash.isEmpty ? of(header) // in the case of the current block, we use the parent to minimize the // impact of forks on the system, but not completely remove it diff --git a/packages/api-derive/src/type/HeaderExtended.ts b/packages/api-derive/src/type/HeaderExtended.ts index b9f7d57754..d1497f3cfa 100644 --- a/packages/api-derive/src/type/HeaderExtended.ts +++ b/packages/api-derive/src/type/HeaderExtended.ts @@ -18,7 +18,7 @@ export function createHeaderExtended (registry: Registry, header?: Header, valid super(registry, header); this.#author = author || extractAuthor(this.digest, validators || []); - this.$createdAtHash = header?.$createdAtHash; + this.createdAtHash = header?.createdAtHash; } /** diff --git a/packages/api-derive/src/type/SignedBlockExtended.ts b/packages/api-derive/src/type/SignedBlockExtended.ts index 175277ed4f..ce4d9b5a49 100644 --- a/packages/api-derive/src/type/SignedBlockExtended.ts +++ b/packages/api-derive/src/type/SignedBlockExtended.ts @@ -46,7 +46,7 @@ export function createSignedBlockExtended (registry: Registry, block?: SignedBlo this.#author = author || extractAuthor(this.block.header.digest, validators || []); this.#events = events || ([] as EventRecord[]); this.#extrinsics = mapExtrinsics(this.block.extrinsics, this.#events); - this.$createdAtHash = block?.$createdAtHash; + this.createdAtHash = block?.createdAtHash; } /** diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index 6610cef2e4..1993f980f5 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/base/Init.ts b/packages/api/src/base/Init.ts index 093817e54e..fe2dd90385 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -196,7 +196,7 @@ export abstract class Init extends Decorate { : await firstValueFrom(this._rpcCore.chain.getHeader.raw(blockHash)) ); - if (header.parentHash.$isEmpty) { + if (header.parentHash.isEmpty) { throw new Error('Unable to retrieve header and parent from supplied hash'); } diff --git a/packages/api/src/submittable/createClass.ts b/packages/api/src/submittable/createClass.ts index f1fc6a0119..5f31808ef2 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 1e7489197b..907936309c 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 { $registry: registry, lookup, pallets } = meta.asLatest; + const { lookup, pallets, registry } = 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 447dcf1b14..17fcf7ce0a 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 { $registry: registry, lookup, pallets } = meta.asLatest; + const { lookup, pallets, registry } = 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 6d92e6be0a..577f855bf2 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 { $registry: registry, lookup } = initMeta(staticMeta).metadata.asLatest; + const { lookup, registry } = 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 e97c3057c9..e6d492488e 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 { $registry: registry, pallets } = meta.asLatest; + const { pallets, registry } = 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 e55c6c95f3..a76e9fc44a 100644 --- a/packages/typegen/src/metadataMd.ts +++ b/packages/typegen/src/metadataMd.ts @@ -232,7 +232,7 @@ function addConstants ({ lookup, pallets }: MetadataLatest): string { description: DESC_CONSTANTS, sections: pallets .sort(sortByName) - .filter(({ constants }) => !constants.$isEmpty) + .filter(({ constants }) => !constants.isEmpty) .map(({ constants, name }) => { const sectionName = stringLowerFirst(name); @@ -256,7 +256,7 @@ function addConstants ({ lookup, pallets }: MetadataLatest): string { } /** @internal */ -function addStorage ({ $registry: registry, lookup, pallets }: MetadataLatest): string { +function addStorage ({ lookup, pallets, registry }: MetadataLatest): string { const { substrate } = getSubstrateStorage(registry); const moduleSections = pallets .sort(sortByName) diff --git a/packages/typegen/src/util/derived.ts b/packages/typegen/src/util/derived.ts index dc47896f3c..fea45fe6a6 100644 --- a/packages/typegen/src/util/derived.ts +++ b/packages/typegen/src/util/derived.ts @@ -67,10 +67,10 @@ export function getSimilarTypes (registry: Registry, definitions: Record !v.startsWith('__Unused')); - if ($isBasic) { + if (isBasic) { possibleTypes.push(arrayToStrType(keys), 'number'); } else { // TODO We don't really want any here, these should be expanded diff --git a/packages/types-codec/src/abstract/Array.ts b/packages/types-codec/src/abstract/Array.ts index 10b65e21bb..1d8dce626f 100644 --- a/packages/types-codec/src/abstract/Array.ts +++ b/packages/types-codec/src/abstract/Array.ts @@ -6,7 +6,7 @@ import type { AnyJson, Codec, Inspect, IU8a, IVec, Registry } from '../types'; import { compactToU8a, u8aConcatStrict, u8aToHex } from '@polkadot/util'; -import { compareArray, warnGet } from '../utils'; +import { compareArray } from '../utils/compareArray'; /** * @name AbstractArray @@ -16,10 +16,11 @@ import { compareArray, warnGet } from '../utils'; * @noInheritDoc */ export abstract class AbstractArray extends Array implements IVec { - public $createdAtHash?: IU8a; - public $initialU8aLength?: number; - public $isStorageFallback?: boolean; - readonly $registry: Registry; + readonly registry: Registry; + + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; /** * @description This ensures that operators such as clice, filter, map, etc. return @@ -32,44 +33,19 @@ export abstract class AbstractArray extends Array implements protected constructor (registry: Registry, length: number) { super(length); - this.$registry = registry; - } - - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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'); + this.registry = registry; } /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { // We need to loop through all entries since they may have a variable length themselves, // e.g. when a Vec or Compact is contained withing, it has a variable length based on data let total = compactToU8a(this.length).length; for (let i = 0; i < this.length; i++) { - total += this[i].$encodedLength; + total += this[i].encodedLength; } return total; @@ -79,13 +55,13 @@ 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()); } /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return this.length === 0; } @@ -107,7 +83,7 @@ export abstract class AbstractArray extends Array implements /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { return { inner: this.inspectInner(), outer: [compactToU8a(this.length)] @@ -118,7 +94,7 @@ export abstract class AbstractArray extends Array implements const inner = new Array(this.length); for (let i = 0; i < this.length; i++) { - inner[i] = this[i].inspectU8a(); + inner[i] = this[i].inspect(); } return inner; diff --git a/packages/types-codec/src/abstract/Base.ts b/packages/types-codec/src/abstract/Base.ts index a539666b65..ea904c48fe 100644 --- a/packages/types-codec/src/abstract/Base.ts +++ b/packages/types-codec/src/abstract/Base.ts @@ -4,55 +4,29 @@ import type { HexString } from '@polkadot/util/types'; import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types'; -import { warnGet } from '../utils'; - /** * @name Base * @description A type extends the Base class, when it holds a value */ export abstract class AbstractBase implements Codec { - public $createdAtHash?: IU8a; - public $initialU8aLength?: number; - public $isStorageFallback?: boolean; - readonly $registry: Registry; + readonly registry: Registry; + + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; readonly #raw: T; protected constructor (registry: Registry, value: T, initialU8aLength?: number) { - this.$initialU8aLength = initialU8aLength; + this.initialU8aLength = initialU8aLength; this.#raw = value; - this.$registry = registry; - } - - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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'); + this.registry = registry; } /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { return this.toU8a().length; } @@ -60,7 +34,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 { @@ -70,8 +44,8 @@ export abstract class AbstractBase implements Codec { /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { - return this.#raw.$isEmpty; + public get isEmpty (): boolean { + return this.#raw.isEmpty; } /** @@ -84,8 +58,8 @@ export abstract class AbstractBase implements Codec { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { - return this.#raw.inspectU8a(); + public inspect (): Inspect { + return this.#raw.inspect(); } /** diff --git a/packages/types-codec/src/abstract/Int.ts b/packages/types-codec/src/abstract/Int.ts index 3ad32dcaa7..e00217e0f5 100644 --- a/packages/types-codec/src/abstract/Int.ts +++ b/packages/types-codec/src/abstract/Int.ts @@ -6,8 +6,6 @@ import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isFunction, isHex, isNumber, isObject, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util'; -import { warnGet } from '../utils'; - export const DEFAULT_UINT_BITS = 64; // Maximum allowed integer for JS is 2^53 - 1, set limit at 52 @@ -74,12 +72,13 @@ function decodeAbstractInt (value: Exclude | Record type === rawType) || []; @@ -271,9 +241,9 @@ 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()}`; + : `${this.isUnsigned ? 'u' : 'i'}${this.bitLength()}`; } /** @@ -294,7 +264,7 @@ export abstract class AbstractInt extends BN implements INumber { return bnToU8a(this, { bitLength: this.bitLength(), isLe: true, - isNegative: !this.$isUnsigned + isNegative: !this.isUnsigned }); } } diff --git a/packages/types-codec/src/base/Compact.spec.ts b/packages/types-codec/src/base/Compact.spec.ts index 9d2b686a77..00d3e32a37 100644 --- a/packages/types-codec/src/base/Compact.spec.ts +++ b/packages/types-codec/src/base/Compact.spec.ts @@ -12,18 +12,6 @@ const CompactU32 = Compact.with(U32); describe('Compact', (): void => { const registry = new TypeRegistry(); - describe('@deprecated', (): void => { - it('warns on createdAtHash usage', () => { - // eslint-disable-next-line deprecation/deprecation - expect(new Compact(registry, 'u128').createdAtHash).not.toBeDefined(); - }); - - it('warns on initialU8aLength usage', () => { - // eslint-disable-next-line deprecation/deprecation - expect(new Compact(registry, 'u128').initialU8aLength).toEqual(0); - }); - }); - describe('constructor', (): void => { it('fails on > MAX_SAFE_INTEGER', (): void => { // eslint-disable-next-line @typescript-eslint/no-loss-of-precision @@ -44,19 +32,19 @@ describe('Compact', (): void => { it('has the correct encodedLength for constructor values (string BlockNumber)', (): void => { expect( - new (Compact.with('BlockNumber'))(registry, 0xfffffff9).$encodedLength + new (Compact.with('BlockNumber'))(registry, 0xfffffff9).encodedLength ).toEqual(5); }); it('has the correct encodedLength for constructor values (class BlockNumber)', (): void => { expect( - new (Compact.with(registry.createClass('BlockNumber')))(registry, 0xfffffff9).$encodedLength + new (Compact.with(registry.createClass('BlockNumber')))(registry, 0xfffffff9).encodedLength ).toEqual(5); }); it('has the correct encodedLength for constructor values (u32)', (): void => { expect( - new (Compact.with(U32))(registry, 0xffff9).$encodedLength + new (Compact.with(U32))(registry, 0xffff9).encodedLength ).toEqual(4); }); @@ -98,7 +86,7 @@ describe('Compact', (): void => { it('has a sane inspect', (): void => { expect( - new (Compact.with(U32))(registry, 0xffff).inspectU8a() + new (Compact.with(U32))(registry, 0xffff).inspect() ).toEqual({ outer: [new Uint8Array([254, 255, 3, 0])] }); diff --git a/packages/types-codec/src/base/Compact.ts b/packages/types-codec/src/base/Compact.ts index cfe490721c..74b138b49b 100644 --- a/packages/types-codec/src/base/Compact.ts +++ b/packages/types-codec/src/base/Compact.ts @@ -7,7 +7,7 @@ import type { AnyJson, AnyNumber, CodecClass, ICompact, Inspect, INumber, IU8a, import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util'; -import { typeToConstructor, warnGet } from '../utils'; +import { typeToConstructor } from '../utils'; interface Options { definition?: CodecClass; @@ -47,49 +47,25 @@ function decodeCompact (registry: Registry, Type: CodecClass< * a number and making the compact representation thereof */ export class Compact implements ICompact { - public $createdAtHash?: IU8a; - public $initialU8aLength?: number; - public $isStorageFallback?: boolean; - readonly $registry: Registry; + readonly registry: Registry; + + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; 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); - this.$initialU8aLength = decodedLength; + this.initialU8aLength = decodedLength; this.#raw = raw; } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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; @@ -107,7 +83,7 @@ export class Compact implements ICompact { /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { return this.toU8a().length; } @@ -115,14 +91,14 @@ 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()); } /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { - return this.#raw.$isEmpty; + public get isEmpty (): boolean { + return this.#raw.isEmpty; } /** @@ -146,7 +122,7 @@ export class Compact implements ICompact { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { return { outer: [this.toU8a()] }; @@ -205,7 +181,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 9e5bb8e294..a5216fc600 100644 --- a/packages/types-codec/src/base/DoNotConstruct.ts +++ b/packages/types-codec/src/base/DoNotConstruct.ts @@ -4,53 +4,26 @@ import type { HexString } from '@polkadot/util/types'; import type { AnyJson, Codec, CodecClass, Inspect, IU8a, Registry } from '../types'; -import { warnGet } from '../utils'; - /** * @name DoNotConstruct * @description * 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; + public createdAtHash?: IU8a; + public isStorageFallback?: boolean; #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; } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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) { @@ -62,7 +35,7 @@ export class DoNotConstruct implements Codec { /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { throw this.#neverError; } @@ -76,7 +49,7 @@ export class DoNotConstruct implements Codec { /** * @description Checks if the value is an empty value (always true) */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { throw this.#neverError; } @@ -84,7 +57,7 @@ export class DoNotConstruct implements Codec { throw this.#neverError; } - public inspectU8a (): Inspect { + public inspect (): Inspect { throw this.#neverError; } diff --git a/packages/types-codec/src/base/Enum.spec.ts b/packages/types-codec/src/base/Enum.spec.ts index 5cf9f2f7a7..1d51572e37 100644 --- a/packages/types-codec/src/base/Enum.spec.ts +++ b/packages/types-codec/src/base/Enum.spec.ts @@ -293,7 +293,7 @@ describe('Enum', (): void => { it('has isNone set, with correct index (i.e. no values are used)', (): void => { const test = new Enum(registry, ['foo', 'bar'], 1); - expect(test.$isNone).toBe(true); + expect(test.isNone).toBe(true); expect(test.index).toEqual(1); }); @@ -303,7 +303,7 @@ describe('Enum', (): void => { registry, { Text, U32 }, '0x0134120000' - ).inspectU8a() + ).inspect() ).toEqual({ outer: [new Uint8Array([0x01]), new Uint8Array([0x34, 0x12, 0x00, 0x00])] }); @@ -430,7 +430,7 @@ describe('Enum', (): void => { const test = new Test(registry, 123, 1); expect(test.toHex()).toEqual('0x017b000000'); - expect(test.$encodedLength).toEqual(1 + 4); + expect(test.encodedLength).toEqual(1 + 4); }); it('encodes a single entry correctly', (): void => { diff --git a/packages/types-codec/src/base/Enum.ts b/packages/types-codec/src/base/Enum.ts index 89922e76de..d385bf8310 100644 --- a/packages/types-codec/src/base/Enum.ts +++ b/packages/types-codec/src/base/Enum.ts @@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, IEnum, Inspect, IU8a, Registry } from import { isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util'; -import { mapToTypeMap, typesToMap, warnGet } from '../utils'; +import { mapToTypeMap, typesToMap } from '../utils'; import { Null } from './Null'; // export interface, this is used in Enum.with, so required as public by TS @@ -183,16 +183,16 @@ 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; - readonly $isBasic: boolean; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; readonly #def: TypesDef; readonly #entryIndex: number; readonly #indexes: number[]; + readonly #isBasic: boolean; readonly #isIndexed: boolean; readonly #raw: Codec; @@ -204,55 +204,19 @@ export class Enum implements IEnum { ? createFromU8a(registry, def, value[0], value.subarray(1)) : decodeEnum(registry, def, value, index); - this.$isBasic = isBasic; - - this.$registry = registry; + this.registry = registry; this.#def = def; + this.#isBasic = isBasic; this.#isIndexed = isIndexed; this.#indexes = Object.values(def).map(({ index }) => index); this.#entryIndex = this.#indexes.indexOf(decoded.index); this.#raw = decoded.value; - if (this.#raw.$initialU8aLength) { - this.$initialU8aLength = 1 + this.#raw.$initialU8aLength; + if (this.#raw.initialU8aLength) { + this.initialU8aLength = 1 + this.#raw.initialU8aLength; } } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - 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'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - return warnGet(this, 'isEmpty'); - } - - /** @deprecated Use $isNone instead. This getter will be removed in a future version */ - public get isNone (): boolean { - return warnGet(this, 'isNone'); - } - public static with (Types: Record | Record | string[]): EnumCodecClass { let definition: Definition | undefined; @@ -297,15 +261,15 @@ export class Enum implements IEnum { /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { - return 1 + this.#raw.$encodedLength; + public get encodedLength (): number { + return 1 + this.#raw.encodedLength; } /** * @description returns a hash of the contents */ public get hash (): IU8a { - return this.$registry.hash(this.toU8a()); + return this.registry.hash(this.toU8a()); } /** @@ -322,17 +286,24 @@ export class Enum implements IEnum { return this.#raw; } + /** + * @description true if this is a basic enum (no values) + */ + public get isBasic (): boolean { + return this.#isBasic; + } + /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { - return this.#raw.$isEmpty; + public get isEmpty (): boolean { + return this.#raw.isEmpty; } /** * @description Checks if the Enum points to a [[Null]] type */ - public get $isNone (): boolean { + public get isNone (): boolean { return this.#raw instanceof Null; } @@ -373,7 +344,7 @@ export class Enum implements IEnum { return !this.toU8a().some((entry, index) => entry !== other[index]); } else if (isNumber(other)) { return this.toNumber() === other; - } else if (this.$isBasic && isString(other)) { + } else if (this.#isBasic && isString(other)) { return this.type === other; } else if (isHex(other)) { return this.toHex() === other; @@ -390,12 +361,12 @@ export class Enum implements IEnum { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { - if (this.$isBasic) { + public inspect (): Inspect { + if (this.#isBasic) { return { outer: [new Uint8Array([this.index])] }; } - const { inner, outer = [] } = this.#raw.inspectU8a(); + const { inner, outer = [] } = this.#raw.inspect(); return { inner, @@ -414,7 +385,7 @@ export class Enum implements IEnum { * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ public toHuman (isExtended?: boolean): AnyJson { - return this.$isBasic || this.$isNone + return this.#isBasic || this.isNone ? this.type : { [this.type]: this.#raw.toHuman(isExtended) }; } @@ -423,7 +394,7 @@ export class Enum implements IEnum { * @description Converts the Object to JSON, typically used for RPC transfers */ public toJSON (): AnyJson { - return this.$isBasic + return this.#isBasic ? this.type : { [stringCamelCase(this.type)]: this.#raw.toJSON() }; } @@ -439,7 +410,7 @@ export class Enum implements IEnum { * @description Converts the value in a best-fit primitive form */ public toPrimitive (): AnyJson { - return this.$isBasic + return this.#isBasic ? this.type : { [stringCamelCase(this.type)]: this.#raw.toPrimitive() }; } @@ -448,7 +419,7 @@ export class Enum implements IEnum { * @description Returns a raw struct representation of the enum types */ protected _toRawStruct (): string[] | Record { - if (this.$isBasic) { + if (this.#isBasic) { return this.#isIndexed ? this.defKeys.reduce((out: Record, key, index): Record => { out[key] = this.#indexes[index]; @@ -460,7 +431,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; @@ -479,7 +450,7 @@ export class Enum implements IEnum { * @description Returns the string representation of the value */ public toString (): string { - return this.$isNone + return this.isNone ? this.type : stringify(this.toJSON()); } diff --git a/packages/types-codec/src/base/Int.spec.ts b/packages/types-codec/src/base/Int.spec.ts index 5a9b1ac1a8..45a8d5c645 100644 --- a/packages/types-codec/src/base/Int.spec.ts +++ b/packages/types-codec/src/base/Int.spec.ts @@ -65,7 +65,7 @@ describe('Int', (): void => { it('has a sane inspect', (): void => { expect( - new Int(registry, '0x12', 16).inspectU8a() + new Int(registry, '0x12', 16).inspect() ).toEqual({ outer: [new Uint8Array([0x12, 0x00])] }); diff --git a/packages/types-codec/src/base/Null.spec.ts b/packages/types-codec/src/base/Null.spec.ts index d3da01a222..59d873d670 100644 --- a/packages/types-codec/src/base/Null.spec.ts +++ b/packages/types-codec/src/base/Null.spec.ts @@ -26,7 +26,7 @@ describe('Null', (): void => { }); it('isEmpty', (): void => { - expect(new Null(registry).$isEmpty).toBe(true); + expect(new Null(registry).isEmpty).toBe(true); }); it('has an empty hex', (): void => { diff --git a/packages/types-codec/src/base/Null.ts b/packages/types-codec/src/base/Null.ts index 5f9ce2bf76..b2527ca7f5 100644 --- a/packages/types-codec/src/base/Null.ts +++ b/packages/types-codec/src/base/Null.ts @@ -6,48 +6,22 @@ import type { Codec, Inspect, IU8a, Registry } from '../types'; import { isNull } from '@polkadot/util'; -import { warnGet } from '../utils'; - /** * @name Null * @description * Implements a type that does not contain anything (apart from `null`) */ export class Null implements Codec { - public $createdAtHash?: IU8a; - readonly $encodedLength = 0; - public $initialU8aLength = 0; - public $isStorageFallback?: boolean; - readonly $isEmpty = true; - readonly $registry: Registry; + readonly encodedLength = 0; + readonly isEmpty = true; + readonly registry: Registry; + + public createdAtHash?: IU8a; + public initialU8aLength = 0; + public isStorageFallback?: boolean; constructor (registry: Registry) { - this.$registry = registry; - } - - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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'); + this.registry = registry; } /** @@ -67,7 +41,7 @@ export class Null implements Codec { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { return {}; } diff --git a/packages/types-codec/src/base/Option.spec.ts b/packages/types-codec/src/base/Option.spec.ts index 6bd2b73447..c0f4f86309 100644 --- a/packages/types-codec/src/base/Option.spec.ts +++ b/packages/types-codec/src/base/Option.spec.ts @@ -37,7 +37,7 @@ describe('Option', (): void => { ].forEach((test): void => { expect(test.isSome).toBe(true); expect(test.isNone).toBe(false); - expect(test.$isEmpty).toBe(false); + expect(test.isEmpty).toBe(false); expect(test.toU8a()).toEqual(new Uint8Array([1])); expect(test.unwrap().toHex()).toEqual('0x'); }); @@ -198,7 +198,7 @@ describe('Option', (): void => { it('has a sane inspect', (): void => { expect( - new Option(registry, U32, '1234').inspectU8a() + new Option(registry, U32, '1234').inspect() ).toEqual({ outer: [new Uint8Array([0x01]), new Uint8Array([210, 4, 0, 0])] }); diff --git a/packages/types-codec/src/base/Option.ts b/packages/types-codec/src/base/Option.ts index 08988e82eb..3f12cafe79 100644 --- a/packages/types-codec/src/base/Option.ts +++ b/packages/types-codec/src/base/Option.ts @@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, Inspect, IOption, IU8a, Registry } fro import { isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util'; -import { typeToConstructor, warnGet } from '../utils'; +import { typeToConstructor } from '../utils'; import { Null } from './Null'; interface Options { @@ -66,11 +66,11 @@ 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; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; readonly #Type: CodecClass; readonly #raw: T; @@ -83,40 +83,15 @@ 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; - if (decoded?.$initialU8aLength) { - this.$initialU8aLength = 1 + decoded.$initialU8aLength; + if (decoded?.initialU8aLength) { + this.initialU8aLength = 1 + decoded.initialU8aLength; } } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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; @@ -136,22 +111,22 @@ export class Option implements IOption { /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { // boolean byte (has value, doesn't have) along with wrapped length - return 1 + this.#raw.$encodedLength; + return 1 + this.#raw.encodedLength; } /** * @description returns a hash of the contents */ public get hash (): IU8a { - return this.$registry.hash(this.toU8a()); + return this.registry.hash(this.toU8a()); } /** * @description Checks if the Option has no value */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return this.isNone; } @@ -190,12 +165,12 @@ export class Option implements IOption { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { if (this.isNone) { return { outer: [new Uint8Array([0])] }; } - const { inner, outer = [] } = this.#raw.inspectU8a(); + const { inner, outer = [] } = this.#raw.inspect(); return { inner, @@ -243,7 +218,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 @@ -266,7 +241,7 @@ export class Option implements IOption { return this.#raw.toU8a(true); } - const u8a = new Uint8Array(this.$encodedLength); + const u8a = new Uint8Array(this.encodedLength); if (this.isSome) { u8a.set([1]); @@ -304,6 +279,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/Result.ts b/packages/types-codec/src/base/Result.ts index 93622e4259..4718ce7f9e 100644 --- a/packages/types-codec/src/base/Result.ts +++ b/packages/types-codec/src/base/Result.ts @@ -51,7 +51,7 @@ export class Result extends Enum implements IR * @description Checks if the Result has no value */ public override get isEmpty (): boolean { - return this.isOk && this.value.$isEmpty; + return this.isOk && this.value.isEmpty; } /** diff --git a/packages/types-codec/src/base/Tuple.spec.ts b/packages/types-codec/src/base/Tuple.spec.ts index 843e66ed84..51a03135fb 100644 --- a/packages/types-codec/src/base/Tuple.spec.ts +++ b/packages/types-codec/src/base/Tuple.spec.ts @@ -50,7 +50,7 @@ describe('Tuple', (): void => { const INPUT = '0xcc0200000000'; const test = registry.createType('(u32, [u32; 0], u16)', INPUT); - expect(test.$encodedLength).toEqual(4 + 0 + 2); + expect(test.encodedLength).toEqual(4 + 0 + 2); expect(test.toHex()).toEqual(INPUT); }); }); @@ -123,7 +123,7 @@ describe('Tuple', (): void => { it('has a sane inspect', (): void => { expect( - tuple.inspectU8a() + tuple.inspect() ).toEqual({ inner: [ { outer: [new Uint8Array([7 << 2]), stringToU8a('bazzing')] }, diff --git a/packages/types-codec/src/base/Tuple.ts b/packages/types-codec/src/base/Tuple.ts index 6a4fd0e7f5..7a2f790a64 100644 --- a/packages/types-codec/src/base/Tuple.ts +++ b/packages/types-codec/src/base/Tuple.ts @@ -68,7 +68,7 @@ export class Tuple extends AbstractArray implements ITuple { super(registry, Classes[0].length); - this.$initialU8aLength = ( + this.initialU8aLength = ( isU8a(value) ? decodeU8a(registry, this, value, Classes) : decodeTuple(registry, this, value, Classes) @@ -93,11 +93,11 @@ export class Tuple extends AbstractArray implements ITuple { /** * @description The length of the value when encoded as a Uint8Array */ - public override get $encodedLength (): number { + public override get encodedLength (): number { let total = 0; for (let i = 0; i < this.length; i++) { - total += this[i].$encodedLength; + total += this[i].encodedLength; } return total; @@ -109,13 +109,13 @@ 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()); } /** * @description Returns a breakdown of the hex encoding for this Codec */ - public override inspectU8a (): Inspect { + public override inspect (): Inspect { return { inner: this.inspectInner() }; @@ -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/UInt.spec.ts b/packages/types-codec/src/base/UInt.spec.ts index 052c9f446e..c60ccd2746 100644 --- a/packages/types-codec/src/base/UInt.spec.ts +++ b/packages/types-codec/src/base/UInt.spec.ts @@ -127,7 +127,7 @@ describe('UInt', (): void => { it('has a sane inspect', (): void => { expect( - new UInt(registry, '0x12', 16).inspectU8a() + new UInt(registry, '0x12', 16).inspect() ).toEqual({ outer: [new Uint8Array([0x12, 0x00])] }); diff --git a/packages/types-codec/src/base/Vec.spec.ts b/packages/types-codec/src/base/Vec.spec.ts index 65ad24e326..9e7833280f 100644 --- a/packages/types-codec/src/base/Vec.spec.ts +++ b/packages/types-codec/src/base/Vec.spec.ts @@ -185,7 +185,7 @@ describe('Vec', (): void => { ]; const vec = registry.createType('Vec', addrs); - expect(vec.inspectU8a()).toEqual({ + expect(vec.inspect()).toEqual({ inner: addrs.map((a) => ({ outer: [decodeAddress(a)] })), diff --git a/packages/types-codec/src/base/Vec.ts b/packages/types-codec/src/base/Vec.ts index 6408e529a7..4042ecf6c0 100644 --- a/packages/types-codec/src/base/Vec.ts +++ b/packages/types-codec/src/base/Vec.ts @@ -80,7 +80,7 @@ export class Vec extends AbstractArray { this.#Type = definition || setDefinition(typeToConstructor(registry, Type)); - this.$initialU8aLength = ( + this.initialU8aLength = ( isU8a(decodeFrom) ? decodeU8aVec(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type) @@ -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.spec.ts b/packages/types-codec/src/base/VecFixed.spec.ts index 500e734557..1c59e7d052 100644 --- a/packages/types-codec/src/base/VecFixed.spec.ts +++ b/packages/types-codec/src/base/VecFixed.spec.ts @@ -50,19 +50,19 @@ describe('VecFixed', (): void => { it('has empty Uint8Array when length is 0', (): void => { const test = new (VecFixed.with(Text, 0))(registry); - expect(test.$encodedLength).toEqual(0); + expect(test.encodedLength).toEqual(0); expect(test.toU8a()).toEqual(new Uint8Array([])); }); it('has equivalent to 1 Uint8Array when length is 1', (): void => { const test = new (VecFixed.with(Text, 1))(registry, ['hello']); - expect(test.$encodedLength).toEqual(1 + 5); + expect(test.encodedLength).toEqual(1 + 5); expect(test.toU8a()).toEqual(new Uint8Array([20, 104, 101, 108, 108, 111])); }); it('has a sane inspect', (): void => { - expect(test.inspectU8a()).toEqual({ + expect(test.inspect()).toEqual({ inner: [ { outer: [new Uint8Array([1 << 2]), stringToU8a('1')] }, { outer: [new Uint8Array([1 << 2]), stringToU8a('2')] }, diff --git a/packages/types-codec/src/base/VecFixed.ts b/packages/types-codec/src/base/VecFixed.ts index bedaaff626..2c3995336b 100644 --- a/packages/types-codec/src/base/VecFixed.ts +++ b/packages/types-codec/src/base/VecFixed.ts @@ -32,7 +32,7 @@ export class VecFixed extends AbstractArray { this.#Type = definition || setDefinition(typeToConstructor(registry, Type)); - this.$initialU8aLength = ( + this.initialU8aLength = ( isU8a(value) ? decodeU8aVec(registry, this, value, 0, this.#Type) : decodeVec(registry, this, value, 0, this.#Type) @@ -57,17 +57,17 @@ 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(); } /** * @description The length of the value when encoded as a Uint8Array */ - public override get $encodedLength (): number { + public override get encodedLength (): number { let total = 0; for (let i = 0; i < this.length; i++) { - total += this[i].$encodedLength; + total += this[i].encodedLength; } return total; @@ -76,7 +76,7 @@ export class VecFixed extends AbstractArray { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public override inspectU8a (): Inspect { + public override inspect (): Inspect { return { inner: this.inspectInner() }; diff --git a/packages/types-codec/src/extended/BTreeMap.spec.ts b/packages/types-codec/src/extended/BTreeMap.spec.ts index ca821bee67..56fdfea2a0 100644 --- a/packages/types-codec/src/extended/BTreeMap.spec.ts +++ b/packages/types-codec/src/extended/BTreeMap.spec.ts @@ -87,7 +87,7 @@ describe('BTreeMap', (): void => { it('correctly encodes length', (): void => { expect( new ( - BTreeMap.with(Text, U32))(registry, mockU32TextMap).$encodedLength + BTreeMap.with(Text, U32))(registry, mockU32TextMap).encodedLength ).toEqual(13); }); @@ -195,7 +195,7 @@ describe('BTreeMap', (): void => { [new Text(registry, '1'), new Text(registry, 'foo')], [new Text(registry, '2'), new Text(registry, 'bar')], [new Text(registry, '3'), new Text(registry, 'baz')] - ])).inspectU8a() + ])).inspect() ).toEqual({ inner: [ { outer: [new Uint8Array([1 << 2]), stringToU8a('1')] }, diff --git a/packages/types-codec/src/extended/BTreeSet.spec.ts b/packages/types-codec/src/extended/BTreeSet.spec.ts index 2b5bb09474..3f35d38db8 100644 --- a/packages/types-codec/src/extended/BTreeSet.spec.ts +++ b/packages/types-codec/src/extended/BTreeSet.spec.ts @@ -130,7 +130,7 @@ describe('BTreeSet', (): void => { it('correctly encodes length', (): void => { expect( new ( - BTreeSet.with(U32))(registry, mockU32Set).$encodedLength + BTreeSet.with(U32))(registry, mockU32Set).encodedLength ).toEqual(17); }); @@ -139,10 +139,10 @@ describe('BTreeSet', (): void => { // only the length byte expect(none.toHex()).toEqual('0x00'); - expect(none.$encodedLength).toEqual(1); + expect(none.encodedLength).toEqual(1); expect( - (new (BTreeSet.with(U32))(registry, none.toHex())).$initialU8aLength - ).toEqual(none.$encodedLength); + (new (BTreeSet.with(U32))(registry, none.toHex())).initialU8aLength + ).toEqual(none.encodedLength); }); it('correctly encodes/decodes filled', (): void => { @@ -150,10 +150,10 @@ describe('BTreeSet', (): void => { // length byte + 2 values, 2 << 2 with u32 values expect(some.toHex()).toEqual('0x080100000002000000'); - expect(some.$encodedLength).toEqual(1 + (4 * 2)); + expect(some.encodedLength).toEqual(1 + (4 * 2)); expect( - (new (BTreeSet.with(U32))(registry, some.toHex())).$initialU8aLength - ).toEqual(some.$encodedLength); + (new (BTreeSet.with(U32))(registry, some.toHex())).initialU8aLength + ).toEqual(some.encodedLength); }); }); @@ -209,7 +209,7 @@ describe('BTreeSet', (): void => { it('has a sane inspect', (): void => { expect( - new (BTreeSet.with(U32))(registry, [1, 2, 3, 4]).inspectU8a() + new (BTreeSet.with(U32))(registry, [1, 2, 3, 4]).inspect() ).toEqual({ inner: [ { outer: [new Uint8Array([1, 0, 0, 0])] }, diff --git a/packages/types-codec/src/extended/BTreeSet.ts b/packages/types-codec/src/extended/BTreeSet.ts index 7fbadeb88c..bc1a643eb6 100644 --- a/packages/types-codec/src/extended/BTreeSet.ts +++ b/packages/types-codec/src/extended/BTreeSet.ts @@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, Inspect, ISet, IU8a, Registry } from ' import { compactFromU8aLim, compactToU8a, isHex, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util'; -import { compareSet, decodeU8aVec, sortSet, typeToConstructor, warnGet } from '../utils'; +import { compareSet, decodeU8aVec, sortSet, typeToConstructor } from '../utils'; const l = logger('BTreeSet'); @@ -70,11 +70,11 @@ 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; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; readonly #ValClass: CodecClass; @@ -83,36 +83,11 @@ export class BTreeSet extends Set implements ISet super(sortSet(values)); - this.$registry = registry; - this.$initialU8aLength = decodedLength; + this.registry = registry; + this.initialU8aLength = decodedLength; this.#ValClass = ValClass; } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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) { @@ -124,11 +99,11 @@ export class BTreeSet extends Set implements ISet /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { let len = compactToU8a(this.size).length; for (const v of this.values()) { - len += v.$encodedLength; + len += v.encodedLength; } return len; @@ -138,13 +113,13 @@ 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()); } /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return this.size === 0; } @@ -165,11 +140,11 @@ export class BTreeSet extends Set implements ISet /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { const inner = new Array(); for (const v of this.values()) { - inner.push(v.inspectU8a()); + inner.push(v.inspect()); } return { @@ -215,7 +190,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/BitVec.spec.ts b/packages/types-codec/src/extended/BitVec.spec.ts index b573fcf8da..e5aec0edb6 100644 --- a/packages/types-codec/src/extended/BitVec.spec.ts +++ b/packages/types-codec/src/extended/BitVec.spec.ts @@ -19,7 +19,7 @@ describe('BitVec', (): void => { it('has the right encodedLength', (): void => { expect( - bitvec.$encodedLength + bitvec.encodedLength ).toEqual((test.length - 2) / 2); }); @@ -48,7 +48,7 @@ describe('BitVec', (): void => { it('has a sane inspect', (): void => { expect( - new BitVec(registry, '0x0837').inspectU8a() + new BitVec(registry, '0x0837').inspect() ).toEqual({ outer: [new Uint8Array([0]), new Uint8Array([0x08, 0x37])] }); diff --git a/packages/types-codec/src/extended/BitVec.ts b/packages/types-codec/src/extended/BitVec.ts index cc89cb1d4f..20bf3b3c72 100644 --- a/packages/types-codec/src/extended/BitVec.ts +++ b/packages/types-codec/src/extended/BitVec.ts @@ -60,14 +60,14 @@ export class BitVec extends Raw { /** * @description The length of the value when encoded as a Uint8Array */ - public override get $encodedLength (): number { + public override get encodedLength (): number { return this.length + compactToU8a(this.#decodedLength).length; } /** * @description Returns a breakdown of the hex encoding for this Codec */ - public override inspectU8a (): Inspect { + public override inspect (): Inspect { return { outer: [compactToU8a(this.#decodedLength), super.toU8a()] }; diff --git a/packages/types-codec/src/extended/Bytes.spec.ts b/packages/types-codec/src/extended/Bytes.spec.ts index 08b2d15743..9853500783 100644 --- a/packages/types-codec/src/extended/Bytes.spec.ts +++ b/packages/types-codec/src/extended/Bytes.spec.ts @@ -65,7 +65,7 @@ describe('Bytes', (): void => { it('has a sane inspect', (): void => { expect( - new Bytes(registry, '0x12345678').inspectU8a() + new Bytes(registry, '0x12345678').inspect() ).toEqual({ outer: [new Uint8Array([4 << 2]), new Uint8Array([0x12, 0x34, 0x56, 0x78])] }); diff --git a/packages/types-codec/src/extended/Bytes.ts b/packages/types-codec/src/extended/Bytes.ts index c3e0b4e4c2..fba393d180 100644 --- a/packages/types-codec/src/extended/Bytes.ts +++ b/packages/types-codec/src/extended/Bytes.ts @@ -50,14 +50,14 @@ export class Bytes extends Raw { /** * @description The length of the value when encoded as a Uint8Array */ - public override get $encodedLength (): number { + public override get encodedLength (): number { return this.length + compactToU8a(this.length).length; } /** * @description Returns a breakdown of the hex encoding for this Codec */ - public override inspectU8a (isBare?: boolean): Inspect { + public override inspect (isBare?: boolean): Inspect { const clength = compactToU8a(this.length); return { diff --git a/packages/types-codec/src/extended/HashMap.spec.ts b/packages/types-codec/src/extended/HashMap.spec.ts index 048ef8499f..16aa8ba59a 100644 --- a/packages/types-codec/src/extended/HashMap.spec.ts +++ b/packages/types-codec/src/extended/HashMap.spec.ts @@ -20,7 +20,7 @@ describe('HashMap', (): void => { new (HashMap.with(Text, Text))(registry, new Map([ [new Text(registry, '1'), new Text(registry, 'foo')], [new Text(registry, '2'), new Text(registry, 'bar')] - ])).inspectU8a() + ])).inspect() ).toEqual({ inner: [ { outer: [new Uint8Array([1 << 2]), stringToU8a('1')] }, diff --git a/packages/types-codec/src/extended/Linkage.ts b/packages/types-codec/src/extended/Linkage.ts index 5e36b1bfe6..c4e47211ff 100644 --- a/packages/types-codec/src/extended/Linkage.ts +++ b/packages/types-codec/src/extended/Linkage.ts @@ -55,7 +55,7 @@ export class Linkage extends Struct { public override toU8a (): Uint8Array { // As part of a storage query (where these appear), in the case of empty, the values // are NOT populated by the node - follow the same logic, leaving it empty - return this.$isEmpty + return this.isEmpty ? EMPTY : super.toU8a(); } diff --git a/packages/types-codec/src/extended/Map.spec.ts b/packages/types-codec/src/extended/Map.spec.ts index e7f7a85cd3..aaf9d52086 100644 --- a/packages/types-codec/src/extended/Map.spec.ts +++ b/packages/types-codec/src/extended/Map.spec.ts @@ -81,10 +81,10 @@ describe('CodecMap', (): void => { // only the length byte expect(none.toHex()).toEqual('0x00'); - expect(none.$encodedLength).toEqual(1); + expect(none.encodedLength).toEqual(1); expect( - new CodecMap(registry, Text, Text, none.toHex()).$initialU8aLength - ).toEqual(none.$encodedLength); + new CodecMap(registry, Text, Text, none.toHex()).initialU8aLength + ).toEqual(none.encodedLength); }); it('correctly encodes/decodes filled', (): void => { @@ -95,10 +95,10 @@ describe('CodecMap', (): void => { // length byte + 2 values, 2 << 2 with Text values expect(some.toHex()).toEqual('0x0804310c666f6f04320c626172'); - expect(some.$encodedLength).toEqual(1 + ((1 + 1) * 2) + ((1 + 3) * 2)); + expect(some.encodedLength).toEqual(1 + ((1 + 1) * 2) + ((1 + 3) * 2)); expect( - new CodecMap(registry, Text, Text, some.toHex()).$initialU8aLength - ).toEqual(some.$encodedLength); + new CodecMap(registry, Text, Text, some.toHex()).initialU8aLength + ).toEqual(some.encodedLength); }); }); @@ -107,7 +107,7 @@ describe('CodecMap', (): void => { new CodecMap(registry, Text, Text, new Map([ [new Text(registry, '1'), new Text(registry, 'foo')], [new Text(registry, '2'), new Text(registry, 'bar')] - ])).inspectU8a() + ])).inspect() ).toEqual({ inner: [ { outer: [new Uint8Array([1 << 2]), stringToU8a('1')] }, diff --git a/packages/types-codec/src/extended/Map.ts b/packages/types-codec/src/extended/Map.ts index b0b1cb1d88..8b94b49ca6 100644 --- a/packages/types-codec/src/extended/Map.ts +++ b/packages/types-codec/src/extended/Map.ts @@ -10,7 +10,7 @@ import { AbstractArray } from '../abstract/Array'; import { Enum } from '../base/Enum'; import { Raw } from '../native/Raw'; import { Struct } from '../native/Struct'; -import { compareMap, decodeU8a, sortMap, typeToConstructor, warnGet } from '../utils'; +import { compareMap, decodeU8a, sortMap, typeToConstructor } from '../utils'; const l = logger('Map'); @@ -94,11 +94,11 @@ function decodeMap (registry: Registry, keyTyp } export class CodecMap extends Map implements IMap { - readonly $registry: Registry; + readonly registry: Registry; - public $createdAtHash?: IU8a; - public $initialU8aLength?: number; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; readonly #KeyClass: CodecClass; readonly #ValClass: CodecClass; @@ -109,46 +109,21 @@ export class CodecMap extends super(type === 'BTreeMap' ? sortMap(decoded) : decoded); - this.$registry = registry; - this.$initialU8aLength = decodedLength; + this.registry = registry; + this.initialU8aLength = decodedLength; this.#KeyClass = KeyClass; this.#ValClass = ValClass; this.#type = type; } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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 */ - public get $encodedLength (): number { + public get encodedLength (): number { let len = compactToU8a(this.size).length; for (const [k, v] of this.entries()) { - len += k.$encodedLength + v.$encodedLength; + len += k.encodedLength + v.encodedLength; } return len; @@ -158,13 +133,13 @@ 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()); } /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return this.size === 0; } @@ -178,12 +153,12 @@ export class CodecMap extends /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { const inner = new Array(); for (const [k, v] of this.entries()) { - inner.push(k.inspectU8a()); - inner.push(v.inspectU8a()); + inner.push(k.inspect()); + inner.push(v.inspect()); } return { @@ -250,7 +225,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/OptionBool.spec.ts b/packages/types-codec/src/extended/OptionBool.spec.ts index 326d88fb5e..59fa936471 100644 --- a/packages/types-codec/src/extended/OptionBool.spec.ts +++ b/packages/types-codec/src/extended/OptionBool.spec.ts @@ -40,7 +40,7 @@ describe('OptionBool', (): void => { }); it('has a sane inspect', (): void => { - expect(new OptionBool(registry, true).inspectU8a()).toEqual({ + expect(new OptionBool(registry, true).inspect()).toEqual({ outer: [new Uint8Array([1])] }); }); diff --git a/packages/types-codec/src/extended/OptionBool.ts b/packages/types-codec/src/extended/OptionBool.ts index 4593af16f8..33a72cf64b 100644 --- a/packages/types-codec/src/extended/OptionBool.ts +++ b/packages/types-codec/src/extended/OptionBool.ts @@ -33,13 +33,13 @@ export class OptionBool extends Option { : value ); - this.$initialU8aLength = 1; + this.initialU8aLength = 1; } /** * @description The length of the value when encoded as a Uint8Array */ - public override get $encodedLength (): number { + public override get encodedLength (): number { return 1; } @@ -64,7 +64,7 @@ export class OptionBool extends Option { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public override inspectU8a (): Inspect { + public override inspect (): Inspect { return { outer: [this.toU8a()] }; } diff --git a/packages/types-codec/src/extended/Range.spec.ts b/packages/types-codec/src/extended/Range.spec.ts index 120263bfba..c5009b722d 100644 --- a/packages/types-codec/src/extended/Range.spec.ts +++ b/packages/types-codec/src/extended/Range.spec.ts @@ -25,7 +25,7 @@ describe('Range', (): void => { }); it('has a sane inspect', (): void => { - expect(range.inspectU8a()).toEqual({ + expect(range.inspect()).toEqual({ inner: [ { outer: [new Uint8Array([1, 0, 0, 0])] }, { outer: [new Uint8Array([2, 0, 0, 0])] } diff --git a/packages/types-codec/src/extended/Type.spec.ts b/packages/types-codec/src/extended/Type.spec.ts index d6026b69d2..e53679ca0f 100644 --- a/packages/types-codec/src/extended/Type.spec.ts +++ b/packages/types-codec/src/extended/Type.spec.ts @@ -106,7 +106,7 @@ describe('Type', (): void => { const u8a = new Type(registry, original).toU8a(); const decoded = new Type(registry, u8a); - expect(decoded.$encodedLength).toEqual(original.length + 1); // extra byte for length + expect(decoded.encodedLength).toEqual(original.length + 1); // extra byte for length expect(decoded.toString()).toEqual(expected); }); diff --git a/packages/types-codec/src/extended/U8aFixed.spec.ts b/packages/types-codec/src/extended/U8aFixed.spec.ts index 97adeeefdf..1f0968bc4c 100644 --- a/packages/types-codec/src/extended/U8aFixed.spec.ts +++ b/packages/types-codec/src/extended/U8aFixed.spec.ts @@ -93,7 +93,7 @@ describe('U8aFixed', (): void => { }); it('has a sane inspect', (): void => { - expect(u8a.inspectU8a()).toEqual({ + expect(u8a.inspect()).toEqual({ outer: [new Uint8Array([1, 2, 3, 4])] }); }); diff --git a/packages/types-codec/src/extended/WrapperKeepOpaque.spec.ts b/packages/types-codec/src/extended/WrapperKeepOpaque.spec.ts index 805d898145..aff059d458 100644 --- a/packages/types-codec/src/extended/WrapperKeepOpaque.spec.ts +++ b/packages/types-codec/src/extended/WrapperKeepOpaque.spec.ts @@ -52,7 +52,7 @@ describe('WrapperKeepOpaque', (): void => { it('has a sane inspect (non-decodable)', (): void => { expect( - new ClazzUSize(registry, u8au32).inspectU8a() + new ClazzUSize(registry, u8au32).inspect() ).toEqual({ outer: [new Uint8Array([4 << 2]), new Uint8Array([0x87, 0xd6, 0x12, 0x00])] }); @@ -60,7 +60,7 @@ describe('WrapperKeepOpaque', (): void => { it('has a sane inspect (decodable)', (): void => { expect( - new ClazzU32(registry, u8au32).inspectU8a() + new ClazzU32(registry, u8au32).inspect() ).toEqual({ inner: [{ outer: [new Uint8Array([0x87, 0xd6, 0x12, 0x00])] }], outer: [new Uint8Array([4 << 2])] diff --git a/packages/types-codec/src/extended/WrapperKeepOpaque.ts b/packages/types-codec/src/extended/WrapperKeepOpaque.ts index 62a3d94e77..a32b929fbe 100644 --- a/packages/types-codec/src/extended/WrapperKeepOpaque.ts +++ b/packages/types-codec/src/extended/WrapperKeepOpaque.ts @@ -70,10 +70,10 @@ export class WrapperKeepOpaque extends Bytes { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public override inspectU8a (): Inspect { + public override inspect (): Inspect { return this.#decoded ? { - inner: [this.#decoded.inspectU8a()], + inner: [this.#decoded.inspect()], outer: [compactToU8a(this.length)] } : { @@ -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/extended/WrapperOpaque.spec.ts b/packages/types-codec/src/extended/WrapperOpaque.spec.ts index 77483f2c12..19e2b6cb8e 100644 --- a/packages/types-codec/src/extended/WrapperOpaque.spec.ts +++ b/packages/types-codec/src/extended/WrapperOpaque.spec.ts @@ -47,7 +47,7 @@ describe('WrapperOpaque', (): void => { it('has a sane inspect', (): void => { expect( - new WrapperOpaque(registry, 'u32', '0x78563412').inspectU8a() + new WrapperOpaque(registry, 'u32', '0x78563412').inspect() ).toEqual({ inner: [{ outer: [new Uint8Array([0x78, 0x56, 0x34, 0x12])] }], outer: [new Uint8Array([4 << 2])] diff --git a/packages/types-codec/src/native/Bool.spec.ts b/packages/types-codec/src/native/Bool.spec.ts index 9dfea85fab..a39bed38b7 100644 --- a/packages/types-codec/src/native/Bool.spec.ts +++ b/packages/types-codec/src/native/Bool.spec.ts @@ -37,7 +37,7 @@ describe('Bool', (): void => { }); it('correctly encodes length', (): void => { - expect(new Bool(registry, true).$encodedLength).toEqual(1); + expect(new Bool(registry, true).encodedLength).toEqual(1); }); describe('utils', (): void => { @@ -58,13 +58,13 @@ describe('Bool', (): void => { }); it('has sane isEmpty aligning with the rest', (): void => { - expect(new Bool(registry).$isEmpty).toBe(true); - expect(new Bool(registry, false).$isEmpty).toBe(true); - expect(new Bool(registry, true).$isEmpty).toBe(false); + expect(new Bool(registry).isEmpty).toBe(true); + expect(new Bool(registry, false).isEmpty).toBe(true); + expect(new Bool(registry, true).isEmpty).toBe(false); }); it('has a sane inspect', (): void => { - expect(new Bool(registry, true).inspectU8a()).toEqual({ + expect(new Bool(registry, true).inspect()).toEqual({ outer: [new Uint8Array([1])] }); }); diff --git a/packages/types-codec/src/native/Bool.ts b/packages/types-codec/src/native/Bool.ts index ebe434664a..4c08e16b01 100644 --- a/packages/types-codec/src/native/Bool.ts +++ b/packages/types-codec/src/native/Bool.ts @@ -6,8 +6,6 @@ import type { AnyBool, Codec, Inspect, IU8a, Registry } from '../types'; import { isU8a, u8aToHex } from '@polkadot/util'; -import { warnGet } from '../utils'; - /** * @name bool * @description @@ -15,12 +13,11 @@ import { warnGet } from '../utils'; * @noInheritDoc */ export class bool extends Boolean implements Codec { - readonly $registry: Registry; + readonly registry: Registry; - public $createdAtHash?: IU8a; - readonly $encodedLength = 1; - public $initialU8aLength = 1; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength = 1; + public isStorageFallback?: boolean; constructor (registry: Registry, value: bool | AnyBool | Uint8Array | number = false) { super( @@ -31,45 +28,27 @@ 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. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ + /** + * @description The length of the value when encoded as a Uint8Array + */ public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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'); + return 1; } /** * @description returns a hash of the contents */ public get hash (): IU8a { - return this.$registry.hash(this.toU8a()); + return this.registry.hash(this.toU8a()); } /** * @description Checks if the value is an empty value (true when it wraps false/default) */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return this.isFalse; } @@ -101,7 +80,7 @@ export class bool extends Boolean implements Codec { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { return { outer: [this.toU8a()] }; diff --git a/packages/types-codec/src/native/Date.spec.ts b/packages/types-codec/src/native/Date.spec.ts index acb6f24f41..0c853c9554 100644 --- a/packages/types-codec/src/native/Date.spec.ts +++ b/packages/types-codec/src/native/Date.spec.ts @@ -75,7 +75,7 @@ describe('Date', (): void => { }); it('has a sane inspect', (): void => { - expect(new CodecDate(registry, 3).inspectU8a()).toEqual({ + expect(new CodecDate(registry, 3).inspect()).toEqual({ outer: [new Uint8Array([3, 0, 0, 0, 0, 0, 0, 0])] }); }); diff --git a/packages/types-codec/src/native/Date.ts b/packages/types-codec/src/native/Date.ts index dbbb7f9656..caec69d38d 100644 --- a/packages/types-codec/src/native/Date.ts +++ b/packages/types-codec/src/native/Date.ts @@ -6,8 +6,6 @@ import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from import { BN, bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util'; -import { warnGet } from '../utils'; - const BITLENGTH: UIntBitLength = 64; const U8A_OPTS = { bitLength: BITLENGTH, isLe: true }; @@ -36,55 +34,36 @@ 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; - public $initialU8aLength = BITLENGTH / 8; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength = BITLENGTH / 8; + public isStorageFallback?: boolean; 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. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ + /** + * @description The length of the value when encoded as a Uint8Array + */ public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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'); + return BITLENGTH / 8; } /** * @description returns a hash of the contents */ public get hash (): IU8a { - return this.$registry.hash(this.toU8a()); + return this.registry.hash(this.toU8a()); } /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return this.getTime() === 0; } @@ -105,7 +84,7 @@ export class CodecDate extends Date implements INumber { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { return { outer: [this.toU8a()] }; diff --git a/packages/types-codec/src/native/Float.spec.ts b/packages/types-codec/src/native/Float.spec.ts index 9baee5d88b..a7ad09a330 100644 --- a/packages/types-codec/src/native/Float.spec.ts +++ b/packages/types-codec/src/native/Float.spec.ts @@ -22,7 +22,7 @@ describe('Float', (): void => { it('triggers isEmpty on 0', (): void => { expect( - new F32(registry, 0).$isEmpty + new F32(registry, 0).isEmpty ).toEqual(true); }); diff --git a/packages/types-codec/src/native/Float.ts b/packages/types-codec/src/native/Float.ts index 6c9bc3708c..8b3f034afa 100644 --- a/packages/types-codec/src/native/Float.ts +++ b/packages/types-codec/src/native/Float.ts @@ -6,8 +6,6 @@ import type { AnyFloat, CodecClass, IFloat, Inspect, IU8a, Registry } from '../t import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util'; -import { warnGet } from '../utils'; - interface Options { bitLength?: 32 | 64; } @@ -21,11 +19,12 @@ interface Options { * in some eth_* RPCs */ export class Float extends Number implements IFloat { - public $createdAtHash?: IU8a; - readonly $encodedLength: number; - public $initialU8aLength?: number; - public $isStorageFallback?: boolean; - readonly $registry: Registry; + readonly encodedLength: number; + readonly registry: Registry; + + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; readonly #bitLength: 32 | 64; @@ -39,34 +38,9 @@ export class Float extends Number implements IFloat { ); this.#bitLength = bitLength; - this.$encodedLength = bitLength / 8; - this.$initialU8aLength = this.$encodedLength; - this.$registry = registry; - } - - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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'); + this.encodedLength = bitLength / 8; + this.initialU8aLength = this.encodedLength; + this.registry = registry; } public static with (bitLength: 32 | 64): CodecClass { @@ -81,13 +55,13 @@ 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()); } /** * @description Returns true if the type wraps an empty/default all-0 value */ - public get $isEmpty (): boolean { + get isEmpty (): boolean { return this.valueOf() === 0; } @@ -101,7 +75,7 @@ export class Float extends Number implements IFloat { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { return { outer: [this.toU8a()] }; diff --git a/packages/types-codec/src/native/Json.ts b/packages/types-codec/src/native/Json.ts index 7adfb65b47..53de1b2a2c 100644 --- a/packages/types-codec/src/native/Json.ts +++ b/packages/types-codec/src/native/Json.ts @@ -6,7 +6,7 @@ import type { AnyJson, Codec, Inspect, IU8a, Registry } from '../types'; import { isFunction, objectProperties, stringify } from '@polkadot/util'; -import { compareMap, warnGet } from '../utils'; +import { compareMap } from '../utils'; /** @internal */ function decodeJson (value?: Record | null): [string, any][] { @@ -22,59 +22,40 @@ 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; - public $initialU8aLength?: number; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; constructor (registry: Registry, value?: Record | null) { const decoded = decodeJson(value); super(decoded); - this.$registry = registry; + this.registry = registry; objectProperties(this, decoded.map(([k]) => k), (k) => this.get(k)); } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ + /** + * @description Always 0, never encodes as a Uint8Array + */ public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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'); + return 0; } /** * @description returns a hash of the contents */ public get hash (): IU8a { - return this.$registry.hash(this.toU8a()); + return this.registry.hash(this.toU8a()); } /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return [...this.keys()].length === 0; } @@ -95,7 +76,7 @@ export class Json extends Map implements Codec { /** * @description Unimplemented, will throw */ - public inspectU8a (): Inspect { + public inspect (): Inspect { throw new Error('Unimplemented'); } diff --git a/packages/types-codec/src/native/Raw.spec.ts b/packages/types-codec/src/native/Raw.spec.ts index 746f9aed97..71ce8a24bb 100644 --- a/packages/types-codec/src/native/Raw.spec.ts +++ b/packages/types-codec/src/native/Raw.spec.ts @@ -45,7 +45,7 @@ describe('Raw', (): void => { }); it('correctly encodes length', (): void => { - expect(u8a.$encodedLength).toEqual(5); + expect(u8a.encodedLength).toEqual(5); }); it('allows wrapping of a pre-existing instance', (): void => { @@ -98,7 +98,7 @@ describe('Raw', (): void => { it('has a sane inspect', (): void => { expect( - new Raw(registry, [1, 2, 3, 4, 5]).inspectU8a() + new Raw(registry, [1, 2, 3, 4, 5]).inspect() ).toEqual({ outer: [new Uint8Array([1, 2, 3, 4, 5])] }); diff --git a/packages/types-codec/src/native/Raw.ts b/packages/types-codec/src/native/Raw.ts index 1e9190698f..039e5a4a45 100644 --- a/packages/types-codec/src/native/Raw.ts +++ b/packages/types-codec/src/native/Raw.ts @@ -6,8 +6,6 @@ import type { AnyJson, AnyU8a, Inspect, IU8a, Registry } from '../types'; import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util'; -import { warnGet } from '../utils'; - /** * @name Raw * @description @@ -18,11 +16,11 @@ import { warnGet } from '../utils'; * @noInheritDoc */ export class Raw extends Uint8Array implements IU8a { - readonly $registry: Registry; + readonly registry: Registry; - public $createdAtHash?: IU8a; - public $initialU8aLength?: number; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; /** * @description This ensures that operators such as clice, filter, map, etc. return @@ -35,39 +33,14 @@ export class Raw extends Uint8Array implements IU8a { constructor (registry: Registry, value?: AnyU8a, initialU8aLength?: number) { super(u8aToU8a(value)); - this.$registry = registry; - this.$initialU8aLength = initialU8aLength; - } - - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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'); + this.registry = registry; + this.initialU8aLength = initialU8aLength; } /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { return this.length; } @@ -75,7 +48,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()); } /** @@ -88,7 +61,7 @@ export class Raw extends Uint8Array implements IU8a { /** * @description Returns true if the type wraps an empty/default all-0 value */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return !this.length || isUndefined(this.find((b) => !!b)); } @@ -121,7 +94,7 @@ export class Raw extends Uint8Array implements IU8a { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { return { outer: [this.toU8a()] }; diff --git a/packages/types-codec/src/native/Set.spec.ts b/packages/types-codec/src/native/Set.spec.ts index bf1138aac2..7691381ee8 100644 --- a/packages/types-codec/src/native/Set.spec.ts +++ b/packages/types-codec/src/native/Set.spec.ts @@ -33,7 +33,7 @@ describe('Set', (): void => { it('constructs via an string[]', (): void => { const set = new CodecSet(registry, SET_ROLES, ['full', 'authority']); - expect(set.$isEmpty).toEqual(false); + expect(set.isEmpty).toEqual(false); expect(set.toString()).toEqual( '[full, authority]' ); @@ -97,7 +97,7 @@ describe('Set', (): void => { }); it('has a sane inspect', (): void => { - expect(set.inspectU8a()).toEqual({ + expect(set.inspect()).toEqual({ outer: [new Uint8Array([SET_ROLES.full | SET_ROLES.authority])] }); }); diff --git a/packages/types-codec/src/native/Set.ts b/packages/types-codec/src/native/Set.ts index 4828ea21be..2d1d08491e 100644 --- a/packages/types-codec/src/native/Set.ts +++ b/packages/types-codec/src/native/Set.ts @@ -6,7 +6,7 @@ import type { CodecClass, Inspect, ISet, IU8a, Registry } from '../types'; import { BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util'; -import { compareArray, warnGet } from '../utils'; +import { compareArray } from '../utils'; type SetValues = Record; @@ -92,11 +92,11 @@ 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; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; readonly #allowed: SetValues; readonly #byteLength: number; @@ -104,36 +104,11 @@ 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; } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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 { @@ -158,7 +133,7 @@ export class CodecSet extends Set implements ISet { /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { return this.#byteLength; } @@ -166,13 +141,13 @@ 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()); } /** * @description true is the Set contains no values */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return this.size === 0; } @@ -225,7 +200,7 @@ export class CodecSet extends Set implements ISet { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { return { outer: [this.toU8a()] }; diff --git a/packages/types-codec/src/native/Struct.spec.ts b/packages/types-codec/src/native/Struct.spec.ts index 28389afae2..55b53924f3 100644 --- a/packages/types-codec/src/native/Struct.spec.ts +++ b/packages/types-codec/src/native/Struct.spec.ts @@ -207,7 +207,7 @@ describe('Struct', (): void => { txt: Text, u32: U32 }) - )(registry, { foo: 'bazzing', bar: 69 }).$encodedLength + )(registry, { foo: 'bazzing', bar: 69 }).encodedLength ).toEqual(5); }); @@ -380,7 +380,7 @@ describe('Struct', (): void => { it('has a sane inspect', (): void => { expect( - new Struct(registry, def, val).inspectU8a() + new Struct(registry, def, val).inspect() ).toEqual({ inner: [ { diff --git a/packages/types-codec/src/native/Struct.ts b/packages/types-codec/src/native/Struct.ts index 5b501d76a2..31223efb6c 100644 --- a/packages/types-codec/src/native/Struct.ts +++ b/packages/types-codec/src/native/Struct.ts @@ -6,7 +6,7 @@ import type { AnyJson, BareOpts, Codec, CodecClass, Inspect, IStruct, IU8a, Regi import { isBoolean, isFunction, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util'; -import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap, warnGet } from '../utils'; +import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap } from '../utils'; type TypesDef = Record>; @@ -103,11 +103,11 @@ 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; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; readonly #jsonMap: Map; readonly #Types: Definition; @@ -122,37 +122,12 @@ export class Struct< super(decoded); - this.$initialU8aLength = decodedLength; - this.$registry = registry; + this.initialU8aLength = decodedLength; + this.registry = registry; this.#jsonMap = jsonMap; this.#Types = typeMap; } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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; @@ -185,9 +160,9 @@ export class Struct< /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { for (const v of this.values()) { - if (!v.$isEmpty) { + if (!v.isEmpty) { return false; } } @@ -198,11 +173,11 @@ export class Struct< /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { let total = 0; for (const v of this.values()) { - total += v.$encodedLength; + total += v.encodedLength; } return total; @@ -212,7 +187,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()); } /** @@ -223,7 +198,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; @@ -261,12 +236,12 @@ export class Struct< /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (isBare?: BareOpts): Inspect { + public inspect (isBare?: BareOpts): Inspect { const inner = new Array(); for (const [k, v] of this.entries()) { inner.push({ - ...v.inspectU8a( + ...v.inspect( !isBare || isBoolean(isBare) ? isBare : isBare[k] @@ -345,7 +320,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.spec.ts b/packages/types-codec/src/native/Text.spec.ts index 3647159e8b..71909d450f 100644 --- a/packages/types-codec/src/native/Text.spec.ts +++ b/packages/types-codec/src/native/Text.spec.ts @@ -59,20 +59,20 @@ describe('Text', (): void => { it('calulates the length & encoded length correctly for ASCII', (): void => { const test = new Text(registry, 'abcde'); - expect(test.$encodedLength).toEqual(6); + expect(test.encodedLength).toEqual(6); expect(test).toHaveLength(5); }); it('calulates the length & encoded length correctly for non-ASCII', (): void => { const test = new Text(registry, '中文'); - expect(test.$encodedLength).toEqual(7); + expect(test.encodedLength).toEqual(7); expect(test).toHaveLength(2); }); it('has a sane inspect', (): void => { expect( - new Text(registry, 'abcde').inspectU8a() + new Text(registry, 'abcde').inspect() ).toEqual({ outer: [new Uint8Array([5 << 2]), stringToU8a('abcde')] }); diff --git a/packages/types-codec/src/native/Text.ts b/packages/types-codec/src/native/Text.ts index 3010cc1613..f74de59b91 100644 --- a/packages/types-codec/src/native/Text.ts +++ b/packages/types-codec/src/native/Text.ts @@ -6,7 +6,6 @@ import type { AnyString, AnyU8a, Inspect, IText, IU8a, Registry } from '../types import { compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util'; -import { warnGet } from '../utils'; import { Raw } from './Raw'; const MAX_LENGTH = 128 * 1024; @@ -50,11 +49,11 @@ 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; - public $isStorageFallback?: boolean; + public createdAtHash?: IU8a; + public initialU8aLength?: number; + public isStorageFallback?: boolean; #override: string | null = null; @@ -63,39 +62,14 @@ export class Text extends String implements IText { super(str); - this.$registry = registry; - this.$initialU8aLength = decodedLength; - } - - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - public get encodedLength (): number { - return warnGet(this, 'encodedLength'); - } - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - public get initialU8aLength (): number | undefined { - return warnGet(this, 'initialU8aLength'); - } - - /** @deprecated Use $isEmpty instead. This getter will be removed in a future version */ - public get isEmpty (): boolean { - 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'); + this.registry = registry; + this.initialU8aLength = decodedLength; } /** * @description The length of the value when encoded as a Uint8Array */ - public get $encodedLength (): number { + public get encodedLength (): number { return this.toU8a().length; } @@ -103,13 +77,13 @@ 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()); } /** * @description Checks if the value is an empty value */ - public get $isEmpty (): boolean { + public get isEmpty (): boolean { return this.length === 0; } @@ -133,7 +107,7 @@ export class Text extends String implements IText { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public inspectU8a (): Inspect { + public inspect (): Inspect { const value = stringToU8a(super.toString()); return { diff --git a/packages/types-codec/src/types/codec.ts b/packages/types-codec/src/types/codec.ts index 73c4669cac..5b3fa73810 100644 --- a/packages/types-codec/src/types/codec.ts +++ b/packages/types-codec/src/types/codec.ts @@ -14,23 +14,6 @@ export interface Inspect { outer?: Uint8Array[]; } -interface CodecDeprecated { - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - readonly createdAtHash: IU8a | undefined; - - /** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */ - readonly encodedLength: number; - - /** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */ - readonly initialU8aLength: number | undefined; - - /** @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; -} - /** * @name Codec * @description @@ -39,32 +22,20 @@ interface CodecDeprecated { * with getters and functions. The Codec Base is however required for operating * as an encoding/decoding layer */ -export interface Codec extends CodecDeprecated { +export interface Codec { /** * @description * The block at which this value was retrieved/created (set to non-empty when * retrieved from storage) */ - $createdAtHash?: IU8a; - - /** - * @description - * The length of the value when encoded as a Uint8Array (which is the SCALE representation) - */ - readonly $encodedLength: number; + createdAtHash?: IU8a; /** * @description * The length of the initial encoded value (Only available when the value was * constructed from a Uint8Array input) */ - $initialU8aLength?: number; - - /** - * @description - * Checks if the value is an empty value, with the internal bytes all-zero - */ - $isEmpty: boolean; + initialU8aLength?: number; /** * @description @@ -76,20 +47,28 @@ export interface Codec extends CodecDeprecated { * any empty storage item should erturn the default. (This is the same as the * implementation on the Substrate runtime) */ - $isStorageFallback?: boolean; + isStorageFallback?: boolean; /** - * @description - * The type registry associated with this object, as available when this type - * was initially created. - */ - readonly $registry: Registry; + * @description The length of the value when encoded as a Uint8Array + */ + readonly encodedLength: number; /** * @description Returns a hash of the value */ readonly hash: IU8a; + /** + * @description Checks if the value is an empty value + */ + readonly isEmpty: boolean; + + /** + * @description The registry associated with this object + */ + readonly registry: Registry; + /** * @description Compares the value of the input to see if there is a match */ @@ -98,7 +77,7 @@ export interface Codec extends CodecDeprecated { /** * @description Returns a breakdown of the hex encoding for this Codec */ - inspectU8a (isBare?: BareOpts): Inspect; + inspect (isBare?: BareOpts): Inspect; /** * @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation diff --git a/packages/types-codec/src/types/interfaces.ts b/packages/types-codec/src/types/interfaces.ts index 0e0725ed4a..d32a0ae89d 100644 --- a/packages/types-codec/src/types/interfaces.ts +++ b/packages/types-codec/src/types/interfaces.ts @@ -14,11 +14,10 @@ export interface ICompact extends Codec { } export interface IEnum extends Codec { - readonly $isBasic: boolean; - readonly defIndexes: number[]; readonly defKeys: string[]; readonly index: number; + readonly isBasic: boolean; readonly type: string; readonly value: Codec; diff --git a/packages/types-codec/src/types/registry.ts b/packages/types-codec/src/types/registry.ts index bcf4796d28..eb963f60f8 100644 --- a/packages/types-codec/src/types/registry.ts +++ b/packages/types-codec/src/types/registry.ts @@ -53,7 +53,7 @@ export interface Registry { readonly chainSS58: number | undefined; readonly chainTokens: string[]; - $createdAtHash?: IU8a; + createdAtHash?: IU8a; findMetaCall (callIndex: Uint8Array): CallFunction; findMetaError (errorIndex: Uint8Array | { error: BN, index: BN } | { error: BN | Uint8Array, index: BN }): RegistryError; diff --git a/packages/types-codec/src/utils/decodeU8a.ts b/packages/types-codec/src/utils/decodeU8a.ts index d950d2a720..d52f8f663b 100644 --- a/packages/types-codec/src/utils/decodeU8a.ts +++ b/packages/types-codec/src/utils/decodeU8a.ts @@ -41,7 +41,7 @@ export function decodeU8a (registry: Registry, result: while (i < count) { const value = new Types[i](registry, u8a.subarray(offset)); - offset += value.$initialU8aLength || value.$encodedLength; + offset += value.initialU8aLength || value.encodedLength; result[i] = value; i++; } @@ -67,7 +67,7 @@ export function decodeU8aStruct (registry: Registry, result: [string, Codec][], while (i < count) { const value = new Types[i](registry, u8a.subarray(offset)); - offset += value.$initialU8aLength || value.$encodedLength; + offset += value.initialU8aLength || value.encodedLength; result[i] = [keys[i], value]; i++; } @@ -93,7 +93,7 @@ export function decodeU8aVec (registry: Registry, resu while (i < count) { const value = new Type(registry, u8a.subarray(offset)); - offset += value.$initialU8aLength || value.$encodedLength; + offset += value.initialU8aLength || value.encodedLength; result[i] = value; i++; } diff --git a/packages/types-codec/src/utils/index.ts b/packages/types-codec/src/utils/index.ts index 6b8cbfa245..8001d8b0fd 100644 --- a/packages/types-codec/src/utils/index.ts +++ b/packages/types-codec/src/utils/index.ts @@ -10,4 +10,3 @@ export { typeToConstructor } from './typeToConstructor'; export { sanitize } from './sanitize'; export { sortAsc, sortSet, sortMap } from './sortValues'; export { typesToMap } from './typesToMap'; -export { warnGet } from './warnGet'; diff --git a/packages/types-codec/src/utils/warnGet.ts b/packages/types-codec/src/utils/warnGet.ts deleted file mode 100644 index d7d279ec08..0000000000 --- a/packages/types-codec/src/utils/warnGet.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2017-2023 @polkadot/types-codec authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -type Getters = 'createdAtHash' | 'encodedLength' | 'hash' | 'initialU8aLength' | 'isBasic' | 'isEmpty' | 'isNone' | 'isUnsigned' | 'registry'; - -const hasWarned: Record = {}; - -/** @description Warns (once, per class) on the use of a deprecated interface */ -export function warnGet (obj: Record, name: Getters): T { - const clazz = `${obj.constructor?.name || 'Codec'}`; - const check = `${clazz}.${name}`; - const pass = `$${name}`; - - if (!hasWarned[check]) { - hasWarned[check] = true; - - console.warn(`Use ${clazz}.${pass} instead. The use of ${check} is deprecated and will be removed in a future version.`); - } - - return obj[pass] as T; -} diff --git a/packages/types-create/src/create/type.ts b/packages/types-create/src/create/type.ts index a4f8d750f5..b53d7f51f3 100644 --- a/packages/types-create/src/create/type.ts +++ b/packages/types-create/src/create/type.ts @@ -24,7 +24,7 @@ function checkInstance (created: Codec, matcher: Uint8Array): void { ) || ( // when the created is empty and matcher is also empty, let it slide... - created.$isEmpty && + created.isEmpty && matcher.every((v) => !v) ) ); @@ -54,11 +54,11 @@ function initType (registry: Registry, Type: CodecClass, params isPedantic && checkPedantic(created, params); if (blockHash) { - created.$createdAtHash = createTypeUnsafe(registry, 'BlockHash', [blockHash]); + created.createdAtHash = createTypeUnsafe(registry, 'BlockHash', [blockHash]); } if (isFallback) { - created.$isStorageFallback = true; + created.isStorageFallback = true; } return created as T; diff --git a/packages/types/src/checkTypes.manual.ts b/packages/types/src/checkTypes.manual.ts index 4794a1c02f..27195dc3a3 100644 --- a/packages/types/src/checkTypes.manual.ts +++ b/packages/types/src/checkTypes.manual.ts @@ -98,4 +98,4 @@ const tt9 = registry.createType('(u32, (u32, u64), Vec, Vec<(u32, u64)>, [u8 // tuple with nested fixed const tta = registry.createType('([u8;32], [u16;5])'); -assert(tt1[2].bitLength() && tt2.bitLength() && tt4[3].bitLength() && tt5.$isEmpty && tt6[1].toHuman() && tt7.toHuman() && tt8.toHuman() && tt9.toHuman() && tta[1][1].bitLength(), 'All ok'); +assert(tt1[2].bitLength() && tt2.bitLength() && tt4[3].bitLength() && tt5.isEmpty && tt6[1].toHuman() && tt7.toHuman() && tt8.toHuman() && tt9.toHuman() && tta[1][1].bitLength(), 'All ok'); diff --git a/packages/types/src/create/createType.spec.ts b/packages/types/src/create/createType.spec.ts index 5c3d3c6153..6bc7107d96 100644 --- a/packages/types/src/create/createType.spec.ts +++ b/packages/types/src/create/createType.spec.ts @@ -22,7 +22,7 @@ describe('createType', (): void => { expect(f64.toRawType()).toEqual('Fixed64'); expect(f64.bitLength()).toEqual(64); - expect(f64.$isUnsigned).toBe(false); + expect(f64.isUnsigned).toBe(false); expect(f64 instanceof Int).toBe(true); }); diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index b351297b86..b7f3f79f73 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -7,7 +7,7 @@ import type { ExtDef } from '../extrinsic/signedExtensions/types'; import type { ChainProperties, DispatchErrorModule, DispatchErrorModuleU8, DispatchErrorModuleU8a, EventMetadataLatest, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types'; import type { CallFunction, CodecHasher, Definitions, DetectCodec, RegisteredTypes, Registry, RegistryError, RegistryTypes } from '../types'; -import { DoNotConstruct, Json, Raw, warnGet } from '@polkadot/types-codec'; +import { DoNotConstruct, Json, Raw } from '@polkadot/types-codec'; import { constructTypeClass, createClassUnsafe, createTypeUnsafe } from '@polkadot/types-create'; import { assertReturn, BN_ZERO, formatBalance, isFunction, isNumber, isString, isU8a, lazyMethod, logger, objectSpread, stringCamelCase, stringify } from '@polkadot/util'; import { blake2AsU8a } from '@polkadot/util-crypto'; @@ -186,7 +186,7 @@ export class TypeRegistry implements Registry { readonly #metadataEvents: Record>> = {}; readonly #moduleMap: Record = {}; - public $createdAtHash?: Hash; + public createdAtHash?: Hash; constructor (createdAtHash?: Hash | Uint8Array | string) { this.#knownDefaults = objectSpread({ Json, Metadata, PortableRegistry, Raw }, baseTypes); @@ -199,15 +199,10 @@ export class TypeRegistry implements Registry { } if (createdAtHash) { - this.$createdAtHash = this.createType('BlockHash', createdAtHash); + this.createdAtHash = this.createType('BlockHash', createdAtHash); } } - /** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */ - public get createdAtHash (): IU8a | undefined { - return warnGet(this, 'createdAtHash'); - } - public get chainDecimals (): number[] { if (this.#chainProperties?.tokenDecimals.isSome) { const allDecimals = this.#chainProperties.tokenDecimals.unwrap(); diff --git a/packages/types/src/ethereum/AccountId.spec.ts b/packages/types/src/ethereum/AccountId.spec.ts index f105401706..460ceec58f 100644 --- a/packages/types/src/ethereum/AccountId.spec.ts +++ b/packages/types/src/ethereum/AccountId.spec.ts @@ -19,7 +19,7 @@ describe('EthereumAccountId', (): void => { }); it('is empty by default', (): void => { - expect(id.$isEmpty).toBe(true); + expect(id.isEmpty).toBe(true); }); it('equals the empty address', (): void => { @@ -77,7 +77,7 @@ describe('EthereumAccountId', (): void => { ])); it('decodes to a non-empty value', (): void => { - expect(registry.createType('EthereumAccountId', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887').$isEmpty).toBe(false); + expect(registry.createType('EthereumAccountId', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887').isEmpty).toBe(false); }); }); }); diff --git a/packages/types/src/ethereum/LookupSource.ts b/packages/types/src/ethereum/LookupSource.ts index 28f4633226..af611452f6 100644 --- a/packages/types/src/ethereum/LookupSource.ts +++ b/packages/types/src/ethereum/LookupSource.ts @@ -69,7 +69,7 @@ export class GenericEthereumLookupSource extends AbstractBase extends AbstractBase extends ExtrinsicBa /** * @description Returns a breakdown of the hex encoding for this Codec */ - override inspectU8a (): Inspect { + override inspect (): Inspect { const encoded = u8aConcat(...this.toU8aInner()); return { inner: this.isSigned - ? this.inner.inspectU8a().inner - : this.inner.method.inspectU8a().inner, + ? this.inner.inspect().inner + : this.inner.method.inspect().inner, outer: [compactToU8a(encoded.length), new Uint8Array([this.version])] }; } diff --git a/packages/types/src/extrinsic/ExtrinsicEra.ts b/packages/types/src/extrinsic/ExtrinsicEra.ts index da97a10ea6..3aa3aaba47 100644 --- a/packages/types/src/extrinsic/ExtrinsicEra.ts +++ b/packages/types/src/extrinsic/ExtrinsicEra.ts @@ -142,7 +142,7 @@ export class MortalEra extends Tuple { /** * @description Encoded length for mortals occupy 2 bytes, different from the actual Tuple since it is encoded. This is a shortcut fro `toU8a().length` */ - public override get $encodedLength (): number { + public override get encodedLength (): number { return 2; } @@ -247,10 +247,10 @@ export class GenericExtrinsicEra extends Enum implements IExtrinsicEra { /** * @description Override the encoded length method */ - public override get $encodedLength (): number { + public override get encodedLength (): number { return this.isImmortalEra - ? this.asImmortalEra.$encodedLength - : this.asMortalEra.$encodedLength; + ? this.asImmortalEra.encodedLength + : this.asMortalEra.encodedLength; } /** diff --git a/packages/types/src/extrinsic/ExtrinsicPayload.spec.ts b/packages/types/src/extrinsic/ExtrinsicPayload.spec.ts index 6d4cf4f438..46b18a28fe 100644 --- a/packages/types/src/extrinsic/ExtrinsicPayload.spec.ts +++ b/packages/types/src/extrinsic/ExtrinsicPayload.spec.ts @@ -23,7 +23,7 @@ describe('ExtrinsicPayload', (): void => { const a = new ExtrinsicPayload(registry, TEST, { version: 4 }); const b = new ExtrinsicPayload(registry, a.toU8a(), { version: 4 }); - expect(a.inspectU8a()).toEqual(b.inspectU8a()); + expect(a.inspect()).toEqual(b.inspect()); expect(a.toJSON()).toEqual(b.toJSON()); }); @@ -31,7 +31,7 @@ describe('ExtrinsicPayload', (): void => { const a = new ExtrinsicPayload(registry, TEST, { version: 4 }); const b = new ExtrinsicPayload(registry, a.toHex(), { version: 4 }); - expect(a.inspectU8a()).toEqual(b.inspectU8a()); + expect(a.inspect()).toEqual(b.inspect()); expect(a.toJSON()).toEqual(b.toJSON()); }); diff --git a/packages/types/src/extrinsic/ExtrinsicPayload.ts b/packages/types/src/extrinsic/ExtrinsicPayload.ts index c17c9f6426..2d6fc1a068 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 587f03b622..6097d5f155 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/Extrinsic.ts b/packages/types/src/extrinsic/v4/Extrinsic.ts index 7c38d2e506..1e9c277e16 100644 --- a/packages/types/src/extrinsic/v4/Extrinsic.ts +++ b/packages/types/src/extrinsic/v4/Extrinsic.ts @@ -40,7 +40,7 @@ export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl { } else if (isU8a(value)) { // here we decode manually since we need to pull through the version information const signature = registry.createTypeUnsafe('ExtrinsicSignatureV4', [value, { isSigned }]); - const method = registry.createTypeUnsafe('Call', [value.subarray(signature.$encodedLength)]); + const method = registry.createTypeUnsafe('Call', [value.subarray(signature.encodedLength)]); return { method, @@ -54,7 +54,7 @@ export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl { /** * @description The length of the value when encoded as a Uint8Array */ - public override get $encodedLength (): number { + public override get encodedLength (): number { return this.toU8a().length; } diff --git a/packages/types/src/extrinsic/v4/ExtrinsicPayload.spec.ts b/packages/types/src/extrinsic/v4/ExtrinsicPayload.spec.ts index e195443bce..9dee87b5f1 100644 --- a/packages/types/src/extrinsic/v4/ExtrinsicPayload.spec.ts +++ b/packages/types/src/extrinsic/v4/ExtrinsicPayload.spec.ts @@ -18,7 +18,7 @@ describe('ExtrinsicPayload', (): void => { it('has a sane inspect', (): void => { // we don't expect this to fail, however it is actually a good // reference for the ordering in base Substrate - expect(new ExtrinsicPayload(registry, { method: tx.timestamp.set(0).toHex() } as never).inspectU8a()).toEqual({ + expect(new ExtrinsicPayload(registry, { method: tx.timestamp.set(0).toHex() } as never).inspect()).toEqual({ inner: [ { name: 'method', outer: [new Uint8Array([3, 0, 0])] }, { name: 'era', outer: [new Uint8Array([0]), new Uint8Array([0])] }, diff --git a/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts b/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts index 379fa971a4..45f42df141 100644 --- a/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts +++ b/packages/types/src/extrinsic/v4/ExtrinsicPayload.ts @@ -40,8 +40,8 @@ export class GenericExtrinsicPayloadV4 extends Struct { /** * @description Returns a breakdown of the hex encoding for this Codec */ - public override inspectU8a (): Inspect { - return super.inspectU8a({ method: true }); + public override inspect (): Inspect { + return super.inspect({ method: true }); } /** @@ -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 4eef330c39..75173e97e5 100644 --- a/packages/types/src/extrinsic/v4/ExtrinsicSignature.ts +++ b/packages/types/src/extrinsic/v4/ExtrinsicSignature.ts @@ -62,9 +62,9 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig /** * @description The length of the value when encoded as a Uint8Array */ - public override get $encodedLength (): number { + public override get encodedLength (): number { return this.isSigned - ? super.$encodedLength + ? super.encodedLength : 0; } @@ -72,7 +72,7 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig * @description `true` if the signature is valid */ public get isSigned (): boolean { - return !this.signature.$isEmpty; + return !this.signature.isEmpty; } /** @@ -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.spec.ts b/packages/types/src/generic/AccountId.spec.ts index 6bb3edcba7..37d83d6c98 100644 --- a/packages/types/src/generic/AccountId.spec.ts +++ b/packages/types/src/generic/AccountId.spec.ts @@ -19,7 +19,7 @@ describe('AccountId', (): void => { }); it('is empty by default', (): void => { - expect(id.$isEmpty).toBe(true); + expect(id.isEmpty).toBe(true); }); it('equals the empty address', (): void => { @@ -125,7 +125,7 @@ describe('AccountId', (): void => { expect( registry .createType('AccountId', 'FVU8T5yaAssHAUwo3PnKso7fqNthEqJZGCZgJZSR9cKjWAf') - .$isEmpty + .isEmpty ).toBe(false); }); diff --git a/packages/types/src/generic/AccountId.ts b/packages/types/src/generic/AccountId.ts index 247c499c09..83bcda91aa 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 9ab5791e9c..9cce6f457b 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 80bb0a25b3..aaf4dda287 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 54dbbf8e2c..ef13bafb48 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 48c271bd1a..4c8fbe319f 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/LookupSource.ts b/packages/types/src/generic/LookupSource.ts index a8861159a0..df414027e4 100644 --- a/packages/types/src/generic/LookupSource.ts +++ b/packages/types/src/generic/LookupSource.ts @@ -70,7 +70,7 @@ export class GenericLookupSource extends AbstractBase { it('has a custom u64 (64-bit) encodedLength', (): void => { expect( - registry.createType('IdentityFields').$encodedLength + registry.createType('IdentityFields').encodedLength ).toEqual(8); }); diff --git a/packages/types/src/metadata/MagicNumber.ts b/packages/types/src/metadata/MagicNumber.ts index b0276e5201..27805a84f2 100644 --- a/packages/types/src/metadata/MagicNumber.ts +++ b/packages/types/src/metadata/MagicNumber.ts @@ -11,7 +11,7 @@ export class MagicNumber extends U32 { constructor (registry: Registry, value?: AnyNumber) { super(registry, value); - if (!this.$isEmpty && !this.eq(MAGIC_NUMBER)) { + if (!this.isEmpty && !this.eq(MAGIC_NUMBER)) { throw new Error(`MagicNumber mismatch: expected ${registry.createTypeUnsafe('u32', [MAGIC_NUMBER]).toHex()}, found ${this.toHex()}`); } } diff --git a/packages/types/src/metadata/MetadataVersioned.ts b/packages/types/src/metadata/MetadataVersioned.ts index 94aef281fa..19e61c9798 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 f7f9fdda20..ef59b0468d 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/metadata/decorate/constants/index.ts b/packages/types/src/metadata/decorate/constants/index.ts index 3ac1d6000f..ea90f9ab80 100644 --- a/packages/types/src/metadata/decorate/constants/index.ts +++ b/packages/types/src/metadata/decorate/constants/index.ts @@ -17,7 +17,7 @@ export function decorateConstants (registry: Registry, { pallets }: MetadataLate for (let i = 0; i < pallets.length; i++) { const { constants, name } = pallets[i]; - if (!constants.$isEmpty) { + if (!constants.isEmpty) { lazyMethod(result, stringCamelCase(name), () => lazyMethods( {}, diff --git a/packages/types/src/primitive/Data.ts b/packages/types/src/primitive/Data.ts index b88d3ca90f..e7412aec26 100644 --- a/packages/types/src/primitive/Data.ts +++ b/packages/types/src/primitive/Data.ts @@ -108,7 +108,7 @@ export class Data extends Enum { /** * @description The encoded length */ - public override get $encodedLength (): number { + public override get encodedLength (): number { return this.toU8a().length; } diff --git a/packages/types/src/primitive/StorageKey.ts b/packages/types/src/primitive/StorageKey.ts index 07a09d19e5..ce507df8b6 100644 --- a/packages/types/src/primitive/StorageKey.ts +++ b/packages/types/src/primitive/StorageKey.ts @@ -108,7 +108,7 @@ function decodeHashers (registry: Registry, value: Uint8Arr ? registry.createTypeUnsafe(getSiName(registry.lookup, type), [value.subarray(offset + hashLen)]) : registry.createTypeUnsafe('Raw', [value.subarray(offset, offset + hashLen)]); - offset += hashLen + (canDecode ? decoded.$encodedLength : 0); + offset += hashLen + (canDecode ? decoded.encodedLength : 0); result[i] = decoded; } @@ -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... }