From 9e5d82a5e7dcfaa4a9e3a0b1876790a759c98014 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 14 Apr 2025 11:46:29 -0300 Subject: [PATCH 01/18] Initial scafolding --- .../src/interfaces/metadata/definitions.ts | 5 ++- packages/types/src/interfaces/metadata/v16.ts | 20 +++++++++++ .../types/src/metadata/MetadataVersioned.ts | 14 ++++++-- packages/types/src/metadata/util/testUtil.ts | 1 + packages/types/src/metadata/v15/toV16.ts | 36 +++++++++++++++++++ .../src/metadata/{v15 => v16}/toLatest.ts | 6 ++-- packages/types/src/metadata/versions.ts | 2 +- 7 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 packages/types/src/interfaces/metadata/v16.ts create mode 100644 packages/types/src/metadata/v15/toV16.ts rename packages/types/src/metadata/{v15 => v16}/toLatest.ts (68%) diff --git a/packages/types/src/interfaces/metadata/definitions.ts b/packages/types/src/interfaces/metadata/definitions.ts index 7fd8d861abc..1315490d2eb 100644 --- a/packages/types/src/interfaces/metadata/definitions.ts +++ b/packages/types/src/interfaces/metadata/definitions.ts @@ -15,6 +15,7 @@ import { v12 } from './v12.js'; import { v13 } from './v13.js'; import { v14 } from './v14.js'; import { v15 } from './v15.js'; +import { v16 } from './v16.js'; export { AllHashers }; @@ -30,6 +31,7 @@ export default { ...v13, ...v14, ...v15, + ...v16, // latest mappings // NOTE: For v15, we only added the runtime defintions, @@ -76,7 +78,8 @@ export default { V12: 'MetadataV12', V13: 'MetadataV13', V14: 'MetadataV14', - V15: 'MetadataV15' + V15: 'MetadataV15', + V16: 'MetadataV16' } } } diff --git a/packages/types/src/interfaces/metadata/v16.ts b/packages/types/src/interfaces/metadata/v16.ts new file mode 100644 index 00000000000..04733713984 --- /dev/null +++ b/packages/types/src/interfaces/metadata/v16.ts @@ -0,0 +1,20 @@ +// Copyright 2017-2025 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +// order important in structs... :) +/* eslint-disable sort-keys */ + +import type { DefinitionsTypes } from '../../types/index.js'; + +export const v16: DefinitionsTypes = { + // actual v16 definition + MetadataV16: { + lookup: 'PortableRegistry', + pallets: 'Vec', + extrinsic: 'ExtrinsicMetadataV15', + type: 'SiLookupTypeId', + apis: 'Vec', + outerEnums: 'OuterEnums15', + custom: 'CustomMetadata15' + } +}; diff --git a/packages/types/src/metadata/MetadataVersioned.ts b/packages/types/src/metadata/MetadataVersioned.ts index 8ae3a3d2dd1..dbf5a09d7e1 100644 --- a/packages/types/src/metadata/MetadataVersioned.ts +++ b/packages/types/src/metadata/MetadataVersioned.ts @@ -3,7 +3,7 @@ import type { AnyJson } from '@polkadot/types-codec/types'; import type { HexString } from '@polkadot/util/types'; -import type { MetadataAll, MetadataLatest, MetadataV9, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV15 } from '../interfaces/metadata/index.js'; +import type { MetadataAll, MetadataLatest, MetadataV9, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV15, MetadataV16 } from '../interfaces/metadata/index.js'; import type { Registry } from '../types/index.js'; import type { MetaVersionAll, MetaVersionAsX } from './versions.js'; @@ -16,9 +16,10 @@ import { toV12 } from './v11/toV12.js'; import { toV13 } from './v12/toV13.js'; import { toV14 } from './v13/toV14.js'; import { toV15 } from './v14/toV15.js'; -import { toLatest } from './v15/toLatest.js'; +import { toV16 } from './v15/toV16.js'; import { MagicNumber } from './MagicNumber.js'; import { LATEST_VERSION, TO_CALLS_VERSION } from './versions.js'; +import { toLatest } from './v16/toLatest.js'; type MetaMapped = MetadataAll[MetaVersionAsX]; type MetaVersions = Exclude | 'latest'; @@ -130,12 +131,19 @@ export class MetadataVersioned extends Struct { } /** - * @description Returns the wrapped values as a V14 object + * @description Returns the wrapped values as a V15 object */ public get asV15 (): MetadataV15 { return this.#getVersion(15, toV15); } + /** + * @description Returns the wrapped values as a V16 object + */ + public get asV16 (): MetadataV16 { + return this.#getVersion(16, toV16); + } + /** * @description Returns the wrapped values as a latest version object */ diff --git a/packages/types/src/metadata/util/testUtil.ts b/packages/types/src/metadata/util/testUtil.ts index 8362af91f99..7b619edd2c8 100644 --- a/packages/types/src/metadata/util/testUtil.ts +++ b/packages/types/src/metadata/util/testUtil.ts @@ -34,6 +34,7 @@ interface MetadataJson { v13: MetadataJsonDef; v14: MetadataJsonDef; v15: MetadataJsonDef; + v16: MetadataJsonDef; } } diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts new file mode 100644 index 00000000000..fb768868778 --- /dev/null +++ b/packages/types/src/metadata/v15/toV16.ts @@ -0,0 +1,36 @@ +// Copyright 2017-2025 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { MetadataV15, MetadataV16 } from '../../interfaces/metadata/index.js'; +import type { Registry } from '../../types/index.js'; + +import { objectSpread } from '@polkadot/util'; + +/** + * Convert the Metadata to v16 + * @internal + **/ +//TODO: return the correct information type +export function toV16 (registry: Registry, v15: MetadataV15, _: number): MetadataV16 { + + //const unchecked = v14.lookup.paramTypes.SpRuntimeUncheckedExtrinsic; + + return registry.createTypeUnsafe('MetadataV16', [ + /* objectSpread({}, v14, { + extrinsic: registry.createTypeUnsafe('ExtrinsicMetadataV15', [ + objectSpread({}, v14.extrinsic, { + addressType: unchecked?.[0].type.unwrapOr(0), + callType: unchecked?.[1].type.unwrapOr(0), + extraType: unchecked?.[3].type.unwrapOr(0), + signatureType: unchecked?.[2].type.unwrapOr(0) + }) + ]), + outerEnums: registry.createTypeUnsafe('OuterEnums15', [{ + // FIXME We need to extract & add the errorType in here + // (these doesn't seem to be an esay way to detect & extract it) + callType: unchecked?.[1].type.unwrapOr(0), + eventType: v14.lookup.paramTypes.FrameSystemEventRecord?.[0].type.unwrapOr(0) + }]) + }) */ + ]); +} diff --git a/packages/types/src/metadata/v15/toLatest.ts b/packages/types/src/metadata/v16/toLatest.ts similarity index 68% rename from packages/types/src/metadata/v15/toLatest.ts rename to packages/types/src/metadata/v16/toLatest.ts index 646e8a1f2c3..2ae9f109dd7 100644 --- a/packages/types/src/metadata/v15/toLatest.ts +++ b/packages/types/src/metadata/v16/toLatest.ts @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import type { Registry } from '@polkadot/types-codec/types'; -import type { MetadataLatest, MetadataV15 } from '../../interfaces/metadata/index.js'; +import type { MetadataLatest, MetadataV16 } from '../../interfaces/metadata/index.js'; /** * Convert the Metadata (which is an alias) to latest * @internal **/ -export function toLatest (_registry: Registry, v15: MetadataV15, _metaVersion: number): MetadataLatest { - return v15; +export function toLatest (_registry: Registry, v16: MetadataV16, _metaVersion: number): MetadataLatest { + return v16; } diff --git a/packages/types/src/metadata/versions.ts b/packages/types/src/metadata/versions.ts index 33877d49e17..0abf5400f70 100644 --- a/packages/types/src/metadata/versions.ts +++ b/packages/types/src/metadata/versions.ts @@ -3,7 +3,7 @@ // Use these to generate all the Meta* types below via template keys // NOTE: Keep from latest -> earliest, see the LATEST_VERSION 0 index -export const KNOWN_VERSIONS = [15, 14, 13, 12, 11, 10, 9] as const; +export const KNOWN_VERSIONS = [16, 15, 14, 13, 12, 11, 10, 9] as const; export const LATEST_VERSION = KNOWN_VERSIONS[0]; // This is part of migration. The toCallsOnly would be usede for esxtensions, From 55fc3ccf59871a954eff4c001f90a4bd338f970e Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Wed, 16 Apr 2025 10:15:42 -0300 Subject: [PATCH 02/18] metadatav16 generated types --- packages/api/src/base/Init.ts | 4 +- packages/typegen/src/generate/runtime.ts | 1 + packages/typegen/src/interfacesTs.ts | 1 + .../types-augment/src/registry/interfaces.ts | 17 +- packages/types/src/create/registry.ts | 39 +++-- .../src/interfaces/metadata/definitions.ts | 21 +-- .../types/src/interfaces/metadata/types.ts | 151 ++++++++++++++++-- packages/types/src/interfaces/metadata/v16.ts | 124 +++++++++++++- scripts/metadata-get.mjs | 4 +- 9 files changed, 321 insertions(+), 41 deletions(-) diff --git a/packages/api/src/base/Init.ts b/packages/api/src/base/Init.ts index 2b177a4428f..1da7ba86447 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -22,7 +22,9 @@ import { Decorate } from './Decorate.js'; const KEEPALIVE_INTERVAL = 10000; const WITH_VERSION_SHORTCUT = false; -const SUPPORTED_METADATA_VERSIONS = [15, 14]; + +//TODO: Remove U32::MAX when metadata 16 is stabilized. +const SUPPORTED_METADATA_VERSIONS = [4294967295, 16 ,15, 14]; const l = logger('api/init'); diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index 641a22d9184..11ee06467e6 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -1,6 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 +//TODO: Replace RuntimeApiMethodMetadataV15 to v16 import type { RuntimeApiMethodMetadataV15, SiLookupTypeId } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { DefinitionCall, DefinitionCallNamed, Definitions, DefinitionsCall, Registry } from '@polkadot/types/types'; diff --git a/packages/typegen/src/interfacesTs.ts b/packages/typegen/src/interfacesTs.ts index 7e0ce59d445..d5813bb9306 100644 --- a/packages/typegen/src/interfacesTs.ts +++ b/packages/typegen/src/interfacesTs.ts @@ -3,6 +3,7 @@ import type { HexString } from '@polkadot/util/types'; +//TODO: replace v15 to v16 once metadata is updated import kusama from '@polkadot/types-support/metadata/v15/kusama-hex'; import polkadot from '@polkadot/types-support/metadata/v15/polkadot-hex'; import substrate from '@polkadot/types-support/metadata/v15/substrate-hex'; diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index e6f512ed5a4..d62b3c0fe3b 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -44,7 +44,7 @@ import type { AuthorityIndex, AuthorityList, AuthoritySet, AuthoritySetChange, A import type { IdentityFields, IdentityInfo, IdentityInfoAdditional, IdentityInfoTo198, IdentityJudgement, RegistrarIndex, RegistrarInfo, Registration, RegistrationJudgement, RegistrationTo198 } from '@polkadot/types/interfaces/identity'; import type { AuthIndex, AuthoritySignature, Heartbeat, HeartbeatTo244, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline'; import type { CallIndex, LotteryConfig } from '@polkadot/types/interfaces/lottery'; -import type { CustomMetadata15, CustomValueMetadata15, ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, ExtrinsicMetadataV15, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV15, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, OpaqueMetadata, OuterEnums15, PalletCallMetadataLatest, PalletCallMetadataV14, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletEventMetadataLatest, PalletEventMetadataV14, PalletMetadataLatest, PalletMetadataV14, PalletMetadataV15, PalletStorageMetadataLatest, PalletStorageMetadataV14, PortableType, PortableTypeV14, RuntimeApiMetadataLatest, RuntimeApiMetadataV15, RuntimeApiMethodMetadataV15, RuntimeApiMethodParamMetadataV15, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata'; +import type { CustomMetadata15, CustomValueMetadata15, DeprecationInfoV16, DeprecationStatusV16, ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, ExtrinsicMetadataV15, ExtrinsicMetadataV16, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV15, MetadataV16, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, OpaqueMetadata, OuterEnums15, PalletCallMetadataLatest, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataLatest, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataLatest, PalletMetadataV14, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataLatest, PalletStorageMetadataV14, PalletStorageMetadataV16, PortableType, PortableTypeV14, RuntimeApiMetadataLatest, RuntimeApiMetadataV15, RuntimeApiMetadataV16, RuntimeApiMethodMetadataV15, RuntimeApiMethodMetadataV16, RuntimeApiMethodParamMetadataV15, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV16, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9, TransactionExtensionMetadataLatest, TransactionExtensionMetadataV16 } from '@polkadot/types/interfaces/metadata'; import type { Mixnode, MixnodesErr, SessionPhase, SessionStatus } from '@polkadot/types/interfaces/mixnet'; import type { MmrBatchProof, MmrEncodableOpaqueLeaf, MmrError, MmrHash, MmrLeafBatchProof, MmrLeafIndex, MmrLeafProof, MmrNodeIndex, MmrProof } from '@polkadot/types/interfaces/mmr'; import type { NftCollectionId, NftItemId } from '@polkadot/types/interfaces/nfts'; @@ -362,6 +362,8 @@ declare module '@polkadot/types/types/registry' { DeliveredMessages: DeliveredMessages; DepositBalance: DepositBalance; DepositBalanceOf: DepositBalanceOf; + DeprecationInfoV16: DeprecationInfoV16; + DeprecationStatusV16: DeprecationStatusV16; DestroyWitness: DestroyWitness; Digest: Digest; DigestItem: DigestItem; @@ -501,6 +503,7 @@ declare module '@polkadot/types/types/registry' { ExtrinsicMetadataV13: ExtrinsicMetadataV13; ExtrinsicMetadataV14: ExtrinsicMetadataV14; ExtrinsicMetadataV15: ExtrinsicMetadataV15; + ExtrinsicMetadataV16: ExtrinsicMetadataV16; ExtrinsicOrHash: ExtrinsicOrHash; ExtrinsicPayload: ExtrinsicPayload; ExtrinsicPayloadUnknown: ExtrinsicPayloadUnknown; @@ -708,6 +711,7 @@ declare module '@polkadot/types/types/registry' { MetadataV13: MetadataV13; MetadataV14: MetadataV14; MetadataV15: MetadataV15; + MetadataV16: MetadataV16; MetadataV9: MetadataV9; MigrationStatusResult: MigrationStatusResult; Mixnode: Mixnode; @@ -829,21 +833,27 @@ declare module '@polkadot/types/types/registry' { PageIndexData: PageIndexData; PalletCallMetadataLatest: PalletCallMetadataLatest; PalletCallMetadataV14: PalletCallMetadataV14; + PalletCallMetadataV16: PalletCallMetadataV16; PalletConstantMetadataLatest: PalletConstantMetadataLatest; PalletConstantMetadataV14: PalletConstantMetadataV14; + PalletConstantMetadataV16: PalletConstantMetadataV16; PalletErrorMetadataLatest: PalletErrorMetadataLatest; PalletErrorMetadataV14: PalletErrorMetadataV14; + PalletErrorMetadataV16: PalletErrorMetadataV16; PalletEventMetadataLatest: PalletEventMetadataLatest; PalletEventMetadataV14: PalletEventMetadataV14; + PalletEventMetadataV16: PalletEventMetadataV16; PalletId: PalletId; PalletInfoV3: PalletInfoV3; PalletInfoV4: PalletInfoV4; PalletMetadataLatest: PalletMetadataLatest; PalletMetadataV14: PalletMetadataV14; PalletMetadataV15: PalletMetadataV15; + PalletMetadataV16: PalletMetadataV16; PalletsOrigin: PalletsOrigin; PalletStorageMetadataLatest: PalletStorageMetadataLatest; PalletStorageMetadataV14: PalletStorageMetadataV14; + PalletStorageMetadataV16: PalletStorageMetadataV16; PalletVersion: PalletVersion; ParachainDispatchOrigin: ParachainDispatchOrigin; ParachainInherentData: ParachainInherentData; @@ -982,7 +992,9 @@ declare module '@polkadot/types/types/registry' { RpcMethods: RpcMethods; RuntimeApiMetadataLatest: RuntimeApiMetadataLatest; RuntimeApiMetadataV15: RuntimeApiMetadataV15; + RuntimeApiMetadataV16: RuntimeApiMetadataV16; RuntimeApiMethodMetadataV15: RuntimeApiMethodMetadataV15; + RuntimeApiMethodMetadataV16: RuntimeApiMethodMetadataV16; RuntimeApiMethodParamMetadataV15: RuntimeApiMethodParamMetadataV15; RuntimeCall: RuntimeCall; RuntimeDbWeight: RuntimeDbWeight; @@ -1127,6 +1139,7 @@ declare module '@polkadot/types/types/registry' { StorageEntryMetadataV12: StorageEntryMetadataV12; StorageEntryMetadataV13: StorageEntryMetadataV13; StorageEntryMetadataV14: StorageEntryMetadataV14; + StorageEntryMetadataV16: StorageEntryMetadataV16; StorageEntryMetadataV9: StorageEntryMetadataV9; StorageEntryModifierLatest: StorageEntryModifierLatest; StorageEntryModifierV10: StorageEntryModifierV10; @@ -1179,6 +1192,8 @@ declare module '@polkadot/types/types/registry' { TraceBlockResponse: TraceBlockResponse; TraceError: TraceError; TransactionalError: TransactionalError; + TransactionExtensionMetadataLatest: TransactionExtensionMetadataLatest; + TransactionExtensionMetadataV16: TransactionExtensionMetadataV16; TransactionInfo: TransactionInfo; TransactionLongevity: TransactionLongevity; TransactionPriority: TransactionPriority; diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index 0dd2b8be538..8f8aecb751d 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -605,17 +605,34 @@ export class TypeRegistry implements Registry { } } - // setup the available extensions - this.setSignedExtensions( - signedExtensions || ( - this.#metadata.extrinsic.version.gt(BN_ZERO) - // FIXME Use the extension and their injected types - ? this.#metadata.extrinsic.signedExtensions.map(({ identifier }) => identifier.toString()) - : fallbackExtensions - ), - userExtensions, - noInitWarn - ); + console.log(this.#metadataVersion) + if (this.#metadataVersion < 16){ + console.log(this.#metadata.extrinsic) + // setup the available extensions + this.setSignedExtensions( + signedExtensions || ( + this.#metadata.extrinsic.version.gt(BN_ZERO) + // FIXME Use the extension and their injected types + ? this.#metadata.extrinsic.signedExtensions.map(({ identifier }) => identifier.toString()) + : fallbackExtensions + ), + userExtensions, + noInitWarn + ); + }/* else { + // setup the available extensions + this.setSignedExtensions( + signedExtensions || ( + this.#metadata.extrinsic?.versions?.gt(BN_ZERO) + // FIXME Use the extension and their injected types + ? this.#metadata.extrinsic.signedExtensions.map(({ identifier }) => identifier.toString()) + : fallbackExtensions + ), + userExtensions, + noInitWarn + ); + } */ + // setup the chain properties with format overrides this.setChainProperties( diff --git a/packages/types/src/interfaces/metadata/definitions.ts b/packages/types/src/interfaces/metadata/definitions.ts index 1315490d2eb..6ef8f8c0c8a 100644 --- a/packages/types/src/interfaces/metadata/definitions.ts +++ b/packages/types/src/interfaces/metadata/definitions.ts @@ -38,20 +38,21 @@ export default { // hence latest for most pointing to the previous V14 ErrorMetadataLatest: 'ErrorMetadataV14', EventMetadataLatest: 'EventMetadataV14', - ExtrinsicMetadataLatest: 'ExtrinsicMetadataV15', + ExtrinsicMetadataLatest: 'ExtrinsicMetadataV16', FunctionArgumentMetadataLatest: 'FunctionArgumentMetadataV14', FunctionMetadataLatest: 'FunctionMetadataV14', - MetadataLatest: 'MetadataV15', - PalletCallMetadataLatest: 'PalletCallMetadataV14', - PalletConstantMetadataLatest: 'PalletConstantMetadataV14', - PalletErrorMetadataLatest: 'PalletErrorMetadataV14', - PalletEventMetadataLatest: 'PalletEventMetadataV14', - PalletMetadataLatest: 'PalletMetadataV15', - PalletStorageMetadataLatest: 'PalletStorageMetadataV14', + MetadataLatest: 'MetadataV16', + PalletCallMetadataLatest: 'PalletCallMetadataV16', + PalletConstantMetadataLatest: 'PalletConstantMetadataV16', + PalletErrorMetadataLatest: 'PalletErrorMetadataV16', + PalletEventMetadataLatest: 'PalletEventMetadataV16', + PalletMetadataLatest: 'PalletMetadataV16', + PalletStorageMetadataLatest: 'PalletStorageMetadataV16', PortableType: 'PortableTypeV14', - RuntimeApiMetadataLatest: 'RuntimeApiMetadataV15', + RuntimeApiMetadataLatest: 'RuntimeApiMetadataV16', SignedExtensionMetadataLatest: 'SignedExtensionMetadataV14', - StorageEntryMetadataLatest: 'StorageEntryMetadataV14', + TransactionExtensionMetadataLatest: 'TransactionExtensionMetadataV16', + StorageEntryMetadataLatest: 'StorageEntryMetadataV16', StorageEntryModifierLatest: 'StorageEntryModifierV14', StorageEntryTypeLatest: 'StorageEntryTypeV14', StorageHasher: 'StorageHasherV14', diff --git a/packages/types/src/interfaces/metadata/types.ts b/packages/types/src/interfaces/metadata/types.ts index b60cd7bc889..4a4c8b587a3 100644 --- a/packages/types/src/interfaces/metadata/types.ts +++ b/packages/types/src/interfaces/metadata/types.ts @@ -2,7 +2,7 @@ /* eslint-disable */ import type { PortableRegistry } from '@polkadot/types'; -import type { BTreeMap, Bytes, Enum, Option, Struct, Text, Type, Vec, WrapperOpaque, bool, u8 } from '@polkadot/types-codec'; +import type { BTreeMap, Bytes, Compact, Enum, Option, Struct, Text, Type, Vec, WrapperOpaque, bool, u32, u8 } from '@polkadot/types-codec'; import type { Si1Field, Si1LookupTypeId, Si1Type, SiLookupTypeId } from '@polkadot/types/interfaces/scaleInfo'; /** @name CustomMetadata15 */ @@ -16,6 +16,28 @@ export interface CustomValueMetadata15 extends Struct { readonly value: Bytes; } +/** @name DeprecationInfoV16 */ +export interface DeprecationInfoV16 extends Enum { + readonly isNotDeprecated: boolean; + readonly isItemDeprecated: boolean; + readonly asItemDeprecated: DeprecationStatusV16; + readonly isVariantsDeprecated: boolean; + readonly asVariantsDeprecated: BTreeMap; + readonly type: 'NotDeprecated' | 'ItemDeprecated' | 'VariantsDeprecated'; +} + +/** @name DeprecationStatusV16 */ +export interface DeprecationStatusV16 extends Enum { + readonly isNotDeprecated: boolean; + readonly isDeprecatedWithoutNote: boolean; + readonly isDeprecated: boolean; + readonly asDeprecated: { + readonly note: Text; + readonly since: Option; + } & Struct; + readonly type: 'NotDeprecated' | 'DeprecatedWithoutNote' | 'Deprecated'; +} + /** @name ErrorMetadataLatest */ export interface ErrorMetadataLatest extends ErrorMetadataV14 {} @@ -78,7 +100,7 @@ export interface EventMetadataV9 extends Struct { } /** @name ExtrinsicMetadataLatest */ -export interface ExtrinsicMetadataLatest extends ExtrinsicMetadataV15 {} +export interface ExtrinsicMetadataLatest extends ExtrinsicMetadataV16 {} /** @name ExtrinsicMetadataV11 */ export interface ExtrinsicMetadataV11 extends Struct { @@ -109,6 +131,15 @@ export interface ExtrinsicMetadataV15 extends Struct { readonly signedExtensions: Vec; } +/** @name ExtrinsicMetadataV16 */ +export interface ExtrinsicMetadataV16 extends Struct { + readonly versions: Bytes; + readonly addressType: SiLookupTypeId; + readonly signatureType: SiLookupTypeId; + readonly transactionExtensionsByVersion: BTreeMap>>; + readonly transactionExtensions: Vec; +} + /** @name FunctionArgumentMetadataLatest */ export interface FunctionArgumentMetadataLatest extends FunctionArgumentMetadataV14 {} @@ -184,11 +215,13 @@ export interface MetadataAll extends Enum { readonly asV14: MetadataV14; readonly isV15: boolean; readonly asV15: MetadataV15; - readonly type: 'V0' | 'V1' | 'V2' | 'V3' | 'V4' | 'V5' | 'V6' | 'V7' | 'V8' | 'V9' | 'V10' | 'V11' | 'V12' | 'V13' | 'V14' | 'V15'; + readonly isV16: boolean; + readonly asV16: MetadataV16; + readonly type: 'V0' | 'V1' | 'V2' | 'V3' | 'V4' | 'V5' | 'V6' | 'V7' | 'V8' | 'V9' | 'V10' | 'V11' | 'V12' | 'V13' | 'V14' | 'V15' | 'V16'; } /** @name MetadataLatest */ -export interface MetadataLatest extends MetadataV15 {} +export interface MetadataLatest extends MetadataV16 {} /** @name MetadataV10 */ export interface MetadataV10 extends Struct { @@ -232,6 +265,17 @@ export interface MetadataV15 extends Struct { readonly custom: CustomMetadata15; } +/** @name MetadataV16 */ +export interface MetadataV16 extends Struct { + readonly lookup: PortableRegistry; + readonly pallets: Vec; + readonly extrinsic: ExtrinsicMetadataV16; + readonly type: SiLookupTypeId; + readonly apis: Vec; + readonly outerEnums: OuterEnums15; + readonly custom: CustomMetadata15; +} + /** @name MetadataV9 */ export interface MetadataV9 extends Struct { readonly modules: Vec; @@ -320,15 +364,21 @@ export interface OuterEnums15 extends Struct { } /** @name PalletCallMetadataLatest */ -export interface PalletCallMetadataLatest extends PalletCallMetadataV14 {} +export interface PalletCallMetadataLatest extends PalletCallMetadataV16 {} /** @name PalletCallMetadataV14 */ export interface PalletCallMetadataV14 extends Struct { readonly type: SiLookupTypeId; } +/** @name PalletCallMetadataV16 */ +export interface PalletCallMetadataV16 extends Struct { + readonly type: SiLookupTypeId; + readonly deprecationInfo: DeprecationInfoV16; +} + /** @name PalletConstantMetadataLatest */ -export interface PalletConstantMetadataLatest extends PalletConstantMetadataV14 {} +export interface PalletConstantMetadataLatest extends PalletConstantMetadataV16 {} /** @name PalletConstantMetadataV14 */ export interface PalletConstantMetadataV14 extends Struct { @@ -338,24 +388,45 @@ export interface PalletConstantMetadataV14 extends Struct { readonly docs: Vec; } +/** @name PalletConstantMetadataV16 */ +export interface PalletConstantMetadataV16 extends Struct { + readonly name: Text; + readonly type: SiLookupTypeId; + readonly value: Bytes; + readonly docs: Vec; + readonly deprecationInfo: DeprecationInfoV16; +} + /** @name PalletErrorMetadataLatest */ -export interface PalletErrorMetadataLatest extends PalletErrorMetadataV14 {} +export interface PalletErrorMetadataLatest extends PalletErrorMetadataV16 {} /** @name PalletErrorMetadataV14 */ export interface PalletErrorMetadataV14 extends Struct { readonly type: SiLookupTypeId; } +/** @name PalletErrorMetadataV16 */ +export interface PalletErrorMetadataV16 extends Struct { + readonly type: SiLookupTypeId; + readonly deprecationInfo: DeprecationInfoV16; +} + /** @name PalletEventMetadataLatest */ -export interface PalletEventMetadataLatest extends PalletEventMetadataV14 {} +export interface PalletEventMetadataLatest extends PalletEventMetadataV16 {} /** @name PalletEventMetadataV14 */ export interface PalletEventMetadataV14 extends Struct { readonly type: SiLookupTypeId; } +/** @name PalletEventMetadataV16 */ +export interface PalletEventMetadataV16 extends Struct { + readonly type: SiLookupTypeId; + readonly deprecationInfo: DeprecationInfoV16; +} + /** @name PalletMetadataLatest */ -export interface PalletMetadataLatest extends PalletMetadataV15 {} +export interface PalletMetadataLatest extends PalletMetadataV16 {} /** @name PalletMetadataV14 */ export interface PalletMetadataV14 extends Struct { @@ -380,8 +451,20 @@ export interface PalletMetadataV15 extends Struct { readonly docs: Vec; } +/** @name PalletMetadataV16 */ +export interface PalletMetadataV16 extends Struct { + readonly name: Text; + readonly storage: Option; + readonly calls: Option; + readonly events: Option; + readonly constants: Vec; + readonly errors: Option; + readonly index: u8; + readonly docs: Vec; +} + /** @name PalletStorageMetadataLatest */ -export interface PalletStorageMetadataLatest extends PalletStorageMetadataV14 {} +export interface PalletStorageMetadataLatest extends PalletStorageMetadataV16 {} /** @name PalletStorageMetadataV14 */ export interface PalletStorageMetadataV14 extends Struct { @@ -389,6 +472,12 @@ export interface PalletStorageMetadataV14 extends Struct { readonly items: Vec; } +/** @name PalletStorageMetadataV16 */ +export interface PalletStorageMetadataV16 extends Struct { + readonly prefix: Text; + readonly entries: Vec; +} + /** @name PortableType */ export interface PortableType extends PortableTypeV14 {} @@ -399,7 +488,7 @@ export interface PortableTypeV14 extends Struct { } /** @name RuntimeApiMetadataLatest */ -export interface RuntimeApiMetadataLatest extends RuntimeApiMetadataV15 {} +export interface RuntimeApiMetadataLatest extends RuntimeApiMetadataV16 {} /** @name RuntimeApiMetadataV15 */ export interface RuntimeApiMetadataV15 extends Struct { @@ -408,6 +497,15 @@ export interface RuntimeApiMetadataV15 extends Struct { readonly docs: Vec; } +/** @name RuntimeApiMetadataV16 */ +export interface RuntimeApiMetadataV16 extends Struct { + readonly name: Text; + readonly methods: Vec; + readonly docs: Vec; + readonly deprecationInfo: DeprecationStatusV16; + readonly version: Compact; +} + /** @name RuntimeApiMethodMetadataV15 */ export interface RuntimeApiMethodMetadataV15 extends Struct { readonly name: Text; @@ -416,6 +514,15 @@ export interface RuntimeApiMethodMetadataV15 extends Struct { readonly docs: Vec; } +/** @name RuntimeApiMethodMetadataV16 */ +export interface RuntimeApiMethodMetadataV16 extends Struct { + readonly name: Text; + readonly inputs: Vec; + readonly output: SiLookupTypeId; + readonly docs: Vec; + readonly deprecationInfo: DeprecationStatusV16; +} + /** @name RuntimeApiMethodParamMetadataV15 */ export interface RuntimeApiMethodParamMetadataV15 extends Struct { readonly name: Text; @@ -433,7 +540,7 @@ export interface SignedExtensionMetadataV14 extends Struct { } /** @name StorageEntryMetadataLatest */ -export interface StorageEntryMetadataLatest extends StorageEntryMetadataV14 {} +export interface StorageEntryMetadataLatest extends StorageEntryMetadataV16 {} /** @name StorageEntryMetadataV10 */ export interface StorageEntryMetadataV10 extends Struct { @@ -474,6 +581,16 @@ export interface StorageEntryMetadataV14 extends Struct { readonly docs: Vec; } +/** @name StorageEntryMetadataV16 */ +export interface StorageEntryMetadataV16 extends Struct { + readonly name: Text; + readonly modifier: StorageEntryModifierV14; + readonly type: StorageEntryTypeV14; + readonly fallback: Bytes; + readonly docs: Vec; + readonly deprecationInfo: DeprecationStatusV16; +} + /** @name StorageEntryMetadataV9 */ export interface StorageEntryMetadataV9 extends Struct { readonly name: Text; @@ -694,4 +811,14 @@ export interface StorageMetadataV9 extends Struct { readonly items: Vec; } +/** @name TransactionExtensionMetadataLatest */ +export interface TransactionExtensionMetadataLatest extends TransactionExtensionMetadataV16 {} + +/** @name TransactionExtensionMetadataV16 */ +export interface TransactionExtensionMetadataV16 extends Struct { + readonly identifier: Text; + readonly type: SiLookupTypeId; + readonly implicit: SiLookupTypeId; +} + export type PHANTOM_METADATA = 'metadata'; diff --git a/packages/types/src/interfaces/metadata/v16.ts b/packages/types/src/interfaces/metadata/v16.ts index 04733713984..9e5fdb266c4 100644 --- a/packages/types/src/interfaces/metadata/v16.ts +++ b/packages/types/src/interfaces/metadata/v16.ts @@ -10,11 +10,127 @@ export const v16: DefinitionsTypes = { // actual v16 definition MetadataV16: { lookup: 'PortableRegistry', - pallets: 'Vec', - extrinsic: 'ExtrinsicMetadataV15', + pallets: 'Vec', + extrinsic: 'ExtrinsicMetadataV16', type: 'SiLookupTypeId', - apis: 'Vec', + apis: 'Vec', outerEnums: 'OuterEnums15', custom: 'CustomMetadata15' - } + }, + + //---- Pallet definitions ---- + PalletMetadataV16: { + name: 'Text', + storage: 'Option', + calls: 'Option', + events: 'Option', + constants: 'Vec', + errors: 'Option', + index: 'u8', + docs: 'Vec' + }, + PalletStorageMetadataV16: { + prefix: 'Text', + entries: 'Vec' + }, + StorageEntryMetadataV16: { + name: 'Text', + modifier: 'StorageEntryModifierV14', + type: 'StorageEntryTypeV14', + fallback: 'Bytes', + docs: 'Vec', + /// Deprecation info + deprecationInfo: 'DeprecationStatusV16', + }, + DeprecationStatusV16: { + _enum: { + /// Entry is not deprecated + NotDeprecated: 'Null', + /// Deprecated without a note. + DeprecatedWithoutNote: 'Null', + /// Entry is deprecated with an note and an optional `since` field. + Deprecated: { + /// Note explaining the deprecation + note: 'Text', + /// Optional value for denoting version when the deprecation occurred. + since: 'Option', + }, + } + }, + PalletCallMetadataV16: { + type: 'SiLookupTypeId', + /// Deprecation status of the pallet call + deprecationInfo: 'DeprecationInfoV16' + }, + DeprecationInfoV16: { + _enum: { + /// Type is not deprecated + NotDeprecated: 'Null', + /// Entry is fully deprecated. + ItemDeprecated: 'DeprecationStatusV16', + /// Entry is partially deprecated. + VariantsDeprecated: 'BTreeMap', + } + }, + PalletEventMetadataV16: { + type: 'SiLookupTypeId', + /// Deprecation info + deprecationInfo: 'DeprecationInfoV16', + }, + PalletConstantMetadataV16: { + name: 'Text', + type: 'SiLookupTypeId', + value: 'Bytes', + docs: 'Vec', + /// Deprecation info + deprecationInfo: 'DeprecationInfoV16', + }, + PalletErrorMetadataV16: { + type: 'SiLookupTypeId', + /// Deprecation info + deprecationInfo: 'DeprecationInfoV16', + }, + + //---- Extrinsic definitions ---- + ExtrinsicMetadataV16: { + /// Extrinsic versions supported by the runtime. + versions: 'Vec', + /// The type of the address that signs the extrinsic + addressType: 'SiLookupTypeId', + /// The type of the extrinsic's signature. + signatureType: 'SiLookupTypeId', + /// A mapping of supported transaction extrinsic versions to their respective transaction extension indexes. + /// + /// For each supported version number, list the indexes, in order, of the extensions used. + transactionExtensionsByVersion: 'BTreeMap>>', + /// The transaction extensions in the order they appear in the extrinsic. + transactionExtensions: 'Vec' + }, + TransactionExtensionMetadataV16: { + /// The unique transaction extension identifier, which may be different from the type name. + identifier: 'Text', + /// The type of the transaction extension, with the data to be included in the extrinsic. + type: 'SiLookupTypeId', + /// The type of the implicit data, with the data to be included in the signed payload. + implicit: 'SiLookupTypeId', + }, + + //---- Runtime Api definitions ---- + RuntimeApiMetadataV16: { + name: 'Text', + methods: 'Vec', + docs: 'Vec', + /// Deprecation info + deprecationInfo: 'DeprecationStatusV16', + /// Runtime API version. + version: 'Compact' + }, + RuntimeApiMethodMetadataV16: { + name: 'Text', + inputs: 'Vec', + output: 'SiLookupTypeId', + docs: 'Vec', + /// Deprecation info + deprecationInfo: 'DeprecationStatusV16', + }, }; diff --git a/scripts/metadata-get.mjs b/scripts/metadata-get.mjs index 0a47a32d930..60818c20315 100644 --- a/scripts/metadata-get.mjs +++ b/scripts/metadata-get.mjs @@ -16,8 +16,8 @@ const CMD = { }; // V15 -const META_VERSION_HEX = '0x0f000000'; -const META_VERSION = 15; +const META_VERSION_HEX = '0x10000000'; +const META_VERSION = 16; /** * Parse the specName given any exceptions. From 8838ab0439e30fe650203f283d90abbb702c8038 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Wed, 16 Apr 2025 11:29:33 -0300 Subject: [PATCH 03/18] Correct registry setSignedExtension --- packages/types/src/create/registry.ts | 39 ++++++++------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index 8f8aecb751d..d72c4df9ab1 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -605,34 +605,17 @@ export class TypeRegistry implements Registry { } } - console.log(this.#metadataVersion) - if (this.#metadataVersion < 16){ - console.log(this.#metadata.extrinsic) - // setup the available extensions - this.setSignedExtensions( - signedExtensions || ( - this.#metadata.extrinsic.version.gt(BN_ZERO) - // FIXME Use the extension and their injected types - ? this.#metadata.extrinsic.signedExtensions.map(({ identifier }) => identifier.toString()) - : fallbackExtensions - ), - userExtensions, - noInitWarn - ); - }/* else { - // setup the available extensions - this.setSignedExtensions( - signedExtensions || ( - this.#metadata.extrinsic?.versions?.gt(BN_ZERO) - // FIXME Use the extension and their injected types - ? this.#metadata.extrinsic.signedExtensions.map(({ identifier }) => identifier.toString()) - : fallbackExtensions - ), - userExtensions, - noInitWarn - ); - } */ - + // setup the available extensions + this.setSignedExtensions( + signedExtensions || ( + this.#metadata.extrinsic.versions.length > 0 && this.#metadata.extrinsic.versions.every(value => value > 0) + // FIXME Use the extension and their injected types + ? this.#metadata.extrinsic.transactionExtensions.map(({ identifier }) => identifier.toString()) + : fallbackExtensions + ), + userExtensions, + noInitWarn + ); // setup the chain properties with format overrides this.setChainProperties( From f0bf597dfe6c765c14eee0cbf4c754d6ccb41b29 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Thu, 17 Apr 2025 15:05:16 -0300 Subject: [PATCH 04/18] toV16() impl --- packages/types/src/metadata/v15/toV16.ts | 147 ++++++++++++++++++++--- 1 file changed, 128 insertions(+), 19 deletions(-) diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index fb768868778..46ae4bf04cc 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -1,36 +1,145 @@ // Copyright 2017-2025 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { MetadataV15, MetadataV16 } from '../../interfaces/metadata/index.js'; +import { type Vec } from '@polkadot/types-codec'; +import type { DeprecationInfoV16, DeprecationStatusV16, ExtrinsicMetadataV15, ExtrinsicMetadataV16, MetadataV15, MetadataV16, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataV14, PalletStorageMetadataV16, RuntimeApiMetadataV15, RuntimeApiMetadataV16, StorageEntryMetadataV16, TransactionExtensionMetadataV16 } from '../../interfaces/metadata/index.js'; import type { Registry } from '../../types/index.js'; import { objectSpread } from '@polkadot/util'; +function palletsFromV15(registry: Registry, palletV15: PalletMetadataV15): PalletMetadataV16 { + return registry.createTypeUnsafe('PalletMetadataV16', [ + objectSpread({}, palletV15, { + storage: palletV15.storage.isSome? convertStorage(registry, palletV15.storage.unwrap()) : null, + calls: palletV15.calls.isSome? convertCalls(registry, palletV15.calls.unwrap()) : null, + events: palletV15.events.isSome? convertEvents(registry, palletV15.events.unwrap()) : null, + constants: convertConstants(registry, palletV15.constants), + errors: palletV15.errors.isSome? converErrors(registry, palletV15.errors.unwrap()) : null, + }) + ]) +} + +function convertStorage(registry: Registry, storage: PalletStorageMetadataV14): PalletStorageMetadataV16 { + const deprecationInfo: DeprecationStatusV16 = registry.createTypeUnsafe('DeprecationStatusV16', ['NotDeprecated']); + + const entries: StorageEntryMetadataV16[] = storage.items.map((item) => + registry.createTypeUnsafe('StorageEntryMetadataV16', [{ + ...item, + deprecationInfo + }]) + ); + + return registry.createTypeUnsafe('PalletStorageMetadataV16', [{ + prefix: storage.prefix, + entries + }]); +} + +function convertCalls(registry: Registry, calls: PalletCallMetadataV14): PalletCallMetadataV16 { + const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); + + return registry.createTypeUnsafe('PalletCallMetadataV16', [{ + type: calls.type, + deprecationInfo + }]); +} + +function convertEvents(registry: Registry, events: PalletEventMetadataV14): PalletEventMetadataV16 { + const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); + + return registry.createTypeUnsafe('PalletEventMetadataV16', [{ + type: events.type, + deprecationInfo + }]); +} + +function convertConstants(registry: Registry, constants: Vec): Vec { + const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); + + return registry.createTypeUnsafe('Vec', [ + constants.map((constant) => registry.createTypeUnsafe('PalletConstantMetadataV16', [{ + ...constant, + deprecationInfo + }]))] + ) +} + + +function converErrors(registry: Registry, errors: PalletErrorMetadataV14): PalletErrorMetadataV16 { + const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); + + return registry.createTypeUnsafe('PalletErrorMetadataV16', [{ + type: errors.type, + deprecationInfo + }]); +} + +function extrinsicFromV15(registry: Registry, extrinsicV15: ExtrinsicMetadataV15): ExtrinsicMetadataV16 { + const transactionExtensions: TransactionExtensionMetadataV16[] = extrinsicV15.signedExtensions.map(({identifier, type, additionalSigned}) => + registry.createTypeUnsafe('TransactionExtensionMetadataV16', [{ + identifier, + type, + implict: additionalSigned + }]) + ); + + const indexes = transactionExtensions.map((_, i) => + registry.createTypeUnsafe('Compact', [i]) + ); + + const transactionExtensionsByVersion = registry.createTypeUnsafe( + 'BTreeMap>>', + [new Map([[registry.createTypeUnsafe('u8', [0]), registry.createTypeUnsafe('Vec>', [indexes])]])] + ); + + return registry.createTypeUnsafe('ExtrinsicMetadataV16', [ + { + versions: [extrinsicV15.version], + addressType: extrinsicV15.addressType, + signatureType: extrinsicV15.signatureType, + transactionExtensionsByVersion: transactionExtensionsByVersion, + transactionExtensions, + } + ]) +} + +function apisFromV15(registry: Registry, runtimeApiV15: RuntimeApiMetadataV15): RuntimeApiMetadataV16 { + const deprecationInfo: DeprecationStatusV16 = registry.createTypeUnsafe('DeprecationStatusV16', ['NotDeprecated']); + + + let methods = runtimeApiV15.methods.map((method) => + registry.createTypeUnsafe('RuntimeApiMethodMetadataV16', [{ + ...method, + deprecationInfo + }]) + ); + + return registry.createTypeUnsafe('RuntimeApiMetadataV16', [ + objectSpread({}, runtimeApiV15, { + methods, + version: registry.createTypeUnsafe('Compact', [0]), + deprecationInfo: deprecationInfo + }) + ]) +} + /** * Convert the Metadata to v16 * @internal **/ -//TODO: return the correct information type export function toV16 (registry: Registry, v15: MetadataV15, _: number): MetadataV16 { - //const unchecked = v14.lookup.paramTypes.SpRuntimeUncheckedExtrinsic; + const pallets: PalletMetadataV16[] = v15.pallets.map((pallet) => { + return palletsFromV15(registry, pallet) + }); + const extrinsic: ExtrinsicMetadataV16 = extrinsicFromV15(registry, v15.extrinsic); + const apis: RuntimeApiMetadataV16[] = v15.apis.map((runtimeApi) => apisFromV15(registry, runtimeApi)) ; return registry.createTypeUnsafe('MetadataV16', [ - /* objectSpread({}, v14, { - extrinsic: registry.createTypeUnsafe('ExtrinsicMetadataV15', [ - objectSpread({}, v14.extrinsic, { - addressType: unchecked?.[0].type.unwrapOr(0), - callType: unchecked?.[1].type.unwrapOr(0), - extraType: unchecked?.[3].type.unwrapOr(0), - signatureType: unchecked?.[2].type.unwrapOr(0) - }) - ]), - outerEnums: registry.createTypeUnsafe('OuterEnums15', [{ - // FIXME We need to extract & add the errorType in here - // (these doesn't seem to be an esay way to detect & extract it) - callType: unchecked?.[1].type.unwrapOr(0), - eventType: v14.lookup.paramTypes.FrameSystemEventRecord?.[0].type.unwrapOr(0) - }]) - }) */ + objectSpread({}, v15, { + pallets, + extrinsic, + apis + }) ]); } From f0aa705227ffb120df701fbe6bd76938e281fd90 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Thu, 17 Apr 2025 15:17:18 -0300 Subject: [PATCH 05/18] Remove references to MetadataV15 --- packages/api/src/base/Decorate.ts | 4 ++-- packages/typegen/src/generate/runtime.ts | 5 ++--- packages/typegen/src/metadataMd.ts | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index 121d020146f..0cf91303b5a 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -5,7 +5,7 @@ import type { Observable } from 'rxjs'; import type { AugmentedCall, DeriveCustom, QueryableCalls } from '@polkadot/api-base/types'; import type { RpcInterface } from '@polkadot/rpc-core/types'; import type { Metadata, StorageKey, Text, u64, Vec } from '@polkadot/types'; -import type { Call, Hash, RuntimeApiMethodMetadataV15, RuntimeVersion } from '@polkadot/types/interfaces'; +import type { Call, Hash, RuntimeApiMethodMetadataV16, RuntimeVersion } from '@polkadot/types/interfaces'; import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types'; import type { StorageEntry } from '@polkadot/types/primitive/types'; import type { AnyFunction, AnyJson, AnyTuple, CallFunction, Codec, DefinitionCall, DefinitionCallNamed, DefinitionRpc, DefinitionRpcSub, DefinitionsCall, DefinitionsCallEntry, DetectCodec, IMethod, IStorageKey, Registry, RegistryError, RegistryTypes } from '@polkadot/types/types'; @@ -494,7 +494,7 @@ export abstract class Decorate extends Events { } // Helper for _getRuntimeDefsViaMetadata - protected _getMethods (registry: Registry, methods: Vec) { + protected _getMethods (registry: Registry, methods: Vec) { const result: Record = {}; methods.forEach((m) => { diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index 11ee06467e6..1104d9697e9 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -1,8 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -//TODO: Replace RuntimeApiMethodMetadataV15 to v16 -import type { RuntimeApiMethodMetadataV15, SiLookupTypeId } from '@polkadot/types/interfaces'; +import type { RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { DefinitionCall, DefinitionCallNamed, Definitions, DefinitionsCall, Registry } from '@polkadot/types/types'; import type { Vec } from '@polkadot/types-codec'; @@ -53,7 +52,7 @@ const getTypesViaAlias = (registry: Registry, id: SiLookupTypeId) => { }; /** @internal */ -function getMethods (registry: Registry, methods: Vec) { +function getMethods (registry: Registry, methods: Vec) { const result: Record = {}; methods.forEach((m) => { diff --git a/packages/typegen/src/metadataMd.ts b/packages/typegen/src/metadataMd.ts index bfaf1a9779e..d5775dcdecb 100644 --- a/packages/typegen/src/metadataMd.ts +++ b/packages/typegen/src/metadataMd.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { MetadataLatest, RuntimeApiMethodMetadataV15, SiLookupTypeId } from '@polkadot/types/interfaces'; +import type { MetadataLatest, RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@polkadot/types/interfaces'; import type { PortableRegistry } from '@polkadot/types/metadata'; import type { Text } from '@polkadot/types/primitive'; import type { Codec, DefinitionCall, DefinitionRpcParam, DefinitionsCall, Registry } from '@polkadot/types/types'; @@ -255,7 +255,7 @@ function addRpc (_runtimeDesc: string, rpcMethods?: string[]): string { } /** @internal */ -function getMethods (registry: Registry, methods: Vec) { +function getMethods (registry: Registry, methods: Vec) { const result: Record = {}; methods.forEach((m) => { From d45b1311e9067d262a4ee708acec630684fe110e Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Thu, 17 Apr 2025 17:33:12 -0300 Subject: [PATCH 06/18] Fix toV16() conversion --- packages/types/src/create/registry.ts | 2 +- .../types/src/interfaces/metadata/types.ts | 2 +- packages/types/src/interfaces/metadata/v16.ts | 2 +- packages/types/src/metadata/v15/toV16.ts | 27 +++++++++---------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index d72c4df9ab1..193e5588d44 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -9,7 +9,7 @@ import type { CallFunction, CodecHasher, Definitions, DetectCodec, RegisteredTyp import { DoNotConstruct, Json, Raw } from '@polkadot/types-codec'; import { constructTypeClass, createClassUnsafe, createTypeUnsafe } from '@polkadot/types-create'; -import { assertReturn, BN_ZERO, formatBalance, isBn, isFunction, isNumber, isString, isU8a, lazyMethod, logger, objectSpread, stringCamelCase, stringify } from '@polkadot/util'; +import { assertReturn, formatBalance, isBn, isFunction, isNumber, isString, isU8a, lazyMethod, logger, objectSpread, stringCamelCase, stringify } from '@polkadot/util'; import { blake2AsU8a } from '@polkadot/util-crypto'; import { expandExtensionTypes, fallbackExtensions, findUnknownExtensions } from '../extrinsic/signedExtensions/index.js'; diff --git a/packages/types/src/interfaces/metadata/types.ts b/packages/types/src/interfaces/metadata/types.ts index 4a4c8b587a3..9fb784324e6 100644 --- a/packages/types/src/interfaces/metadata/types.ts +++ b/packages/types/src/interfaces/metadata/types.ts @@ -475,7 +475,7 @@ export interface PalletStorageMetadataV14 extends Struct { /** @name PalletStorageMetadataV16 */ export interface PalletStorageMetadataV16 extends Struct { readonly prefix: Text; - readonly entries: Vec; + readonly items: Vec; } /** @name PortableType */ diff --git a/packages/types/src/interfaces/metadata/v16.ts b/packages/types/src/interfaces/metadata/v16.ts index 9e5fdb266c4..83c4b505b0b 100644 --- a/packages/types/src/interfaces/metadata/v16.ts +++ b/packages/types/src/interfaces/metadata/v16.ts @@ -31,7 +31,7 @@ export const v16: DefinitionsTypes = { }, PalletStorageMetadataV16: { prefix: 'Text', - entries: 'Vec' + items: 'Vec' }, StorageEntryMetadataV16: { name: 'Text', diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index 46ae4bf04cc..f03b14081e1 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -22,16 +22,15 @@ function palletsFromV15(registry: Registry, palletV15: PalletMetadataV15): Palle function convertStorage(registry: Registry, storage: PalletStorageMetadataV14): PalletStorageMetadataV16 { const deprecationInfo: DeprecationStatusV16 = registry.createTypeUnsafe('DeprecationStatusV16', ['NotDeprecated']); - const entries: StorageEntryMetadataV16[] = storage.items.map((item) => - registry.createTypeUnsafe('StorageEntryMetadataV16', [{ - ...item, - deprecationInfo - }]) + const items: StorageEntryMetadataV16[] = storage.items.map((item) => + registry.createTypeUnsafe('StorageEntryMetadataV16', [ + objectSpread({}, item, deprecationInfo) + ]) ); return registry.createTypeUnsafe('PalletStorageMetadataV16', [{ prefix: storage.prefix, - entries + items: registry.createTypeUnsafe('Vec', [items]) }]); } @@ -57,10 +56,9 @@ function convertConstants(registry: Registry, constants: Vec', [ - constants.map((constant) => registry.createTypeUnsafe('PalletConstantMetadataV16', [{ - ...constant, - deprecationInfo - }]))] + constants.map((constant) => registry.createTypeUnsafe('PalletConstantMetadataV16', [ + objectSpread({}, constant, {deprecationInfo}) + ]))] ) } @@ -108,17 +106,16 @@ function apisFromV15(registry: Registry, runtimeApiV15: RuntimeApiMetadataV15): let methods = runtimeApiV15.methods.map((method) => - registry.createTypeUnsafe('RuntimeApiMethodMetadataV16', [{ - ...method, - deprecationInfo - }]) + registry.createTypeUnsafe('RuntimeApiMethodMetadataV16', + [objectSpread({}, method, {deprecationInfo})] + ) ); return registry.createTypeUnsafe('RuntimeApiMetadataV16', [ objectSpread({}, runtimeApiV15, { methods, + deprecationInfo, version: registry.createTypeUnsafe('Compact', [0]), - deprecationInfo: deprecationInfo }) ]) } From 78faad0ddc40997114ad87cb2a79156bc1f6077a Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 21 Apr 2025 10:14:36 -0300 Subject: [PATCH 07/18] Progress on deprecation notice --- packages/typegen/src/generate/consts.ts | 28 ++++++++++++++++++++++- packages/typegen/src/generate/query.ts | 28 +++++++++++++++++++++-- packages/types/src/extrinsic/Extrinsic.ts | 6 ++++- packages/types/src/metadata/v15/toV16.ts | 1 + 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/packages/typegen/src/generate/consts.ts b/packages/typegen/src/generate/consts.ts index 89e7ba3dc07..22e048b75e6 100644 --- a/packages/typegen/src/generate/consts.ts +++ b/packages/typegen/src/generate/consts.ts @@ -14,9 +14,26 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; +import type { DeprecationInfoV16 } from '@polkadot/types/interfaces'; const generateForMetaTemplate = Handlebars.compile(readTemplate('consts')); +//TODO: Figure out how to handle VariantsDeprecated +function getDeprecationNotice(deprecationInfo: DeprecationInfoV16): string | null { + if (deprecationInfo.isNotDeprecated) return null; + + let deprecationNotice = "@deprecated" + + if (deprecationInfo.isItemDeprecated && deprecationInfo.asItemDeprecated.isDeprecated) { + const { note, since } = deprecationInfo.asItemDeprecated.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + + deprecationNotice += ` ${note}${sinceText}`; + } + + return deprecationNotice +} + /** @internal */ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void { writeFile(dest, (): string => { @@ -45,9 +62,18 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, } const items = constants - .map(({ docs, name, type }) => { + .map(({ deprecationInfo, docs, name, type }) => { const typeDef = lookup.getTypeDef(type); const returnType = typeDef.lookupName || formatType(registry, allDefs, typeDef, imports); + const deprecationNotice = getDeprecationNotice(deprecationInfo); + + if (deprecationNotice) { + const items = docs.length + ? ["", deprecationNotice] + : [deprecationNotice]; + + docs.push(...items.map(text => registry.createType('Text', text))); + } // Add the type to the list of used types if (!(imports.primitiveTypes[returnType])) { diff --git a/packages/typegen/src/generate/query.ts b/packages/typegen/src/generate/query.ts index eee498dd776..d9128bbea18 100644 --- a/packages/typegen/src/generate/query.ts +++ b/packages/typegen/src/generate/query.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { StorageEntryMetadataLatest } from '@polkadot/types/interfaces'; +import type { DeprecationStatusV16, StorageEntryMetadataLatest } from '@polkadot/types/interfaces'; import type { Metadata, PortableRegistry } from '@polkadot/types/metadata'; import type { Definitions, Registry } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; @@ -20,6 +20,19 @@ import { ignoreUnusedLookups } from './lookup.js'; const generateForMetaTemplate = Handlebars.compile(readTemplate('query')); +function getDeprecationNotice(deprecationInfo: DeprecationStatusV16): string { + let deprecationNotice = "@deprecated" + + if (deprecationInfo.isDeprecated) { + const { note, since } = deprecationInfo.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + + deprecationNotice += ` ${note}${sinceText}`; + } + + return deprecationNotice +} + // From a storage entry metadata, we return [args, returnType] /** @internal */ function entrySignature (lookup: PortableRegistry, allDefs: Record, registry: Registry, section: string, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [boolean, string, string, string] { @@ -93,8 +106,19 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr .map(({ name, storage }) => { const items = storage.unwrap().items .map((storageEntry) => { + + let {deprecationInfo, docs} = storageEntry; const [isOptional, args, params, _returnType] = entrySignature(lookup, allDefs, registry, name.toString(), storageEntry, imports); + if (!deprecationInfo.isNotDeprecated){ + const deprecationNotice = getDeprecationNotice(deprecationInfo); + const items = docs.length + ? ["", deprecationNotice] + : [deprecationNotice]; + + docs.push(...items.map(text => registry.createType('Text', text))); + } + // Add the type and args to the list of used types if (!(imports.primitiveTypes[_returnType])) { usedTypes.add(_returnType); @@ -110,7 +134,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr return { args, - docs: storageEntry.docs, + docs: docs, entryType: 'AugmentedQuery', name: stringCamelCase(storageEntry.name), params, diff --git a/packages/types/src/extrinsic/Extrinsic.ts b/packages/types/src/extrinsic/Extrinsic.ts index 432593d86f3..58ee3552b4d 100644 --- a/packages/types/src/extrinsic/Extrinsic.ts +++ b/packages/types/src/extrinsic/Extrinsic.ts @@ -329,7 +329,11 @@ export class GenericExtrinsic extends ExtrinsicBa static LATEST_EXTRINSIC_VERSION = LATEST_EXTRINSIC_VERSION; constructor (registry: Registry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, { preamble, version }: CreateOptions = {}) { - super(registry, decodeExtrinsic(registry, value, version || registry.metadata.extrinsic.version?.toNumber(), preamble), undefined, preamble); + const versionsLength = registry.metadata.extrinsic.versions.length; + const highestSupportedVersion = versionsLength ? registry.metadata.extrinsic.versions[versionsLength -1] : undefined; + + console.log(registry.metadata.extrinsic.versions) + super(registry, decodeExtrinsic(registry, value, version || highestSupportedVersion, preamble), undefined, preamble); } /** diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index f03b14081e1..ceb9e1118d6 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -85,6 +85,7 @@ function extrinsicFromV15(registry: Registry, extrinsicV15: ExtrinsicMetadataV15 registry.createTypeUnsafe('Compact', [i]) ); + //TODO: Metadata: Revise Version, should it match extrinsicV15.version? const transactionExtensionsByVersion = registry.createTypeUnsafe( 'BTreeMap>>', [new Map([[registry.createTypeUnsafe('u8', [0]), registry.createTypeUnsafe('Vec>', [indexes])]])] From 46f7320b21040c3fbb0873d01ecf30e518b5d004 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 21 Apr 2025 16:26:54 -0300 Subject: [PATCH 08/18] Add deprecationInfo to code generation --- packages/typegen/src/generate/consts.ts | 20 ++--- packages/typegen/src/generate/errors.ts | 50 +++++++++--- packages/typegen/src/generate/events.ts | 99 ++++++++++++++++-------- packages/typegen/src/generate/query.ts | 16 ++-- packages/typegen/src/generate/runtime.ts | 31 +++++++- packages/typegen/src/generate/tx.ts | 38 ++++++++- packages/types/src/metadata/v15/toV16.ts | 10 +-- 7 files changed, 194 insertions(+), 70 deletions(-) diff --git a/packages/typegen/src/generate/consts.ts b/packages/typegen/src/generate/consts.ts index 22e048b75e6..f7c301a7071 100644 --- a/packages/typegen/src/generate/consts.ts +++ b/packages/typegen/src/generate/consts.ts @@ -14,21 +14,20 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; -import type { DeprecationInfoV16 } from '@polkadot/types/interfaces'; +import type { DeprecationInfoV16, DeprecationStatusV16 } from '@polkadot/types/interfaces'; const generateForMetaTemplate = Handlebars.compile(readTemplate('consts')); -//TODO: Figure out how to handle VariantsDeprecated -function getDeprecationNotice(deprecationInfo: DeprecationInfoV16): string | null { - if (deprecationInfo.isNotDeprecated) return null; - +function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { let deprecationNotice = "@deprecated" - - if (deprecationInfo.isItemDeprecated && deprecationInfo.asItemDeprecated.isDeprecated) { - const { note, since } = deprecationInfo.asItemDeprecated.asDeprecated; + + if (deprecationStatus.isDeprecated) { + const { note, since } = deprecationStatus.asDeprecated; const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; deprecationNotice += ` ${note}${sinceText}`; + }else { + deprecationNotice += ` Const ${name} has been deprecated` } return deprecationNotice @@ -65,9 +64,10 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, .map(({ deprecationInfo, docs, name, type }) => { const typeDef = lookup.getTypeDef(type); const returnType = typeDef.lookupName || formatType(registry, allDefs, typeDef, imports); - const deprecationNotice = getDeprecationNotice(deprecationInfo); - if (deprecationNotice) { + if (!deprecationInfo.isNotDeprecated){ + const deprecationNotice = getDeprecationNotice(deprecationInfo.asItemDeprecated, stringCamelCase(name)); + const items = docs.length ? ["", deprecationNotice] : [deprecationNotice]; diff --git a/packages/typegen/src/generate/errors.ts b/packages/typegen/src/generate/errors.ts index 2b339cf0fb4..57f712f89a1 100644 --- a/packages/typegen/src/generate/errors.ts +++ b/packages/typegen/src/generate/errors.ts @@ -10,9 +10,25 @@ import Handlebars from 'handlebars'; import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, initMeta, readTemplate, writeFile } from '../util/index.js'; +import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; const generateForMetaTemplate = Handlebars.compile(readTemplate('errors')); +function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = "@deprecated" + + if (deprecationStatus.isDeprecated) { + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + + deprecationNotice += ` ${note}${sinceText}`; + }else { + deprecationNotice += ` ${name} has been deprecated` + } + + return deprecationNotice +} + /** @internal */ function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void { writeFile(dest, (): string => { @@ -20,15 +36,31 @@ function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void const { lookup, pallets } = meta.asLatest; const modules = pallets .filter(({ errors }) => errors.isSome) - .map(({ errors, name }) => ({ - items: lookup.getSiType(errors.unwrap().type).def.asVariant.variants - .map(({ docs, name }) => ({ - docs, - name: name.toString() - })) - .sort(compareName), - name: stringCamelCase(name) - })) + .map((data) => { + let name = data.name; + let errors = data.errors.unwrap() + return { + items: lookup.getSiType(errors.type).def.asVariant.variants + .map(({ docs, name, index }) => { + if (errors.deprecationInfo.isVariantsDeprecated) { + const rawStatus = errors.deprecationInfo.asVariantsDeprecated.toJSON()?.[index.toNumber()]; + + if (rawStatus) { + const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe("DeprecationStatusV16", [rawStatus]); + if (!deprecationStatus.isNotDeprecated){ + const deprecationNotice = getDeprecationNotice(deprecationStatus, name.toString()); + const notices = docs.length ? ["", deprecationNotice] : [deprecationNotice]; + docs.push(...notices.map(text => meta.registry.createType('Text', text))); + } + } + } + return { + docs, + name: name.toString() + }}) + .sort(compareName), + name: stringCamelCase(name) + }}) .sort(compareName); return generateForMetaTemplate({ diff --git a/packages/typegen/src/generate/events.ts b/packages/typegen/src/generate/events.ts index f292c7a8628..65b829bc6e8 100644 --- a/packages/typegen/src/generate/events.ts +++ b/packages/typegen/src/generate/events.ts @@ -14,6 +14,7 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; +import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; const generateForMetaTemplate = Handlebars.compile(readTemplate('events')); @@ -61,6 +62,21 @@ const ALIAS = [ 'yield' ]; +function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = "@deprecated" + + if (deprecationStatus.isDeprecated) { + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + + deprecationNotice += ` ${note}${sinceText}`; + }else { + deprecationNotice += ` Event ${name} has been deprecated` + } + + return deprecationNotice +} + /** @internal */ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void { writeFile(dest, (): string => { @@ -82,39 +98,58 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, const usedTypes = new Set([]); const modules = pallets .filter(({ events }) => events.isSome) - .map(({ events, name }) => ({ - items: lookup.getSiType(events.unwrap().type).def.asVariant.variants - .map(({ docs, fields, name }) => { - const args = fields - .map(({ type }) => lookup.getTypeDef(type)) - .map((typeDef) => { - const arg = typeDef.lookupName || formatType(registry, allDefs, typeDef, imports); - - // Add the type to the list of used types - if (!(imports.primitiveTypes[arg])) { - usedTypes.add(arg); - } + .map((data) => { + let name = data.name; + let events = data.events.unwrap(); + + return { + items: lookup.getSiType(events.type).def.asVariant.variants + .map(({ docs, fields, name, index }) => { + if (events.deprecationInfo.isVariantsDeprecated) { + const rawStatus = events.deprecationInfo.asVariantsDeprecated.toJSON()?.[index.toNumber()]; + + if (rawStatus) { + const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe("DeprecationStatusV16", [rawStatus]); - return arg; - }); - - const names = fields - .map(({ name }) => registry.lookup.sanitizeField(name)[0]) - .filter((n): n is string => !!n); - - setImports(allDefs, imports, args); - - return { - docs, - name: name.toString(), - type: names.length !== 0 && names.length === args.length - ? `[${names.map((n, i) => `${ALIAS.includes(n) ? `${n}_` : n}: ${args[i]}`).join(', ')}], { ${names.map((n, i) => `${n}: ${args[i]}`).join(', ')} }` - : `[${args.join(', ')}]` - }; - }) - .sort(compareName), - name: stringCamelCase(name) - })) + if (!deprecationStatus.isNotDeprecated) { + const deprecationNotice = getDeprecationNotice(deprecationStatus, name.toString()); + const notice = docs.length ? ["", deprecationNotice] : [deprecationNotice]; + docs.push(...notice.map(text => meta.registry.createType('Text', text))); + + } + } + } + + const args = fields + .map(({ type }) => lookup.getTypeDef(type)) + .map((typeDef) => { + const arg = typeDef.lookupName || formatType(registry, allDefs, typeDef, imports); + + // Add the type to the list of used types + if (!(imports.primitiveTypes[arg])) { + usedTypes.add(arg); + } + + return arg; + }); + + const names = fields + .map(({ name }) => registry.lookup.sanitizeField(name)[0]) + .filter((n): n is string => !!n); + + setImports(allDefs, imports, args); + + return { + docs, + name: name.toString(), + type: names.length !== 0 && names.length === args.length + ? `[${names.map((n, i) => `${ALIAS.includes(n) ? `${n}_` : n}: ${args[i]}`).join(', ')}], { ${names.map((n, i) => `${n}: ${args[i]}`).join(', ')} }` + : `[${args.join(', ')}]` + }; + }) + .sort(compareName), + name: stringCamelCase(name) + }}) .sort(compareName); // filter out the unused lookup types from imports diff --git a/packages/typegen/src/generate/query.ts b/packages/typegen/src/generate/query.ts index d9128bbea18..3d6e39cfae2 100644 --- a/packages/typegen/src/generate/query.ts +++ b/packages/typegen/src/generate/query.ts @@ -20,14 +20,16 @@ import { ignoreUnusedLookups } from './lookup.js'; const generateForMetaTemplate = Handlebars.compile(readTemplate('query')); -function getDeprecationNotice(deprecationInfo: DeprecationStatusV16): string { +function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { let deprecationNotice = "@deprecated" - - if (deprecationInfo.isDeprecated) { - const { note, since } = deprecationInfo.asDeprecated; + + if (deprecationStatus.isDeprecated) { + const { note, since } = deprecationStatus.asDeprecated; const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; deprecationNotice += ` ${note}${sinceText}`; + }else { + deprecationNotice += ` Storage item ${name} has been deprecated` } return deprecationNotice @@ -107,15 +109,15 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr const items = storage.unwrap().items .map((storageEntry) => { - let {deprecationInfo, docs} = storageEntry; + let {deprecationInfo, docs, name} = storageEntry; const [isOptional, args, params, _returnType] = entrySignature(lookup, allDefs, registry, name.toString(), storageEntry, imports); if (!deprecationInfo.isNotDeprecated){ - const deprecationNotice = getDeprecationNotice(deprecationInfo); + const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name)); const items = docs.length ? ["", deprecationNotice] : [deprecationNotice]; - + docs.push(...items.map(text => registry.createType('Text', text))); } diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index 1104d9697e9..a781f7771d2 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@polkadot/types/interfaces'; +import type { DeprecationStatusV16, RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { DefinitionCall, DefinitionCallNamed, Definitions, DefinitionsCall, Registry } from '@polkadot/types/types'; import type { Vec } from '@polkadot/types-codec'; @@ -51,15 +51,37 @@ const getTypesViaAlias = (registry: Registry, id: SiLookupTypeId) => { return typeName; }; +function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = "@deprecated" + + if (deprecationStatus.isDeprecated) { + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + + deprecationNotice += ` ${note}${sinceText}`; + }else { + deprecationNotice += ` ${name} has been deprecated` + } + + return deprecationNotice +} + /** @internal */ function getMethods (registry: Registry, methods: Vec) { const result: Record = {}; methods.forEach((m) => { - const { docs, inputs, name, output } = m; + const { deprecationInfo, docs, inputs, name, output } = m; + let description = docs.map((d) => d.toString()).join(); + + if (!deprecationInfo.isNotDeprecated) { + const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name)); + const notice = description.length ? `\n * ${deprecationNotice}` : ` * ${deprecationNotice}`; + description += notice; + } result[name.toString()] = { - description: docs.map((d) => d.toString()).join(), + description, params: inputs.map(({ name, type }) => { return { name: name.toString(), type: getTypesViaAlias(registry, type) }; }), @@ -76,7 +98,7 @@ function getRuntimeDefViaMetadata (registry: Registry) { const { apis } = registry.metadata; for (let i = 0, count = apis.length; i < count; i++) { - const { methods, name } = apis[i]; + const { methods, name, deprecationInfo } = apis[i]; result[name.toString()] = [{ methods: getMethods(registry, methods), @@ -215,6 +237,7 @@ export function generateCallTypes (registry: Registry, meta: Metadata, dest: str return `${param.name}: ${similarTypes.join(' | ')}`; }); + console.log(def.description) return { args: args.join(', '), docs: [def.description], diff --git a/packages/typegen/src/generate/tx.ts b/packages/typegen/src/generate/tx.ts index 00a123c1412..6edbffe6a1b 100644 --- a/packages/typegen/src/generate/tx.ts +++ b/packages/typegen/src/generate/tx.ts @@ -15,6 +15,7 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, getSimilarTypes, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; +import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; const MAPPED_NAMES: Record = { class: 'clazz', @@ -29,6 +30,21 @@ function mapName (_name: Text): string { return MAPPED_NAMES[name] || name; } +function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = "@deprecated" + + if (deprecationStatus.isDeprecated) { + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + + deprecationNotice += ` ${note}${sinceText}`; + }else { + deprecationNotice += ` Call ${name}() has been deprecated` + } + + return deprecationNotice +} + /** @internal */ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void { writeFile(dest, (): string => { @@ -51,12 +67,27 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr const modules = pallets .sort(compareName) .filter(({ calls }) => calls.isSome) - .map(({ calls, name }) => { + .map((data) => { + let name = data.name; + let calls = data.calls.unwrap() + setImports(allDefs, imports, ['SubmittableExtrinsic']); const sectionName = stringCamelCase(name); - const items = lookup.getSiType(calls.unwrap().type).def.asVariant.variants - .map(({ docs, fields, name }) => { + const items = lookup.getSiType(calls.type).def.asVariant.variants + .map(({ docs, fields, name, index }) => { + if (calls.deprecationInfo.isVariantsDeprecated) { + const rawStatus = calls.deprecationInfo.asVariantsDeprecated.toJSON()?.[index.toNumber()]; + if (rawStatus) { + const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe("DeprecationStatusV16", [rawStatus]); + if (!deprecationStatus.isNotDeprecated) { + const deprecationNotice = getDeprecationNotice(deprecationStatus, stringCamelCase(name)); + const notice = docs.length ? ["", deprecationNotice] : [deprecationNotice]; + docs.push(...notice.map(text => meta.registry.createType('Text', text))); + } + } + } + const typesInfo = fields.map(({ name, type, typeName }, index): [string, string, string] => { const typeDef = registry.lookup.getTypeDef(type); @@ -72,6 +103,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr : typeDef.lookupName || typeDef.type ]; }); + const params = typesInfo .map(([name,, typeStr]) => { const similarTypes = getSimilarTypes(registry, allDefs, typeStr, imports); diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index ceb9e1118d6..cc283ecc9bd 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { type Vec } from '@polkadot/types-codec'; +import { BTreeMap, type Vec } from '@polkadot/types-codec'; import type { DeprecationInfoV16, DeprecationStatusV16, ExtrinsicMetadataV15, ExtrinsicMetadataV16, MetadataV15, MetadataV16, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataV14, PalletStorageMetadataV16, RuntimeApiMetadataV15, RuntimeApiMetadataV16, StorageEntryMetadataV16, TransactionExtensionMetadataV16 } from '../../interfaces/metadata/index.js'; import type { Registry } from '../../types/index.js'; @@ -20,11 +20,11 @@ function palletsFromV15(registry: Registry, palletV15: PalletMetadataV15): Palle } function convertStorage(registry: Registry, storage: PalletStorageMetadataV14): PalletStorageMetadataV16 { - const deprecationInfo: DeprecationStatusV16 = registry.createTypeUnsafe('DeprecationStatusV16', ['NotDeprecated']); + const deprecationInfo = registry.createTypeUnsafe('DeprecationStatusV16', ["NotDeprecated"]); const items: StorageEntryMetadataV16[] = storage.items.map((item) => registry.createTypeUnsafe('StorageEntryMetadataV16', [ - objectSpread({}, item, deprecationInfo) + objectSpread({}, item, {deprecationInfo}) ]) ); @@ -85,7 +85,7 @@ function extrinsicFromV15(registry: Registry, extrinsicV15: ExtrinsicMetadataV15 registry.createTypeUnsafe('Compact', [i]) ); - //TODO: Metadata: Revise Version, should it match extrinsicV15.version? + //FIXME: Metadata: Revise Version, should it match extrinsicV15 latest version? const transactionExtensionsByVersion = registry.createTypeUnsafe( 'BTreeMap>>', [new Map([[registry.createTypeUnsafe('u8', [0]), registry.createTypeUnsafe('Vec>', [indexes])]])] @@ -107,7 +107,7 @@ function apisFromV15(registry: Registry, runtimeApiV15: RuntimeApiMetadataV15): let methods = runtimeApiV15.methods.map((method) => - registry.createTypeUnsafe('RuntimeApiMethodMetadataV16', + registry.createTypeUnsafe('RuntimeApiMethodMetadataV16', [objectSpread({}, method, {deprecationInfo})] ) ); From e26a10e3e21380f70363a66cd6f5bc5e895f8d7b Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 21 Apr 2025 16:35:44 -0300 Subject: [PATCH 09/18] Fix compilation issues --- packages/api/src/base/Init.ts | 3 ++- packages/typegen/src/generate/consts.ts | 2 +- packages/typegen/src/generate/runtime.ts | 2 +- packages/types/src/metadata/v15/toV16.ts | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/api/src/base/Init.ts b/packages/api/src/base/Init.ts index 1da7ba86447..82fd4911779 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -19,6 +19,7 @@ import { assertReturn, BN_ZERO, isUndefined, logger, noop, objectSpread, u8aEq, import { blake2AsHex, cryptoWaitReady } from '@polkadot/util-crypto'; import { Decorate } from './Decorate.js'; +import { LATEST_EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/constants'; const KEEPALIVE_INTERVAL = 10000; const WITH_VERSION_SHORTCUT = false; @@ -373,7 +374,7 @@ export abstract class Init extends Decorate { throw new Error('Invalid initializion order, runtimeVersion is not available'); } - this._extrinsicType = metadata.asLatest.extrinsic.version.toNumber(); + this._extrinsicType = metadata.asLatest.extrinsic.versions.at(-1) || LATEST_EXTRINSIC_VERSION; this._rx.extrinsicType = this._extrinsicType; this._rx.genesisHash = this._genesisHash; this._rx.runtimeVersion = runtimeVersion; diff --git a/packages/typegen/src/generate/consts.ts b/packages/typegen/src/generate/consts.ts index f7c301a7071..9c2191ec5a6 100644 --- a/packages/typegen/src/generate/consts.ts +++ b/packages/typegen/src/generate/consts.ts @@ -14,7 +14,7 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; -import type { DeprecationInfoV16, DeprecationStatusV16 } from '@polkadot/types/interfaces'; +import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; const generateForMetaTemplate = Handlebars.compile(readTemplate('consts')); diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index a781f7771d2..004c3470be7 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -98,7 +98,7 @@ function getRuntimeDefViaMetadata (registry: Registry) { const { apis } = registry.metadata; for (let i = 0, count = apis.length; i < count; i++) { - const { methods, name, deprecationInfo } = apis[i]; + const { methods, name } = apis[i]; result[name.toString()] = [{ methods: getMethods(registry, methods), diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index cc283ecc9bd..7a429b3d5db 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { BTreeMap, type Vec } from '@polkadot/types-codec'; +import { type Vec } from '@polkadot/types-codec'; import type { DeprecationInfoV16, DeprecationStatusV16, ExtrinsicMetadataV15, ExtrinsicMetadataV16, MetadataV15, MetadataV16, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataV14, PalletStorageMetadataV16, RuntimeApiMetadataV15, RuntimeApiMetadataV16, StorageEntryMetadataV16, TransactionExtensionMetadataV16 } from '../../interfaces/metadata/index.js'; import type { Registry } from '../../types/index.js'; @@ -88,7 +88,7 @@ function extrinsicFromV15(registry: Registry, extrinsicV15: ExtrinsicMetadataV15 //FIXME: Metadata: Revise Version, should it match extrinsicV15 latest version? const transactionExtensionsByVersion = registry.createTypeUnsafe( 'BTreeMap>>', - [new Map([[registry.createTypeUnsafe('u8', [0]), registry.createTypeUnsafe('Vec>', [indexes])]])] + [new Map([[registry.createTypeUnsafe('u8', [extrinsicV15.version]), registry.createTypeUnsafe('Vec>', [indexes])]])] ); return registry.createTypeUnsafe('ExtrinsicMetadataV16', [ From 0b458455a002ce0cd6ba867f2ca95bae26122683 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 21 Apr 2025 16:46:08 -0300 Subject: [PATCH 10/18] lint --- packages/api/src/base/Init.ts | 6 +- packages/typegen/src/generate/consts.ts | 24 ++--- packages/typegen/src/generate/errors.ts | 42 +++++---- packages/typegen/src/generate/events.ts | 33 +++---- packages/typegen/src/generate/query.ts | 27 +++--- packages/typegen/src/generate/runtime.ts | 20 +++-- packages/typegen/src/generate/tx.ts | 33 +++---- packages/typegen/src/interfacesTs.ts | 2 +- packages/typegen/src/metadataMd.ts | 2 +- packages/types/src/create/registry.ts | 2 +- packages/types/src/extrinsic/Extrinsic.ts | 6 +- packages/types/src/interfaces/metadata/v16.ts | 84 ++++++++--------- .../types/src/metadata/MetadataVersioned.ts | 4 +- packages/types/src/metadata/v15/toV16.ts | 89 +++++++++---------- 14 files changed, 191 insertions(+), 183 deletions(-) diff --git a/packages/api/src/base/Init.ts b/packages/api/src/base/Init.ts index 82fd4911779..689cd168664 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -14,18 +14,18 @@ import type { VersionedRegistry } from './types.js'; import { firstValueFrom, map, of, switchMap } from 'rxjs'; import { Metadata, TypeRegistry } from '@polkadot/types'; +import { LATEST_EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/constants'; import { getSpecAlias, getSpecExtensions, getSpecHasher, getSpecRpc, getSpecTypes, getUpgradeVersion } from '@polkadot/types-known'; import { assertReturn, BN_ZERO, isUndefined, logger, noop, objectSpread, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util'; import { blake2AsHex, cryptoWaitReady } from '@polkadot/util-crypto'; import { Decorate } from './Decorate.js'; -import { LATEST_EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/constants'; const KEEPALIVE_INTERVAL = 10000; const WITH_VERSION_SHORTCUT = false; -//TODO: Remove U32::MAX when metadata 16 is stabilized. -const SUPPORTED_METADATA_VERSIONS = [4294967295, 16 ,15, 14]; +// TODO: Remove U32::MAX when metadata 16 is stabilized. +const SUPPORTED_METADATA_VERSIONS = [4294967295, 16, 15, 14]; const l = logger('api/init'); diff --git a/packages/typegen/src/generate/consts.ts b/packages/typegen/src/generate/consts.ts index 9c2191ec5a6..92a78f7d991 100644 --- a/packages/typegen/src/generate/consts.ts +++ b/packages/typegen/src/generate/consts.ts @@ -1,6 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { Definitions } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; @@ -14,23 +15,22 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; -import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; const generateForMetaTemplate = Handlebars.compile(readTemplate('consts')); -function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { - let deprecationNotice = "@deprecated" +function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = '@deprecated'; if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - deprecationNotice += ` ${note}${sinceText}`; - }else { - deprecationNotice += ` Const ${name} has been deprecated` + deprecationNotice += ` ${note.toString()}${sinceText}`; + } else { + deprecationNotice += ` Const ${name} has been deprecated`; } - return deprecationNotice + return deprecationNotice; } /** @internal */ @@ -65,14 +65,14 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, const typeDef = lookup.getTypeDef(type); const returnType = typeDef.lookupName || formatType(registry, allDefs, typeDef, imports); - if (!deprecationInfo.isNotDeprecated){ + if (!deprecationInfo.isNotDeprecated) { const deprecationNotice = getDeprecationNotice(deprecationInfo.asItemDeprecated, stringCamelCase(name)); const items = docs.length - ? ["", deprecationNotice] + ? ['', deprecationNotice] : [deprecationNotice]; - docs.push(...items.map(text => registry.createType('Text', text))); + docs.push(...items.map((text) => registry.createType('Text', text))); } // Add the type to the list of used types diff --git a/packages/typegen/src/generate/errors.ts b/packages/typegen/src/generate/errors.ts index 57f712f89a1..3cde18c66d5 100644 --- a/packages/typegen/src/generate/errors.ts +++ b/packages/typegen/src/generate/errors.ts @@ -1,6 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { HexString } from '@polkadot/util/types'; import type { ExtraTypes } from './types.js'; @@ -10,23 +11,22 @@ import Handlebars from 'handlebars'; import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, initMeta, readTemplate, writeFile } from '../util/index.js'; -import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; const generateForMetaTemplate = Handlebars.compile(readTemplate('errors')); -function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { - let deprecationNotice = "@deprecated" +function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = '@deprecated'; if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - deprecationNotice += ` ${note}${sinceText}`; - }else { - deprecationNotice += ` ${name} has been deprecated` + deprecationNotice += ` ${note.toString()}${sinceText}`; + } else { + deprecationNotice += ` ${name} has been deprecated`; } - return deprecationNotice + return deprecationNotice; } /** @internal */ @@ -37,30 +37,36 @@ function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void const modules = pallets .filter(({ errors }) => errors.isSome) .map((data) => { - let name = data.name; - let errors = data.errors.unwrap() + const name = data.name; + const errors = data.errors.unwrap(); + return { items: lookup.getSiType(errors.type).def.asVariant.variants - .map(({ docs, name, index }) => { + .map(({ docs, index, name }) => { if (errors.deprecationInfo.isVariantsDeprecated) { const rawStatus = errors.deprecationInfo.asVariantsDeprecated.toJSON()?.[index.toNumber()]; if (rawStatus) { - const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe("DeprecationStatusV16", [rawStatus]); - if (!deprecationStatus.isNotDeprecated){ + const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe('DeprecationStatusV16', [rawStatus]); + + if (!deprecationStatus.isNotDeprecated) { const deprecationNotice = getDeprecationNotice(deprecationStatus, name.toString()); - const notices = docs.length ? ["", deprecationNotice] : [deprecationNotice]; - docs.push(...notices.map(text => meta.registry.createType('Text', text))); + const notices = docs.length ? ['', deprecationNotice] : [deprecationNotice]; + + docs.push(...notices.map((text) => meta.registry.createType('Text', text))); } } } + return { docs, name: name.toString() - }}) + }; + }) .sort(compareName), name: stringCamelCase(name) - }}) + }; + }) .sort(compareName); return generateForMetaTemplate({ diff --git a/packages/typegen/src/generate/events.ts b/packages/typegen/src/generate/events.ts index 65b829bc6e8..3479b66e573 100644 --- a/packages/typegen/src/generate/events.ts +++ b/packages/typegen/src/generate/events.ts @@ -1,6 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { Definitions } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; @@ -14,7 +15,6 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; -import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; const generateForMetaTemplate = Handlebars.compile(readTemplate('events')); @@ -62,19 +62,19 @@ const ALIAS = [ 'yield' ]; -function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { - let deprecationNotice = "@deprecated" +function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = '@deprecated'; if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - deprecationNotice += ` ${note}${sinceText}`; - }else { - deprecationNotice += ` Event ${name} has been deprecated` + deprecationNotice += ` ${note.toString()}${sinceText}`; + } else { + deprecationNotice += ` Event ${name} has been deprecated`; } - return deprecationNotice + return deprecationNotice; } /** @internal */ @@ -99,23 +99,23 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, const modules = pallets .filter(({ events }) => events.isSome) .map((data) => { - let name = data.name; - let events = data.events.unwrap(); + const name = data.name; + const events = data.events.unwrap(); return { items: lookup.getSiType(events.type).def.asVariant.variants - .map(({ docs, fields, name, index }) => { + .map(({ docs, fields, index, name }) => { if (events.deprecationInfo.isVariantsDeprecated) { const rawStatus = events.deprecationInfo.asVariantsDeprecated.toJSON()?.[index.toNumber()]; if (rawStatus) { - const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe("DeprecationStatusV16", [rawStatus]); + const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe('DeprecationStatusV16', [rawStatus]); if (!deprecationStatus.isNotDeprecated) { const deprecationNotice = getDeprecationNotice(deprecationStatus, name.toString()); - const notice = docs.length ? ["", deprecationNotice] : [deprecationNotice]; - docs.push(...notice.map(text => meta.registry.createType('Text', text))); + const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice]; + docs.push(...notice.map((text) => meta.registry.createType('Text', text))); } } } @@ -149,7 +149,8 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, }) .sort(compareName), name: stringCamelCase(name) - }}) + }; + }) .sort(compareName); // filter out the unused lookup types from imports diff --git a/packages/typegen/src/generate/query.ts b/packages/typegen/src/generate/query.ts index 3d6e39cfae2..7f2e860215f 100644 --- a/packages/typegen/src/generate/query.ts +++ b/packages/typegen/src/generate/query.ts @@ -20,19 +20,19 @@ import { ignoreUnusedLookups } from './lookup.js'; const generateForMetaTemplate = Handlebars.compile(readTemplate('query')); -function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { - let deprecationNotice = "@deprecated" +function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = '@deprecated'; if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - deprecationNotice += ` ${note}${sinceText}`; - }else { - deprecationNotice += ` Storage item ${name} has been deprecated` + deprecationNotice += ` ${note.toString()}${sinceText}`; + } else { + deprecationNotice += ` Storage item ${name} has been deprecated`; } - return deprecationNotice + return deprecationNotice; } // From a storage entry metadata, we return [args, returnType] @@ -108,17 +108,16 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr .map(({ name, storage }) => { const items = storage.unwrap().items .map((storageEntry) => { - - let {deprecationInfo, docs, name} = storageEntry; + const { deprecationInfo, docs, name } = storageEntry; const [isOptional, args, params, _returnType] = entrySignature(lookup, allDefs, registry, name.toString(), storageEntry, imports); - if (!deprecationInfo.isNotDeprecated){ + if (!deprecationInfo.isNotDeprecated) { const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name)); const items = docs.length - ? ["", deprecationNotice] + ? ['', deprecationNotice] : [deprecationNotice]; - docs.push(...items.map(text => registry.createType('Text', text))); + docs.push(...items.map((text) => registry.createType('Text', text))); } // Add the type and args to the list of used types @@ -136,7 +135,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr return { args, - docs: docs, + docs, entryType: 'AugmentedQuery', name: stringCamelCase(storageEntry.name), params, diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index 004c3470be7..dc7e78b1f5b 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -51,19 +51,19 @@ const getTypesViaAlias = (registry: Registry, id: SiLookupTypeId) => { return typeName; }; -function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { - let deprecationNotice = "@deprecated" +function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = '@deprecated'; if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - deprecationNotice += ` ${note}${sinceText}`; - }else { - deprecationNotice += ` ${name} has been deprecated` + deprecationNotice += ` ${note.toString()}${sinceText}`; + } else { + deprecationNotice += ` ${name} has been deprecated`; } - return deprecationNotice + return deprecationNotice; } /** @internal */ @@ -77,6 +77,7 @@ function getMethods (registry: Registry, methods: Vec = { class: 'clazz', @@ -30,19 +30,19 @@ function mapName (_name: Text): string { return MAPPED_NAMES[name] || name; } -function getDeprecationNotice(deprecationStatus: DeprecationStatusV16, name: string): string { - let deprecationNotice = "@deprecated" +function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { + let deprecationNotice = '@deprecated'; if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap()}.` : ""; + const { note, since } = deprecationStatus.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - deprecationNotice += ` ${note}${sinceText}`; - }else { - deprecationNotice += ` Call ${name}() has been deprecated` + deprecationNotice += ` ${note.toString()}${sinceText}`; + } else { + deprecationNotice += ` Call ${name}() has been deprecated`; } - return deprecationNotice + return deprecationNotice; } /** @internal */ @@ -68,22 +68,25 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr .sort(compareName) .filter(({ calls }) => calls.isSome) .map((data) => { - let name = data.name; - let calls = data.calls.unwrap() + const name = data.name; + const calls = data.calls.unwrap(); setImports(allDefs, imports, ['SubmittableExtrinsic']); const sectionName = stringCamelCase(name); const items = lookup.getSiType(calls.type).def.asVariant.variants - .map(({ docs, fields, name, index }) => { + .map(({ docs, fields, index, name }) => { if (calls.deprecationInfo.isVariantsDeprecated) { const rawStatus = calls.deprecationInfo.asVariantsDeprecated.toJSON()?.[index.toNumber()]; + if (rawStatus) { - const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe("DeprecationStatusV16", [rawStatus]); + const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe('DeprecationStatusV16', [rawStatus]); + if (!deprecationStatus.isNotDeprecated) { const deprecationNotice = getDeprecationNotice(deprecationStatus, stringCamelCase(name)); - const notice = docs.length ? ["", deprecationNotice] : [deprecationNotice]; - docs.push(...notice.map(text => meta.registry.createType('Text', text))); + const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice]; + + docs.push(...notice.map((text) => meta.registry.createType('Text', text))); } } } diff --git a/packages/typegen/src/interfacesTs.ts b/packages/typegen/src/interfacesTs.ts index d5813bb9306..242a1cd55a5 100644 --- a/packages/typegen/src/interfacesTs.ts +++ b/packages/typegen/src/interfacesTs.ts @@ -3,7 +3,7 @@ import type { HexString } from '@polkadot/util/types'; -//TODO: replace v15 to v16 once metadata is updated +// TODO: replace v15 to v16 once metadata is updated import kusama from '@polkadot/types-support/metadata/v15/kusama-hex'; import polkadot from '@polkadot/types-support/metadata/v15/polkadot-hex'; import substrate from '@polkadot/types-support/metadata/v15/substrate-hex'; diff --git a/packages/typegen/src/metadataMd.ts b/packages/typegen/src/metadataMd.ts index d5775dcdecb..2fdccd247a8 100644 --- a/packages/typegen/src/metadataMd.ts +++ b/packages/typegen/src/metadataMd.ts @@ -614,7 +614,7 @@ function extractDeriveExample (tags: Spec[]) { let example = ''; const inCodeBlock = { done: false, found: false }; - // / Obtain code block from example tag. + // Obtain code block from example tag. exampleTag.source.forEach((line) => { if (inCodeBlock.done) { return; diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index 193e5588d44..f2d99a98c33 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -608,7 +608,7 @@ export class TypeRegistry implements Registry { // setup the available extensions this.setSignedExtensions( signedExtensions || ( - this.#metadata.extrinsic.versions.length > 0 && this.#metadata.extrinsic.versions.every(value => value > 0) + this.#metadata.extrinsic.versions.length > 0 && this.#metadata.extrinsic.versions.every((value) => value > 0) // FIXME Use the extension and their injected types ? this.#metadata.extrinsic.transactionExtensions.map(({ identifier }) => identifier.toString()) : fallbackExtensions diff --git a/packages/types/src/extrinsic/Extrinsic.ts b/packages/types/src/extrinsic/Extrinsic.ts index 58ee3552b4d..777ee0f5995 100644 --- a/packages/types/src/extrinsic/Extrinsic.ts +++ b/packages/types/src/extrinsic/Extrinsic.ts @@ -330,9 +330,9 @@ export class GenericExtrinsic extends ExtrinsicBa constructor (registry: Registry, value?: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call, { preamble, version }: CreateOptions = {}) { const versionsLength = registry.metadata.extrinsic.versions.length; - const highestSupportedVersion = versionsLength ? registry.metadata.extrinsic.versions[versionsLength -1] : undefined; - - console.log(registry.metadata.extrinsic.versions) + const highestSupportedVersion = versionsLength ? registry.metadata.extrinsic.versions[versionsLength - 1] : undefined; + + console.log(registry.metadata.extrinsic.versions); super(registry, decodeExtrinsic(registry, value, version || highestSupportedVersion, preamble), undefined, preamble); } diff --git a/packages/types/src/interfaces/metadata/v16.ts b/packages/types/src/interfaces/metadata/v16.ts index 83c4b505b0b..4f1e38a9617 100644 --- a/packages/types/src/interfaces/metadata/v16.ts +++ b/packages/types/src/interfaces/metadata/v16.ts @@ -7,7 +7,7 @@ import type { DefinitionsTypes } from '../../types/index.js'; export const v16: DefinitionsTypes = { - // actual v16 definition +// actual v16 definition MetadataV16: { lookup: 'PortableRegistry', pallets: 'Vec', @@ -18,7 +18,7 @@ export const v16: DefinitionsTypes = { custom: 'CustomMetadata15' }, - //---- Pallet definitions ---- + // ---- Pallet definitions ---- PalletMetadataV16: { name: 'Text', storage: 'Option', @@ -39,90 +39,90 @@ export const v16: DefinitionsTypes = { type: 'StorageEntryTypeV14', fallback: 'Bytes', docs: 'Vec', - /// Deprecation info - deprecationInfo: 'DeprecationStatusV16', + // Deprecation info + deprecationInfo: 'DeprecationStatusV16' }, DeprecationStatusV16: { _enum: { - /// Entry is not deprecated + // Entry is not deprecated NotDeprecated: 'Null', - /// Deprecated without a note. + // Deprecated without a note. DeprecatedWithoutNote: 'Null', - /// Entry is deprecated with an note and an optional `since` field. + // Entry is deprecated with an note and an optional `since` field. Deprecated: { - /// Note explaining the deprecation + // Note explaining the deprecation note: 'Text', - /// Optional value for denoting version when the deprecation occurred. - since: 'Option', - }, + // Optional value for denoting version when the deprecation occurred. + since: 'Option' + } } }, PalletCallMetadataV16: { type: 'SiLookupTypeId', - /// Deprecation status of the pallet call + // Deprecation status of the pallet call deprecationInfo: 'DeprecationInfoV16' }, DeprecationInfoV16: { _enum: { - /// Type is not deprecated + // Type is not deprecated NotDeprecated: 'Null', - /// Entry is fully deprecated. - ItemDeprecated: 'DeprecationStatusV16', - /// Entry is partially deprecated. - VariantsDeprecated: 'BTreeMap', + // Entry is fully deprecated. + ItemDeprecated: 'DeprecationStatusV16', + // Entry is partially deprecated. + VariantsDeprecated: 'BTreeMap' } }, PalletEventMetadataV16: { type: 'SiLookupTypeId', - /// Deprecation info - deprecationInfo: 'DeprecationInfoV16', + // Deprecation info + deprecationInfo: 'DeprecationInfoV16' }, PalletConstantMetadataV16: { name: 'Text', type: 'SiLookupTypeId', value: 'Bytes', docs: 'Vec', - /// Deprecation info - deprecationInfo: 'DeprecationInfoV16', + // Deprecation info + deprecationInfo: 'DeprecationInfoV16' }, PalletErrorMetadataV16: { type: 'SiLookupTypeId', - /// Deprecation info - deprecationInfo: 'DeprecationInfoV16', + // Deprecation info + deprecationInfo: 'DeprecationInfoV16' }, - //---- Extrinsic definitions ---- + // ---- Extrinsic definitions ---- ExtrinsicMetadataV16: { - /// Extrinsic versions supported by the runtime. + // Extrinsic versions supported by the runtime. versions: 'Vec', - /// The type of the address that signs the extrinsic + // The type of the address that signs the extrinsic addressType: 'SiLookupTypeId', - /// The type of the extrinsic's signature. + // The type of the extrinsic's signature. signatureType: 'SiLookupTypeId', - /// A mapping of supported transaction extrinsic versions to their respective transaction extension indexes. - /// - /// For each supported version number, list the indexes, in order, of the extensions used. + // A mapping of supported transaction extrinsic versions to their respective transaction extension indexes. + // + // For each supported version number, list the indexes, in order, of the extensions used. transactionExtensionsByVersion: 'BTreeMap>>', - /// The transaction extensions in the order they appear in the extrinsic. + // The transaction extensions in the order they appear in the extrinsic. transactionExtensions: 'Vec' }, TransactionExtensionMetadataV16: { - /// The unique transaction extension identifier, which may be different from the type name. + // The unique transaction extension identifier, which may be different from the type name. identifier: 'Text', - /// The type of the transaction extension, with the data to be included in the extrinsic. + // The type of the transaction extension, with the data to be included in the extrinsic. type: 'SiLookupTypeId', - /// The type of the implicit data, with the data to be included in the signed payload. - implicit: 'SiLookupTypeId', + // The type of the implicit data, with the data to be included in the signed payload. + implicit: 'SiLookupTypeId' }, - //---- Runtime Api definitions ---- + // ---- Runtime Api definitions ---- RuntimeApiMetadataV16: { name: 'Text', methods: 'Vec', docs: 'Vec', - /// Deprecation info - deprecationInfo: 'DeprecationStatusV16', - /// Runtime API version. + // Deprecation info + deprecationInfo: 'DeprecationStatusV16', + // Runtime API version. version: 'Compact' }, RuntimeApiMethodMetadataV16: { @@ -130,7 +130,7 @@ export const v16: DefinitionsTypes = { inputs: 'Vec', output: 'SiLookupTypeId', docs: 'Vec', - /// Deprecation info - deprecationInfo: 'DeprecationStatusV16', - }, + // Deprecation info + deprecationInfo: 'DeprecationStatusV16' + } }; diff --git a/packages/types/src/metadata/MetadataVersioned.ts b/packages/types/src/metadata/MetadataVersioned.ts index dbf5a09d7e1..b3e36a4609f 100644 --- a/packages/types/src/metadata/MetadataVersioned.ts +++ b/packages/types/src/metadata/MetadataVersioned.ts @@ -17,9 +17,9 @@ import { toV13 } from './v12/toV13.js'; import { toV14 } from './v13/toV14.js'; import { toV15 } from './v14/toV15.js'; import { toV16 } from './v15/toV16.js'; +import { toLatest } from './v16/toLatest.js'; import { MagicNumber } from './MagicNumber.js'; import { LATEST_VERSION, TO_CALLS_VERSION } from './versions.js'; -import { toLatest } from './v16/toLatest.js'; type MetaMapped = MetadataAll[MetaVersionAsX]; type MetaVersions = Exclude | 'latest'; @@ -137,7 +137,7 @@ export class MetadataVersioned extends Struct { return this.#getVersion(15, toV15); } - /** + /** * @description Returns the wrapped values as a V16 object */ public get asV16 (): MetadataV16 { diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index 7a429b3d5db..194bfe4756a 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -1,83 +1,82 @@ // Copyright 2017-2025 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { type Vec } from '@polkadot/types-codec'; import type { DeprecationInfoV16, DeprecationStatusV16, ExtrinsicMetadataV15, ExtrinsicMetadataV16, MetadataV15, MetadataV16, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataV14, PalletStorageMetadataV16, RuntimeApiMetadataV15, RuntimeApiMetadataV16, StorageEntryMetadataV16, TransactionExtensionMetadataV16 } from '../../interfaces/metadata/index.js'; import type { Registry } from '../../types/index.js'; +import { type Vec } from '@polkadot/types-codec'; import { objectSpread } from '@polkadot/util'; -function palletsFromV15(registry: Registry, palletV15: PalletMetadataV15): PalletMetadataV16 { +function palletsFromV15 (registry: Registry, palletV15: PalletMetadataV15): PalletMetadataV16 { return registry.createTypeUnsafe('PalletMetadataV16', [ objectSpread({}, palletV15, { - storage: palletV15.storage.isSome? convertStorage(registry, palletV15.storage.unwrap()) : null, - calls: palletV15.calls.isSome? convertCalls(registry, palletV15.calls.unwrap()) : null, - events: palletV15.events.isSome? convertEvents(registry, palletV15.events.unwrap()) : null, + calls: palletV15.calls.isSome ? convertCalls(registry, palletV15.calls.unwrap()) : null, constants: convertConstants(registry, palletV15.constants), - errors: palletV15.errors.isSome? converErrors(registry, palletV15.errors.unwrap()) : null, + errors: palletV15.errors.isSome ? converErrors(registry, palletV15.errors.unwrap()) : null, + events: palletV15.events.isSome ? convertEvents(registry, palletV15.events.unwrap()) : null, + storage: palletV15.storage.isSome ? convertStorage(registry, palletV15.storage.unwrap()) : null }) - ]) + ]); } -function convertStorage(registry: Registry, storage: PalletStorageMetadataV14): PalletStorageMetadataV16 { - const deprecationInfo = registry.createTypeUnsafe('DeprecationStatusV16', ["NotDeprecated"]); +function convertStorage (registry: Registry, storage: PalletStorageMetadataV14): PalletStorageMetadataV16 { + const deprecationInfo = registry.createTypeUnsafe('DeprecationStatusV16', ['NotDeprecated']); const items: StorageEntryMetadataV16[] = storage.items.map((item) => registry.createTypeUnsafe('StorageEntryMetadataV16', [ - objectSpread({}, item, {deprecationInfo}) + objectSpread({}, item, { deprecationInfo }) ]) ); return registry.createTypeUnsafe('PalletStorageMetadataV16', [{ - prefix: storage.prefix, - items: registry.createTypeUnsafe('Vec', [items]) + items: registry.createTypeUnsafe('Vec', [items]), + prefix: storage.prefix }]); } -function convertCalls(registry: Registry, calls: PalletCallMetadataV14): PalletCallMetadataV16 { +function convertCalls (registry: Registry, calls: PalletCallMetadataV14): PalletCallMetadataV16 { const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); return registry.createTypeUnsafe('PalletCallMetadataV16', [{ - type: calls.type, - deprecationInfo + deprecationInfo, + type: calls.type }]); } -function convertEvents(registry: Registry, events: PalletEventMetadataV14): PalletEventMetadataV16 { +function convertEvents (registry: Registry, events: PalletEventMetadataV14): PalletEventMetadataV16 { const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); return registry.createTypeUnsafe('PalletEventMetadataV16', [{ - type: events.type, - deprecationInfo + deprecationInfo, + type: events.type }]); } -function convertConstants(registry: Registry, constants: Vec): Vec { +function convertConstants (registry: Registry, constants: Vec): Vec { const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); return registry.createTypeUnsafe('Vec', [ constants.map((constant) => registry.createTypeUnsafe('PalletConstantMetadataV16', [ - objectSpread({}, constant, {deprecationInfo}) + objectSpread({}, constant, { deprecationInfo }) ]))] - ) + ); } - -function converErrors(registry: Registry, errors: PalletErrorMetadataV14): PalletErrorMetadataV16 { +function converErrors (registry: Registry, errors: PalletErrorMetadataV14): PalletErrorMetadataV16 { const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); return registry.createTypeUnsafe('PalletErrorMetadataV16', [{ - type: errors.type, - deprecationInfo + deprecationInfo, + type: errors.type }]); } -function extrinsicFromV15(registry: Registry, extrinsicV15: ExtrinsicMetadataV15): ExtrinsicMetadataV16 { - const transactionExtensions: TransactionExtensionMetadataV16[] = extrinsicV15.signedExtensions.map(({identifier, type, additionalSigned}) => +function extrinsicFromV15 (registry: Registry, extrinsicV15: ExtrinsicMetadataV15): ExtrinsicMetadataV16 { + const transactionExtensions: TransactionExtensionMetadataV16[] = extrinsicV15.signedExtensions.map(({ additionalSigned, identifier, type }) => registry.createTypeUnsafe('TransactionExtensionMetadataV16', [{ identifier, - type, - implict: additionalSigned + implict: additionalSigned, + type }]) ); @@ -85,7 +84,7 @@ function extrinsicFromV15(registry: Registry, extrinsicV15: ExtrinsicMetadataV15 registry.createTypeUnsafe('Compact', [i]) ); - //FIXME: Metadata: Revise Version, should it match extrinsicV15 latest version? + // FIXME: Metadata: Revise Version, should it match extrinsicV15 latest version? const transactionExtensionsByVersion = registry.createTypeUnsafe( 'BTreeMap>>', [new Map([[registry.createTypeUnsafe('u8', [extrinsicV15.version]), registry.createTypeUnsafe('Vec>', [indexes])]])] @@ -93,32 +92,31 @@ function extrinsicFromV15(registry: Registry, extrinsicV15: ExtrinsicMetadataV15 return registry.createTypeUnsafe('ExtrinsicMetadataV16', [ { - versions: [extrinsicV15.version], addressType: extrinsicV15.addressType, signatureType: extrinsicV15.signatureType, - transactionExtensionsByVersion: transactionExtensionsByVersion, transactionExtensions, + transactionExtensionsByVersion, + versions: [extrinsicV15.version] } - ]) + ]); } -function apisFromV15(registry: Registry, runtimeApiV15: RuntimeApiMetadataV15): RuntimeApiMetadataV16 { +function apisFromV15 (registry: Registry, runtimeApiV15: RuntimeApiMetadataV15): RuntimeApiMetadataV16 { const deprecationInfo: DeprecationStatusV16 = registry.createTypeUnsafe('DeprecationStatusV16', ['NotDeprecated']); - - let methods = runtimeApiV15.methods.map((method) => + const methods = runtimeApiV15.methods.map((method) => registry.createTypeUnsafe('RuntimeApiMethodMetadataV16', - [objectSpread({}, method, {deprecationInfo})] + [objectSpread({}, method, { deprecationInfo })] ) ); return registry.createTypeUnsafe('RuntimeApiMetadataV16', [ objectSpread({}, runtimeApiV15, { - methods, deprecationInfo, - version: registry.createTypeUnsafe('Compact', [0]), + methods, + version: registry.createTypeUnsafe('Compact', [0]) }) - ]) + ]); } /** @@ -126,18 +124,17 @@ function apisFromV15(registry: Registry, runtimeApiV15: RuntimeApiMetadataV15): * @internal **/ export function toV16 (registry: Registry, v15: MetadataV15, _: number): MetadataV16 { - const pallets: PalletMetadataV16[] = v15.pallets.map((pallet) => { - return palletsFromV15(registry, pallet) + return palletsFromV15(registry, pallet); }); const extrinsic: ExtrinsicMetadataV16 = extrinsicFromV15(registry, v15.extrinsic); - const apis: RuntimeApiMetadataV16[] = v15.apis.map((runtimeApi) => apisFromV15(registry, runtimeApi)) ; + const apis: RuntimeApiMetadataV16[] = v15.apis.map((runtimeApi) => apisFromV15(registry, runtimeApi)); return registry.createTypeUnsafe('MetadataV16', [ - objectSpread({}, v15, { - pallets, + objectSpread({}, v15, { + apis, extrinsic, - apis + pallets }) ]); } From 0f6970616ba625ba4e86a516aeae7ddccb8e7990 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Mon, 21 Apr 2025 16:47:41 -0300 Subject: [PATCH 11/18] Remove console.log() --- packages/typegen/src/generate/runtime.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index dc7e78b1f5b..afd60e5b0d8 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -238,8 +238,6 @@ export function generateCallTypes (registry: Registry, meta: Metadata, dest: str return `${param.name}: ${similarTypes.join(' | ')}`; }); - console.log(def.description); - return { args: args.join(', '), docs: [def.description], From 09b1464f834f4b8b60b1bc4f9ffdfe1164a5d18c Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Wed, 23 Apr 2025 11:31:26 -0300 Subject: [PATCH 12/18] Update metadata DeprecationInfo --- packages/typegen/src/generate/consts.ts | 12 ++-- packages/typegen/src/generate/errors.ts | 25 ++++---- packages/typegen/src/generate/events.ts | 28 ++++----- packages/typegen/src/generate/query.ts | 10 +-- packages/typegen/src/generate/runtime.ts | 8 +-- packages/typegen/src/generate/tx.ts | 26 ++++---- .../types-augment/src/registry/interfaces.ts | 7 ++- .../types/src/interfaces/metadata/types.ts | 62 ++++++++++--------- packages/types/src/interfaces/metadata/v16.ts | 50 ++++++++------- packages/types/src/metadata/v15/toV16.ts | 18 +++--- 10 files changed, 126 insertions(+), 120 deletions(-) diff --git a/packages/typegen/src/generate/consts.ts b/packages/typegen/src/generate/consts.ts index 92a78f7d991..bf87f4da215 100644 --- a/packages/typegen/src/generate/consts.ts +++ b/packages/typegen/src/generate/consts.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; +import type { ItemDeprecationInfoV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { Definitions } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; @@ -18,16 +18,16 @@ import { ignoreUnusedLookups } from './lookup.js'; const generateForMetaTemplate = Handlebars.compile(readTemplate('consts')); -function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { +function getDeprecationNotice (deprecationInfo: ItemDeprecationInfoV16, name: string): string { let deprecationNotice = '@deprecated'; - if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; + if (deprecationInfo.isDeprecated) { + const { note, since } = deprecationInfo.asDeprecated; const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; deprecationNotice += ` ${note.toString()}${sinceText}`; } else { - deprecationNotice += ` Const ${name} has been deprecated`; + deprecationNotice += ` Constant ${name} has been deprecated`; } return deprecationNotice; @@ -66,7 +66,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, const returnType = typeDef.lookupName || formatType(registry, allDefs, typeDef, imports); if (!deprecationInfo.isNotDeprecated) { - const deprecationNotice = getDeprecationNotice(deprecationInfo.asItemDeprecated, stringCamelCase(name)); + const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name)); const items = docs.length ? ['', deprecationNotice] diff --git a/packages/typegen/src/generate/errors.ts b/packages/typegen/src/generate/errors.ts index 3cde18c66d5..15f4d4ea005 100644 --- a/packages/typegen/src/generate/errors.ts +++ b/packages/typegen/src/generate/errors.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; +import type { VariantDeprecationInfoV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { HexString } from '@polkadot/util/types'; import type { ExtraTypes } from './types.js'; @@ -14,11 +14,11 @@ import { compareName, createImports, initMeta, readTemplate, writeFile } from '. const generateForMetaTemplate = Handlebars.compile(readTemplate('errors')); -function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { +function getDeprecationNotice (deprecationInfo: VariantDeprecationInfoV16, name: string): string { let deprecationNotice = '@deprecated'; - if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; + if (deprecationInfo.isDeprecated) { + const { note, since } = deprecationInfo.asDeprecated; const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; deprecationNotice += ` ${note.toString()}${sinceText}`; @@ -39,23 +39,20 @@ function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void .map((data) => { const name = data.name; const errors = data.errors.unwrap(); + const deprecationInfo = errors.deprecationInfo[0].toJSON(); return { items: lookup.getSiType(errors.type).def.asVariant.variants .map(({ docs, index, name }) => { - if (errors.deprecationInfo.isVariantsDeprecated) { - const rawStatus = errors.deprecationInfo.asVariantsDeprecated.toJSON()?.[index.toNumber()]; + const rawStatus = deprecationInfo?.[index.toNumber()]; - if (rawStatus) { - const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe('DeprecationStatusV16', [rawStatus]); + if (rawStatus) { + const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]); - if (!deprecationStatus.isNotDeprecated) { - const deprecationNotice = getDeprecationNotice(deprecationStatus, name.toString()); - const notices = docs.length ? ['', deprecationNotice] : [deprecationNotice]; + const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString()); + const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice]; - docs.push(...notices.map((text) => meta.registry.createType('Text', text))); - } - } + docs.push(...notice.map((text) => meta.registry.createType('Text', text))); } return { diff --git a/packages/typegen/src/generate/events.ts b/packages/typegen/src/generate/events.ts index 3479b66e573..bad043c947e 100644 --- a/packages/typegen/src/generate/events.ts +++ b/packages/typegen/src/generate/events.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; +import type { VariantDeprecationInfoV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { Definitions } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; @@ -62,16 +62,16 @@ const ALIAS = [ 'yield' ]; -function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { +function getDeprecationNotice (deprecationInfo: VariantDeprecationInfoV16, name: string): string { let deprecationNotice = '@deprecated'; - if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; + if (deprecationInfo.isDeprecated) { + const { note, since } = deprecationInfo.asDeprecated; const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; deprecationNotice += ` ${note.toString()}${sinceText}`; } else { - deprecationNotice += ` Event ${name} has been deprecated`; + deprecationNotice += ` ${name} has been deprecated`; } return deprecationNotice; @@ -101,23 +101,19 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, .map((data) => { const name = data.name; const events = data.events.unwrap(); + const deprecationInfo = events.deprecationInfo[0].toJSON(); return { items: lookup.getSiType(events.type).def.asVariant.variants .map(({ docs, fields, index, name }) => { - if (events.deprecationInfo.isVariantsDeprecated) { - const rawStatus = events.deprecationInfo.asVariantsDeprecated.toJSON()?.[index.toNumber()]; + const rawStatus = deprecationInfo?.[index.toNumber()]; - if (rawStatus) { - const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe('DeprecationStatusV16', [rawStatus]); + if (rawStatus) { + const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]); + const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString()); + const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice]; - if (!deprecationStatus.isNotDeprecated) { - const deprecationNotice = getDeprecationNotice(deprecationStatus, name.toString()); - const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice]; - - docs.push(...notice.map((text) => meta.registry.createType('Text', text))); - } - } + docs.push(...notice.map((text) => meta.registry.createType('Text', text))); } const args = fields diff --git a/packages/typegen/src/generate/query.ts b/packages/typegen/src/generate/query.ts index 7f2e860215f..5901f515c02 100644 --- a/packages/typegen/src/generate/query.ts +++ b/packages/typegen/src/generate/query.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeprecationStatusV16, StorageEntryMetadataLatest } from '@polkadot/types/interfaces'; +import type { ItemDeprecationInfoV16, StorageEntryMetadataLatest } from '@polkadot/types/interfaces'; import type { Metadata, PortableRegistry } from '@polkadot/types/metadata'; import type { Definitions, Registry } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; @@ -20,16 +20,16 @@ import { ignoreUnusedLookups } from './lookup.js'; const generateForMetaTemplate = Handlebars.compile(readTemplate('query')); -function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { +function getDeprecationNotice (deprecationInfo: ItemDeprecationInfoV16, name: string): string { let deprecationNotice = '@deprecated'; - if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; + if (deprecationInfo.isDeprecated) { + const { note, since } = deprecationInfo.asDeprecated; const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; deprecationNotice += ` ${note.toString()}${sinceText}`; } else { - deprecationNotice += ` Storage item ${name} has been deprecated`; + deprecationNotice += ` ${name} has been deprecated`; } return deprecationNotice; diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index afd60e5b0d8..26c27df5a10 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeprecationStatusV16, RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@polkadot/types/interfaces'; +import type { ItemDeprecationInfoV16, RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { DefinitionCall, DefinitionCallNamed, Definitions, DefinitionsCall, Registry } from '@polkadot/types/types'; import type { Vec } from '@polkadot/types-codec'; @@ -51,11 +51,11 @@ const getTypesViaAlias = (registry: Registry, id: SiLookupTypeId) => { return typeName; }; -function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { +function getDeprecationNotice (deprecationInfo: ItemDeprecationInfoV16, name: string): string { let deprecationNotice = '@deprecated'; - if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; + if (deprecationInfo.isDeprecated) { + const { note, since } = deprecationInfo.asDeprecated; const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; deprecationNotice += ` ${note.toString()}${sinceText}`; diff --git a/packages/typegen/src/generate/tx.ts b/packages/typegen/src/generate/tx.ts index c54c5f9ca43..142800580df 100644 --- a/packages/typegen/src/generate/tx.ts +++ b/packages/typegen/src/generate/tx.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeprecationStatusV16 } from '@polkadot/types/interfaces'; +import type { VariantDeprecationInfoV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { Text } from '@polkadot/types/primitive'; import type { Definitions, Registry } from '@polkadot/types/types'; @@ -30,11 +30,11 @@ function mapName (_name: Text): string { return MAPPED_NAMES[name] || name; } -function getDeprecationNotice (deprecationStatus: DeprecationStatusV16, name: string): string { +function getDeprecationNotice (deprecationInfo: VariantDeprecationInfoV16, name: string): string { let deprecationNotice = '@deprecated'; - if (deprecationStatus.isDeprecated) { - const { note, since } = deprecationStatus.asDeprecated; + if (deprecationInfo.isDeprecated) { + const { note, since } = deprecationInfo.asDeprecated; const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; deprecationNotice += ` ${note.toString()}${sinceText}`; @@ -70,25 +70,21 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr .map((data) => { const name = data.name; const calls = data.calls.unwrap(); + const deprecationInfo = calls.deprecationInfo[0].toJSON(); setImports(allDefs, imports, ['SubmittableExtrinsic']); const sectionName = stringCamelCase(name); const items = lookup.getSiType(calls.type).def.asVariant.variants .map(({ docs, fields, index, name }) => { - if (calls.deprecationInfo.isVariantsDeprecated) { - const rawStatus = calls.deprecationInfo.asVariantsDeprecated.toJSON()?.[index.toNumber()]; + const rawStatus = deprecationInfo?.[index.toNumber()]; - if (rawStatus) { - const deprecationStatus: DeprecationStatusV16 = meta.registry.createTypeUnsafe('DeprecationStatusV16', [rawStatus]); + if (rawStatus) { + const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]); + const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString()); + const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice]; - if (!deprecationStatus.isNotDeprecated) { - const deprecationNotice = getDeprecationNotice(deprecationStatus, stringCamelCase(name)); - const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice]; - - docs.push(...notice.map((text) => meta.registry.createType('Text', text))); - } - } + docs.push(...notice.map((text) => meta.registry.createType('Text', text))); } const typesInfo = fields.map(({ name, type, typeName }, index): [string, string, string] => { diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index d62b3c0fe3b..303fd03abb5 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -44,7 +44,7 @@ import type { AuthorityIndex, AuthorityList, AuthoritySet, AuthoritySetChange, A import type { IdentityFields, IdentityInfo, IdentityInfoAdditional, IdentityInfoTo198, IdentityJudgement, RegistrarIndex, RegistrarInfo, Registration, RegistrationJudgement, RegistrationTo198 } from '@polkadot/types/interfaces/identity'; import type { AuthIndex, AuthoritySignature, Heartbeat, HeartbeatTo244, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline'; import type { CallIndex, LotteryConfig } from '@polkadot/types/interfaces/lottery'; -import type { CustomMetadata15, CustomValueMetadata15, DeprecationInfoV16, DeprecationStatusV16, ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, ExtrinsicMetadataV15, ExtrinsicMetadataV16, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV15, MetadataV16, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, OpaqueMetadata, OuterEnums15, PalletCallMetadataLatest, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataLatest, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataLatest, PalletMetadataV14, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataLatest, PalletStorageMetadataV14, PalletStorageMetadataV16, PortableType, PortableTypeV14, RuntimeApiMetadataLatest, RuntimeApiMetadataV15, RuntimeApiMetadataV16, RuntimeApiMethodMetadataV15, RuntimeApiMethodMetadataV16, RuntimeApiMethodParamMetadataV15, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV16, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9, TransactionExtensionMetadataLatest, TransactionExtensionMetadataV16 } from '@polkadot/types/interfaces/metadata'; +import type { CustomMetadata15, CustomValueMetadata15, EnumDeprecationInfoV16, ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, ExtrinsicMetadataV15, ExtrinsicMetadataV16, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, ItemDeprecationInfoV16, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV15, MetadataV16, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, OpaqueMetadata, OuterEnums15, PalletCallMetadataLatest, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataLatest, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataLatest, PalletMetadataV14, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataLatest, PalletStorageMetadataV14, PalletStorageMetadataV16, PortableType, PortableTypeV14, RuntimeApiMetadataLatest, RuntimeApiMetadataV15, RuntimeApiMetadataV16, RuntimeApiMethodMetadataV15, RuntimeApiMethodMetadataV16, RuntimeApiMethodParamMetadataV15, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV16, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9, TransactionExtensionMetadataLatest, TransactionExtensionMetadataV16, VariantDeprecationInfoV16 } from '@polkadot/types/interfaces/metadata'; import type { Mixnode, MixnodesErr, SessionPhase, SessionStatus } from '@polkadot/types/interfaces/mixnet'; import type { MmrBatchProof, MmrEncodableOpaqueLeaf, MmrError, MmrHash, MmrLeafBatchProof, MmrLeafIndex, MmrLeafProof, MmrNodeIndex, MmrProof } from '@polkadot/types/interfaces/mmr'; import type { NftCollectionId, NftItemId } from '@polkadot/types/interfaces/nfts'; @@ -362,8 +362,6 @@ declare module '@polkadot/types/types/registry' { DeliveredMessages: DeliveredMessages; DepositBalance: DepositBalance; DepositBalanceOf: DepositBalanceOf; - DeprecationInfoV16: DeprecationInfoV16; - DeprecationStatusV16: DeprecationStatusV16; DestroyWitness: DestroyWitness; Digest: Digest; DigestItem: DigestItem; @@ -410,6 +408,7 @@ declare module '@polkadot/types/types/registry' { ElectionStatus: ElectionStatus; EncodedFinalityProofs: EncodedFinalityProofs; EncodedJustification: EncodedJustification; + EnumDeprecationInfoV16: EnumDeprecationInfoV16; Epoch: Epoch; EpochAuthorship: EpochAuthorship; Era: Era; @@ -650,6 +649,7 @@ declare module '@polkadot/types/types/registry' { InvalidTransaction: InvalidTransaction; isize: isize; ISize: ISize; + ItemDeprecationInfoV16: ItemDeprecationInfoV16; Json: Json; Junction: Junction; Junctions: Junctions; @@ -1257,6 +1257,7 @@ declare module '@polkadot/types/types/registry' { ValidDisputeStatementKind: ValidDisputeStatementKind; ValidityAttestation: ValidityAttestation; ValidTransaction: ValidTransaction; + VariantDeprecationInfoV16: VariantDeprecationInfoV16; VecInboundHrmpMessage: VecInboundHrmpMessage; VersionedMultiAsset: VersionedMultiAsset; VersionedMultiAssets: VersionedMultiAssets; diff --git a/packages/types/src/interfaces/metadata/types.ts b/packages/types/src/interfaces/metadata/types.ts index 9fb784324e6..e2bc40d32cf 100644 --- a/packages/types/src/interfaces/metadata/types.ts +++ b/packages/types/src/interfaces/metadata/types.ts @@ -3,6 +3,7 @@ import type { PortableRegistry } from '@polkadot/types'; import type { BTreeMap, Bytes, Compact, Enum, Option, Struct, Text, Type, Vec, WrapperOpaque, bool, u32, u8 } from '@polkadot/types-codec'; +import type { ITuple } from '@polkadot/types-codec/types'; import type { Si1Field, Si1LookupTypeId, Si1Type, SiLookupTypeId } from '@polkadot/types/interfaces/scaleInfo'; /** @name CustomMetadata15 */ @@ -16,27 +17,8 @@ export interface CustomValueMetadata15 extends Struct { readonly value: Bytes; } -/** @name DeprecationInfoV16 */ -export interface DeprecationInfoV16 extends Enum { - readonly isNotDeprecated: boolean; - readonly isItemDeprecated: boolean; - readonly asItemDeprecated: DeprecationStatusV16; - readonly isVariantsDeprecated: boolean; - readonly asVariantsDeprecated: BTreeMap; - readonly type: 'NotDeprecated' | 'ItemDeprecated' | 'VariantsDeprecated'; -} - -/** @name DeprecationStatusV16 */ -export interface DeprecationStatusV16 extends Enum { - readonly isNotDeprecated: boolean; - readonly isDeprecatedWithoutNote: boolean; - readonly isDeprecated: boolean; - readonly asDeprecated: { - readonly note: Text; - readonly since: Option; - } & Struct; - readonly type: 'NotDeprecated' | 'DeprecatedWithoutNote' | 'Deprecated'; -} +/** @name EnumDeprecationInfoV16 */ +export interface EnumDeprecationInfoV16 extends ITuple<[BTreeMap]> {} /** @name ErrorMetadataLatest */ export interface ErrorMetadataLatest extends ErrorMetadataV14 {} @@ -199,6 +181,18 @@ export interface FunctionMetadataV9 extends Struct { readonly docs: Vec; } +/** @name ItemDeprecationInfoV16 */ +export interface ItemDeprecationInfoV16 extends Enum { + readonly isNotDeprecated: boolean; + readonly isDeprecatedWithoutNote: boolean; + readonly isDeprecated: boolean; + readonly asDeprecated: { + readonly note: Text; + readonly since: Option; + } & Struct; + readonly type: 'NotDeprecated' | 'DeprecatedWithoutNote' | 'Deprecated'; +} + /** @name MetadataAll */ export interface MetadataAll extends Enum { readonly isV9: boolean; @@ -374,7 +368,7 @@ export interface PalletCallMetadataV14 extends Struct { /** @name PalletCallMetadataV16 */ export interface PalletCallMetadataV16 extends Struct { readonly type: SiLookupTypeId; - readonly deprecationInfo: DeprecationInfoV16; + readonly deprecationInfo: EnumDeprecationInfoV16; } /** @name PalletConstantMetadataLatest */ @@ -394,7 +388,7 @@ export interface PalletConstantMetadataV16 extends Struct { readonly type: SiLookupTypeId; readonly value: Bytes; readonly docs: Vec; - readonly deprecationInfo: DeprecationInfoV16; + readonly deprecationInfo: ItemDeprecationInfoV16; } /** @name PalletErrorMetadataLatest */ @@ -408,7 +402,7 @@ export interface PalletErrorMetadataV14 extends Struct { /** @name PalletErrorMetadataV16 */ export interface PalletErrorMetadataV16 extends Struct { readonly type: SiLookupTypeId; - readonly deprecationInfo: DeprecationInfoV16; + readonly deprecationInfo: EnumDeprecationInfoV16; } /** @name PalletEventMetadataLatest */ @@ -422,7 +416,7 @@ export interface PalletEventMetadataV14 extends Struct { /** @name PalletEventMetadataV16 */ export interface PalletEventMetadataV16 extends Struct { readonly type: SiLookupTypeId; - readonly deprecationInfo: DeprecationInfoV16; + readonly deprecationInfo: EnumDeprecationInfoV16; } /** @name PalletMetadataLatest */ @@ -461,6 +455,7 @@ export interface PalletMetadataV16 extends Struct { readonly errors: Option; readonly index: u8; readonly docs: Vec; + readonly deprecationInfo: ItemDeprecationInfoV16; } /** @name PalletStorageMetadataLatest */ @@ -502,7 +497,7 @@ export interface RuntimeApiMetadataV16 extends Struct { readonly name: Text; readonly methods: Vec; readonly docs: Vec; - readonly deprecationInfo: DeprecationStatusV16; + readonly deprecationInfo: ItemDeprecationInfoV16; readonly version: Compact; } @@ -520,7 +515,7 @@ export interface RuntimeApiMethodMetadataV16 extends Struct { readonly inputs: Vec; readonly output: SiLookupTypeId; readonly docs: Vec; - readonly deprecationInfo: DeprecationStatusV16; + readonly deprecationInfo: ItemDeprecationInfoV16; } /** @name RuntimeApiMethodParamMetadataV15 */ @@ -588,7 +583,7 @@ export interface StorageEntryMetadataV16 extends Struct { readonly type: StorageEntryTypeV14; readonly fallback: Bytes; readonly docs: Vec; - readonly deprecationInfo: DeprecationStatusV16; + readonly deprecationInfo: ItemDeprecationInfoV16; } /** @name StorageEntryMetadataV9 */ @@ -821,4 +816,15 @@ export interface TransactionExtensionMetadataV16 extends Struct { readonly implicit: SiLookupTypeId; } +/** @name VariantDeprecationInfoV16 */ +export interface VariantDeprecationInfoV16 extends Enum { + readonly isDeprecatedWithoutNote: boolean; + readonly isDeprecated: boolean; + readonly asDeprecated: { + readonly note: Text; + readonly since: Option; + } & Struct; + readonly type: 'DeprecatedWithoutNote' | 'Deprecated'; +} + export type PHANTOM_METADATA = 'metadata'; diff --git a/packages/types/src/interfaces/metadata/v16.ts b/packages/types/src/interfaces/metadata/v16.ts index 4f1e38a9617..c3eb6fbf81a 100644 --- a/packages/types/src/interfaces/metadata/v16.ts +++ b/packages/types/src/interfaces/metadata/v16.ts @@ -27,7 +27,9 @@ export const v16: DefinitionsTypes = { constants: 'Vec', errors: 'Option', index: 'u8', - docs: 'Vec' + docs: 'Vec', + // Deprecation info + deprecationInfo: 'ItemDeprecationInfoV16' }, PalletStorageMetadataV16: { prefix: 'Text', @@ -40,19 +42,19 @@ export const v16: DefinitionsTypes = { fallback: 'Bytes', docs: 'Vec', // Deprecation info - deprecationInfo: 'DeprecationStatusV16' + deprecationInfo: 'ItemDeprecationInfoV16' }, - DeprecationStatusV16: { + ItemDeprecationInfoV16: { _enum: { - // Entry is not deprecated + // Item is not deprecated. NotDeprecated: 'Null', - // Deprecated without a note. + // Item is fully deprecated without a note. DeprecatedWithoutNote: 'Null', - // Entry is deprecated with an note and an optional `since` field. + // Item is fully deprecated with a note and an optional `since` field. Deprecated: { - // Note explaining the deprecation + // Note explaining the deprecation note: 'Text', - // Optional value for denoting version when the deprecation occurred. + // Optional value for noting the version when the deprecation occurred. since: 'Option' } } @@ -60,22 +62,28 @@ export const v16: DefinitionsTypes = { PalletCallMetadataV16: { type: 'SiLookupTypeId', // Deprecation status of the pallet call - deprecationInfo: 'DeprecationInfoV16' + deprecationInfo: 'EnumDeprecationInfoV16' }, - DeprecationInfoV16: { + // Deprecation information for enums in which specific variants can be deprecated. + // If the map is empty, then nothing is deprecated. + EnumDeprecationInfoV16: '(BTreeMap)', + VariantDeprecationInfoV16: { _enum: { - // Type is not deprecated - NotDeprecated: 'Null', - // Entry is fully deprecated. - ItemDeprecated: 'DeprecationStatusV16', - // Entry is partially deprecated. - VariantsDeprecated: 'BTreeMap' + // Variant is deprecated without a note. + DeprecatedWithoutNote: 'Null', + // Variant is deprecated with a note and an optional `since` field. + Deprecated: { + // Note explaining the deprecation + note: 'Text', + // Optional value for noting the version when the deprecation occurred. + since: 'Option' + } } }, PalletEventMetadataV16: { type: 'SiLookupTypeId', // Deprecation info - deprecationInfo: 'DeprecationInfoV16' + deprecationInfo: 'EnumDeprecationInfoV16' }, PalletConstantMetadataV16: { name: 'Text', @@ -83,12 +91,12 @@ export const v16: DefinitionsTypes = { value: 'Bytes', docs: 'Vec', // Deprecation info - deprecationInfo: 'DeprecationInfoV16' + deprecationInfo: 'ItemDeprecationInfoV16' }, PalletErrorMetadataV16: { type: 'SiLookupTypeId', // Deprecation info - deprecationInfo: 'DeprecationInfoV16' + deprecationInfo: 'EnumDeprecationInfoV16' }, // ---- Extrinsic definitions ---- @@ -121,7 +129,7 @@ export const v16: DefinitionsTypes = { methods: 'Vec', docs: 'Vec', // Deprecation info - deprecationInfo: 'DeprecationStatusV16', + deprecationInfo: 'ItemDeprecationInfoV16', // Runtime API version. version: 'Compact' }, @@ -131,6 +139,6 @@ export const v16: DefinitionsTypes = { output: 'SiLookupTypeId', docs: 'Vec', // Deprecation info - deprecationInfo: 'DeprecationStatusV16' + deprecationInfo: 'ItemDeprecationInfoV16' } }; diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index 194bfe4756a..9805b1539b7 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -1,17 +1,20 @@ // Copyright 2017-2025 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DeprecationInfoV16, DeprecationStatusV16, ExtrinsicMetadataV15, ExtrinsicMetadataV16, MetadataV15, MetadataV16, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataV14, PalletStorageMetadataV16, RuntimeApiMetadataV15, RuntimeApiMetadataV16, StorageEntryMetadataV16, TransactionExtensionMetadataV16 } from '../../interfaces/metadata/index.js'; +import type { ExtrinsicMetadataV15, ExtrinsicMetadataV16, ItemDeprecationInfoV16, MetadataV15, MetadataV16, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataV14, PalletStorageMetadataV16, RuntimeApiMetadataV15, RuntimeApiMetadataV16, StorageEntryMetadataV16, TransactionExtensionMetadataV16 } from '../../interfaces/metadata/index.js'; import type { Registry } from '../../types/index.js'; import { type Vec } from '@polkadot/types-codec'; import { objectSpread } from '@polkadot/util'; function palletsFromV15 (registry: Registry, palletV15: PalletMetadataV15): PalletMetadataV16 { + const deprecationInfo: ItemDeprecationInfoV16 = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']); + return registry.createTypeUnsafe('PalletMetadataV16', [ objectSpread({}, palletV15, { calls: palletV15.calls.isSome ? convertCalls(registry, palletV15.calls.unwrap()) : null, constants: convertConstants(registry, palletV15.constants), + deprecationInfo, errors: palletV15.errors.isSome ? converErrors(registry, palletV15.errors.unwrap()) : null, events: palletV15.events.isSome ? convertEvents(registry, palletV15.events.unwrap()) : null, storage: palletV15.storage.isSome ? convertStorage(registry, palletV15.storage.unwrap()) : null @@ -20,7 +23,7 @@ function palletsFromV15 (registry: Registry, palletV15: PalletMetadataV15): Pall } function convertStorage (registry: Registry, storage: PalletStorageMetadataV14): PalletStorageMetadataV16 { - const deprecationInfo = registry.createTypeUnsafe('DeprecationStatusV16', ['NotDeprecated']); + const deprecationInfo: ItemDeprecationInfoV16 = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']); const items: StorageEntryMetadataV16[] = storage.items.map((item) => registry.createTypeUnsafe('StorageEntryMetadataV16', [ @@ -35,7 +38,7 @@ function convertStorage (registry: Registry, storage: PalletStorageMetadataV14): } function convertCalls (registry: Registry, calls: PalletCallMetadataV14): PalletCallMetadataV16 { - const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); + const deprecationInfo = registry.createTypeUnsafe('EnumDeprecationInfoV16', []); return registry.createTypeUnsafe('PalletCallMetadataV16', [{ deprecationInfo, @@ -44,7 +47,7 @@ function convertCalls (registry: Registry, calls: PalletCallMetadataV14): Pallet } function convertEvents (registry: Registry, events: PalletEventMetadataV14): PalletEventMetadataV16 { - const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); + const deprecationInfo = registry.createTypeUnsafe('EnumDeprecationInfoV16', []); return registry.createTypeUnsafe('PalletEventMetadataV16', [{ deprecationInfo, @@ -53,7 +56,7 @@ function convertEvents (registry: Registry, events: PalletEventMetadataV14): Pal } function convertConstants (registry: Registry, constants: Vec): Vec { - const deprecationInfo: DeprecationInfoV16 = registry.createTypeUnsafe('DeprecationInfoV16', ['NotDeprecated']); + const deprecationInfo: ItemDeprecationInfoV16 = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']); return registry.createTypeUnsafe('Vec', [ constants.map((constant) => registry.createTypeUnsafe('PalletConstantMetadataV16', [ @@ -63,7 +66,7 @@ function convertConstants (registry: Registry, constants: Vec', [i]) ); - // FIXME: Metadata: Revise Version, should it match extrinsicV15 latest version? const transactionExtensionsByVersion = registry.createTypeUnsafe( 'BTreeMap>>', [new Map([[registry.createTypeUnsafe('u8', [extrinsicV15.version]), registry.createTypeUnsafe('Vec>', [indexes])]])] @@ -102,7 +104,7 @@ function extrinsicFromV15 (registry: Registry, extrinsicV15: ExtrinsicMetadataV1 } function apisFromV15 (registry: Registry, runtimeApiV15: RuntimeApiMetadataV15): RuntimeApiMetadataV16 { - const deprecationInfo: DeprecationStatusV16 = registry.createTypeUnsafe('DeprecationStatusV16', ['NotDeprecated']); + const deprecationInfo = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']); const methods = runtimeApiV15.methods.map((method) => registry.createTypeUnsafe('RuntimeApiMethodMetadataV16', From 789c2407aa2b933a63166f6fea933071385e7e00 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Tue, 6 May 2025 09:45:31 -0300 Subject: [PATCH 13/18] Add PalletViewFunctionMetadataV16 and PalletAssociatedTypeMetadataV16 --- .../types-augment/src/registry/interfaces.ts | 4 ++- .../types/src/interfaces/metadata/types.ts | 22 +++++++++++++- packages/types/src/interfaces/metadata/v16.ts | 22 ++++++++++++++ packages/types/src/metadata/v15/toV16.ts | 1 + .../types/src/metadata/v16/Metadata.spec.ts | 29 +++++++++++++++++++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 packages/types/src/metadata/v16/Metadata.spec.ts diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 303fd03abb5..b10ac75fc0d 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -44,7 +44,7 @@ import type { AuthorityIndex, AuthorityList, AuthoritySet, AuthoritySetChange, A import type { IdentityFields, IdentityInfo, IdentityInfoAdditional, IdentityInfoTo198, IdentityJudgement, RegistrarIndex, RegistrarInfo, Registration, RegistrationJudgement, RegistrationTo198 } from '@polkadot/types/interfaces/identity'; import type { AuthIndex, AuthoritySignature, Heartbeat, HeartbeatTo244, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline'; import type { CallIndex, LotteryConfig } from '@polkadot/types/interfaces/lottery'; -import type { CustomMetadata15, CustomValueMetadata15, EnumDeprecationInfoV16, ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, ExtrinsicMetadataV15, ExtrinsicMetadataV16, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, ItemDeprecationInfoV16, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV15, MetadataV16, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, OpaqueMetadata, OuterEnums15, PalletCallMetadataLatest, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataLatest, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataLatest, PalletMetadataV14, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataLatest, PalletStorageMetadataV14, PalletStorageMetadataV16, PortableType, PortableTypeV14, RuntimeApiMetadataLatest, RuntimeApiMetadataV15, RuntimeApiMetadataV16, RuntimeApiMethodMetadataV15, RuntimeApiMethodMetadataV16, RuntimeApiMethodParamMetadataV15, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV16, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9, TransactionExtensionMetadataLatest, TransactionExtensionMetadataV16, VariantDeprecationInfoV16 } from '@polkadot/types/interfaces/metadata'; +import type { CustomMetadata15, CustomValueMetadata15, EnumDeprecationInfoV16, ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, ExtrinsicMetadataV15, ExtrinsicMetadataV16, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, ItemDeprecationInfoV16, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV15, MetadataV16, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, OpaqueMetadata, OuterEnums15, PalletAssociatedTypeMetadataV16, PalletCallMetadataLatest, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataLatest, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataLatest, PalletMetadataV14, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataLatest, PalletStorageMetadataV14, PalletStorageMetadataV16, PalletViewFunctionMetadataV16, PortableType, PortableTypeV14, RuntimeApiMetadataLatest, RuntimeApiMetadataV15, RuntimeApiMetadataV16, RuntimeApiMethodMetadataV15, RuntimeApiMethodMetadataV16, RuntimeApiMethodParamMetadataV15, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV16, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9, TransactionExtensionMetadataLatest, TransactionExtensionMetadataV16, VariantDeprecationInfoV16 } from '@polkadot/types/interfaces/metadata'; import type { Mixnode, MixnodesErr, SessionPhase, SessionStatus } from '@polkadot/types/interfaces/mixnet'; import type { MmrBatchProof, MmrEncodableOpaqueLeaf, MmrError, MmrHash, MmrLeafBatchProof, MmrLeafIndex, MmrLeafProof, MmrNodeIndex, MmrProof } from '@polkadot/types/interfaces/mmr'; import type { NftCollectionId, NftItemId } from '@polkadot/types/interfaces/nfts'; @@ -831,6 +831,7 @@ declare module '@polkadot/types/types/registry' { Owner: Owner; PageCounter: PageCounter; PageIndexData: PageIndexData; + PalletAssociatedTypeMetadataV16: PalletAssociatedTypeMetadataV16; PalletCallMetadataLatest: PalletCallMetadataLatest; PalletCallMetadataV14: PalletCallMetadataV14; PalletCallMetadataV16: PalletCallMetadataV16; @@ -855,6 +856,7 @@ declare module '@polkadot/types/types/registry' { PalletStorageMetadataV14: PalletStorageMetadataV14; PalletStorageMetadataV16: PalletStorageMetadataV16; PalletVersion: PalletVersion; + PalletViewFunctionMetadataV16: PalletViewFunctionMetadataV16; ParachainDispatchOrigin: ParachainDispatchOrigin; ParachainInherentData: ParachainInherentData; ParachainProposal: ParachainProposal; diff --git a/packages/types/src/interfaces/metadata/types.ts b/packages/types/src/interfaces/metadata/types.ts index e2bc40d32cf..2bbb5f62a6c 100644 --- a/packages/types/src/interfaces/metadata/types.ts +++ b/packages/types/src/interfaces/metadata/types.ts @@ -2,7 +2,7 @@ /* eslint-disable */ import type { PortableRegistry } from '@polkadot/types'; -import type { BTreeMap, Bytes, Compact, Enum, Option, Struct, Text, Type, Vec, WrapperOpaque, bool, u32, u8 } from '@polkadot/types-codec'; +import type { BTreeMap, Bytes, Compact, Enum, Option, Struct, Text, Type, U8aFixed, Vec, WrapperOpaque, bool, u32, u8 } from '@polkadot/types-codec'; import type { ITuple } from '@polkadot/types-codec/types'; import type { Si1Field, Si1LookupTypeId, Si1Type, SiLookupTypeId } from '@polkadot/types/interfaces/scaleInfo'; @@ -117,6 +117,7 @@ export interface ExtrinsicMetadataV15 extends Struct { export interface ExtrinsicMetadataV16 extends Struct { readonly versions: Bytes; readonly addressType: SiLookupTypeId; + readonly callType: SiLookupTypeId; readonly signatureType: SiLookupTypeId; readonly transactionExtensionsByVersion: BTreeMap>>; readonly transactionExtensions: Vec; @@ -357,6 +358,13 @@ export interface OuterEnums15 extends Struct { readonly errorType: SiLookupTypeId; } +/** @name PalletAssociatedTypeMetadataV16 */ +export interface PalletAssociatedTypeMetadataV16 extends Struct { + readonly name: Text; + readonly type: SiLookupTypeId; + readonly docs: Vec; +} + /** @name PalletCallMetadataLatest */ export interface PalletCallMetadataLatest extends PalletCallMetadataV16 {} @@ -453,6 +461,8 @@ export interface PalletMetadataV16 extends Struct { readonly events: Option; readonly constants: Vec; readonly errors: Option; + readonly associatedTypes: Vec; + readonly viewFunctions: Vec; readonly index: u8; readonly docs: Vec; readonly deprecationInfo: ItemDeprecationInfoV16; @@ -473,6 +483,16 @@ export interface PalletStorageMetadataV16 extends Struct { readonly items: Vec; } +/** @name PalletViewFunctionMetadataV16 */ +export interface PalletViewFunctionMetadataV16 extends Struct { + readonly id: U8aFixed; + readonly name: Text; + readonly inputs: Vec; + readonly output: SiLookupTypeId; + readonly docs: Vec; + readonly deprecationInfo: ItemDeprecationInfoV16; +} + /** @name PortableType */ export interface PortableType extends PortableTypeV14 {} diff --git a/packages/types/src/interfaces/metadata/v16.ts b/packages/types/src/interfaces/metadata/v16.ts index c3eb6fbf81a..a966cc5d2d7 100644 --- a/packages/types/src/interfaces/metadata/v16.ts +++ b/packages/types/src/interfaces/metadata/v16.ts @@ -26,6 +26,8 @@ export const v16: DefinitionsTypes = { events: 'Option', constants: 'Vec', errors: 'Option', + associatedTypes: 'Vec', + viewFunctions: 'Vec', index: 'u8', docs: 'Vec', // Deprecation info @@ -98,6 +100,24 @@ export const v16: DefinitionsTypes = { // Deprecation info deprecationInfo: 'EnumDeprecationInfoV16' }, + PalletAssociatedTypeMetadataV16: { + name: 'Text', + type: 'SiLookupTypeId', + docs: 'Vec' + }, + PalletViewFunctionMetadataV16: { + id: '[u8; 32]', + // Method name. + name: 'Text', + // Method par ameters. + inputs: 'Vec', + // Method output. + output: 'SiLookupTypeId', + // Method documentation. + docs: 'Vec', + // Deprecation info + deprecationInfo: 'ItemDeprecationInfoV16' + }, // ---- Extrinsic definitions ---- ExtrinsicMetadataV16: { @@ -105,6 +125,8 @@ export const v16: DefinitionsTypes = { versions: 'Vec', // The type of the address that signs the extrinsic addressType: 'SiLookupTypeId', + // The type of the outermost Call enum. + callType: 'SiLookupTypeId', // The type of the extrinsic's signature. signatureType: 'SiLookupTypeId', // A mapping of supported transaction extrinsic versions to their respective transaction extension indexes. diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index 9805b1539b7..11f9de89101 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -95,6 +95,7 @@ function extrinsicFromV15 (registry: Registry, extrinsicV15: ExtrinsicMetadataV1 return registry.createTypeUnsafe('ExtrinsicMetadataV16', [ { addressType: extrinsicV15.addressType, + callType: extrinsicV15.callType, signatureType: extrinsicV15.signatureType, transactionExtensions, transactionExtensionsByVersion, diff --git a/packages/types/src/metadata/v16/Metadata.spec.ts b/packages/types/src/metadata/v16/Metadata.spec.ts new file mode 100644 index 00000000000..38e952cefe2 --- /dev/null +++ b/packages/types/src/metadata/v16/Metadata.spec.ts @@ -0,0 +1,29 @@ +// Copyright 2017-2025 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 +/* +import assetHubKusamaData from '@polkadot/types-support/metadata/v15/asset-hub-kusama-hex'; +import assetHubPolkadotData from '@polkadot/types-support/metadata/v15/asset-hub-polkadot-hex'; +import kusamaData from '@polkadot/types-support/metadata/v15/kusama-hex'; +import polkadotData from '@polkadot/types-support/metadata/v15/polkadot-hex'; +import substrateData from '@polkadot/types-support/metadata/v15/substrate-hex'; + +import { testMeta } from '../util/testUtil.js'; + +testMeta(16, { + 'asset-hub-kusama': { + data: assetHubKusamaData + }, + 'asset-hub-polkadot': { + data: assetHubPolkadotData + }, + kusama: { + data: kusamaData + }, + polkadot: { + data: polkadotData + }, + substrate: { + data: substrateData + } +}); + */ From b07d48646d7d30e0d1d1ded727fc969ca5db2b07 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Tue, 6 May 2025 12:28:59 -0300 Subject: [PATCH 14/18] Add view functions and associatedTypes in toV16 --- packages/types/src/interfaces/metadata/v16.ts | 2 +- packages/types/src/metadata/v15/toV16.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/types/src/interfaces/metadata/v16.ts b/packages/types/src/interfaces/metadata/v16.ts index a966cc5d2d7..c04c159b9d7 100644 --- a/packages/types/src/interfaces/metadata/v16.ts +++ b/packages/types/src/interfaces/metadata/v16.ts @@ -7,7 +7,7 @@ import type { DefinitionsTypes } from '../../types/index.js'; export const v16: DefinitionsTypes = { -// actual v16 definition + // actual v16 definition MetadataV16: { lookup: 'PortableRegistry', pallets: 'Vec', diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index 11f9de89101..dace0910916 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -1,7 +1,7 @@ // Copyright 2017-2025 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { ExtrinsicMetadataV15, ExtrinsicMetadataV16, ItemDeprecationInfoV16, MetadataV15, MetadataV16, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataV14, PalletStorageMetadataV16, RuntimeApiMetadataV15, RuntimeApiMetadataV16, StorageEntryMetadataV16, TransactionExtensionMetadataV16 } from '../../interfaces/metadata/index.js'; +import type { ExtrinsicMetadataV15, ExtrinsicMetadataV16, ItemDeprecationInfoV16, MetadataV15, MetadataV16, PalletAssociatedTypeMetadataV16, PalletCallMetadataV14, PalletCallMetadataV16, PalletConstantMetadataV14, PalletConstantMetadataV16, PalletErrorMetadataV14, PalletErrorMetadataV16, PalletEventMetadataV14, PalletEventMetadataV16, PalletMetadataV15, PalletMetadataV16, PalletStorageMetadataV14, PalletStorageMetadataV16, RuntimeApiMetadataV15, RuntimeApiMetadataV16, StorageEntryMetadataV16, TransactionExtensionMetadataV16 } from '../../interfaces/metadata/index.js'; import type { Registry } from '../../types/index.js'; import { type Vec } from '@polkadot/types-codec'; @@ -9,15 +9,19 @@ import { objectSpread } from '@polkadot/util'; function palletsFromV15 (registry: Registry, palletV15: PalletMetadataV15): PalletMetadataV16 { const deprecationInfo: ItemDeprecationInfoV16 = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']); + const associatedTypes: Vec = registry.createTypeUnsafe('Vec',[[]]); + const viewFunctions: Vec = registry.createTypeUnsafe('Vec',[[]]); return registry.createTypeUnsafe('PalletMetadataV16', [ objectSpread({}, palletV15, { + associatedTypes, calls: palletV15.calls.isSome ? convertCalls(registry, palletV15.calls.unwrap()) : null, constants: convertConstants(registry, palletV15.constants), deprecationInfo, errors: palletV15.errors.isSome ? converErrors(registry, palletV15.errors.unwrap()) : null, events: palletV15.events.isSome ? convertEvents(registry, palletV15.events.unwrap()) : null, - storage: palletV15.storage.isSome ? convertStorage(registry, palletV15.storage.unwrap()) : null + storage: palletV15.storage.isSome ? convertStorage(registry, palletV15.storage.unwrap()) : null, + viewFunctions }) ]); } From ee210b8666d7aafc14d32dd8dd6735f93a11bd97 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Fri, 9 May 2025 09:20:23 -0300 Subject: [PATCH 15/18] lint --- packages/types/src/metadata/v15/toV16.ts | 4 ++-- packages/types/src/metadata/v16/Metadata.spec.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/types/src/metadata/v15/toV16.ts b/packages/types/src/metadata/v15/toV16.ts index dace0910916..40c80c05295 100644 --- a/packages/types/src/metadata/v15/toV16.ts +++ b/packages/types/src/metadata/v15/toV16.ts @@ -9,8 +9,8 @@ import { objectSpread } from '@polkadot/util'; function palletsFromV15 (registry: Registry, palletV15: PalletMetadataV15): PalletMetadataV16 { const deprecationInfo: ItemDeprecationInfoV16 = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']); - const associatedTypes: Vec = registry.createTypeUnsafe('Vec',[[]]); - const viewFunctions: Vec = registry.createTypeUnsafe('Vec',[[]]); + const associatedTypes: Vec = registry.createTypeUnsafe('Vec', [[]]); + const viewFunctions: Vec = registry.createTypeUnsafe('Vec', [[]]); return registry.createTypeUnsafe('PalletMetadataV16', [ objectSpread({}, palletV15, { diff --git a/packages/types/src/metadata/v16/Metadata.spec.ts b/packages/types/src/metadata/v16/Metadata.spec.ts index 38e952cefe2..9990fafcea2 100644 --- a/packages/types/src/metadata/v16/Metadata.spec.ts +++ b/packages/types/src/metadata/v16/Metadata.spec.ts @@ -1,5 +1,6 @@ // Copyright 2017-2025 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 + /* import assetHubKusamaData from '@polkadot/types-support/metadata/v15/asset-hub-kusama-hex'; import assetHubPolkadotData from '@polkadot/types-support/metadata/v15/asset-hub-polkadot-hex'; From 0fd6387a02542a8dd310c501e0559410373775d2 Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Tue, 13 May 2025 16:02:49 -0300 Subject: [PATCH 16/18] Remove u32::max from supported versions --- packages/api/src/base/Init.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/src/base/Init.ts b/packages/api/src/base/Init.ts index 689cd168664..104ef4d2173 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -25,7 +25,7 @@ const KEEPALIVE_INTERVAL = 10000; const WITH_VERSION_SHORTCUT = false; // TODO: Remove U32::MAX when metadata 16 is stabilized. -const SUPPORTED_METADATA_VERSIONS = [4294967295, 16, 15, 14]; +const SUPPORTED_METADATA_VERSIONS = [16, 15, 14]; const l = logger('api/init'); From c9a37508f0f51a4d5c8868e8a53329cc1856b74d Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Wed, 14 May 2025 16:22:39 -0300 Subject: [PATCH 17/18] Tweak v16 types --- packages/typegen/src/generate/errors.ts | 2 +- packages/typegen/src/generate/events.ts | 2 +- packages/typegen/src/generate/tx.ts | 2 +- .../types/src/interfaces/metadata/types.ts | 9 ++++----- packages/types/src/interfaces/metadata/v16.ts | 14 ++++++++------ .../types/src/metadata/v16/Metadata.spec.ts | 18 +++++++++--------- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/packages/typegen/src/generate/errors.ts b/packages/typegen/src/generate/errors.ts index 15f4d4ea005..4dcc4c11677 100644 --- a/packages/typegen/src/generate/errors.ts +++ b/packages/typegen/src/generate/errors.ts @@ -39,7 +39,7 @@ function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void .map((data) => { const name = data.name; const errors = data.errors.unwrap(); - const deprecationInfo = errors.deprecationInfo[0].toJSON(); + const deprecationInfo = errors.deprecationInfo.toJSON(); return { items: lookup.getSiType(errors.type).def.asVariant.variants diff --git a/packages/typegen/src/generate/events.ts b/packages/typegen/src/generate/events.ts index bad043c947e..54abcdc400c 100644 --- a/packages/typegen/src/generate/events.ts +++ b/packages/typegen/src/generate/events.ts @@ -101,7 +101,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, .map((data) => { const name = data.name; const events = data.events.unwrap(); - const deprecationInfo = events.deprecationInfo[0].toJSON(); + const deprecationInfo = events.deprecationInfo.toJSON(); return { items: lookup.getSiType(events.type).def.asVariant.variants diff --git a/packages/typegen/src/generate/tx.ts b/packages/typegen/src/generate/tx.ts index 142800580df..a667ca6ce39 100644 --- a/packages/typegen/src/generate/tx.ts +++ b/packages/typegen/src/generate/tx.ts @@ -70,7 +70,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr .map((data) => { const name = data.name; const calls = data.calls.unwrap(); - const deprecationInfo = calls.deprecationInfo[0].toJSON(); + const deprecationInfo = calls.deprecationInfo.toJSON(); setImports(allDefs, imports, ['SubmittableExtrinsic']); diff --git a/packages/types/src/interfaces/metadata/types.ts b/packages/types/src/interfaces/metadata/types.ts index 2bbb5f62a6c..85debb77474 100644 --- a/packages/types/src/interfaces/metadata/types.ts +++ b/packages/types/src/interfaces/metadata/types.ts @@ -3,7 +3,6 @@ import type { PortableRegistry } from '@polkadot/types'; import type { BTreeMap, Bytes, Compact, Enum, Option, Struct, Text, Type, U8aFixed, Vec, WrapperOpaque, bool, u32, u8 } from '@polkadot/types-codec'; -import type { ITuple } from '@polkadot/types-codec/types'; import type { Si1Field, Si1LookupTypeId, Si1Type, SiLookupTypeId } from '@polkadot/types/interfaces/scaleInfo'; /** @name CustomMetadata15 */ @@ -18,7 +17,7 @@ export interface CustomValueMetadata15 extends Struct { } /** @name EnumDeprecationInfoV16 */ -export interface EnumDeprecationInfoV16 extends ITuple<[BTreeMap]> {} +export interface EnumDeprecationInfoV16 extends BTreeMap {} /** @name ErrorMetadataLatest */ export interface ErrorMetadataLatest extends ErrorMetadataV14 {} @@ -265,7 +264,6 @@ export interface MetadataV16 extends Struct { readonly lookup: PortableRegistry; readonly pallets: Vec; readonly extrinsic: ExtrinsicMetadataV16; - readonly type: SiLookupTypeId; readonly apis: Vec; readonly outerEnums: OuterEnums15; readonly custom: CustomMetadata15; @@ -517,8 +515,8 @@ export interface RuntimeApiMetadataV16 extends Struct { readonly name: Text; readonly methods: Vec; readonly docs: Vec; - readonly deprecationInfo: ItemDeprecationInfoV16; readonly version: Compact; + readonly deprecationInfo: ItemDeprecationInfoV16; } /** @name RuntimeApiMethodMetadataV15 */ @@ -838,13 +836,14 @@ export interface TransactionExtensionMetadataV16 extends Struct { /** @name VariantDeprecationInfoV16 */ export interface VariantDeprecationInfoV16 extends Enum { + readonly isDummyVariant: boolean; readonly isDeprecatedWithoutNote: boolean; readonly isDeprecated: boolean; readonly asDeprecated: { readonly note: Text; readonly since: Option; } & Struct; - readonly type: 'DeprecatedWithoutNote' | 'Deprecated'; + readonly type: 'DummyVariant' | 'DeprecatedWithoutNote' | 'Deprecated'; } export type PHANTOM_METADATA = 'metadata'; diff --git a/packages/types/src/interfaces/metadata/v16.ts b/packages/types/src/interfaces/metadata/v16.ts index c04c159b9d7..3a635cd1455 100644 --- a/packages/types/src/interfaces/metadata/v16.ts +++ b/packages/types/src/interfaces/metadata/v16.ts @@ -12,7 +12,6 @@ export const v16: DefinitionsTypes = { lookup: 'PortableRegistry', pallets: 'Vec', extrinsic: 'ExtrinsicMetadataV16', - type: 'SiLookupTypeId', apis: 'Vec', outerEnums: 'OuterEnums15', custom: 'CustomMetadata15' @@ -43,7 +42,6 @@ export const v16: DefinitionsTypes = { type: 'StorageEntryTypeV14', fallback: 'Bytes', docs: 'Vec', - // Deprecation info deprecationInfo: 'ItemDeprecationInfoV16' }, ItemDeprecationInfoV16: { @@ -68,9 +66,12 @@ export const v16: DefinitionsTypes = { }, // Deprecation information for enums in which specific variants can be deprecated. // If the map is empty, then nothing is deprecated. - EnumDeprecationInfoV16: '(BTreeMap)', + EnumDeprecationInfoV16: 'BTreeMap', VariantDeprecationInfoV16: { _enum: { + // Dummy variant, just here to force DeprecatedWithoutNote + // to have index 1 and Deprecated to have index 2 + DummyVariant: 'Null', // Variant is deprecated without a note. DeprecatedWithoutNote: 'Null', // Variant is deprecated with a note and an optional `since` field. @@ -80,6 +81,7 @@ export const v16: DefinitionsTypes = { // Optional value for noting the version when the deprecation occurred. since: 'Option' } + } }, PalletEventMetadataV16: { @@ -150,10 +152,10 @@ export const v16: DefinitionsTypes = { name: 'Text', methods: 'Vec', docs: 'Vec', - // Deprecation info - deprecationInfo: 'ItemDeprecationInfoV16', // Runtime API version. - version: 'Compact' + version: 'Compact', + // Deprecation info + deprecationInfo: 'ItemDeprecationInfoV16' }, RuntimeApiMethodMetadataV16: { name: 'Text', diff --git a/packages/types/src/metadata/v16/Metadata.spec.ts b/packages/types/src/metadata/v16/Metadata.spec.ts index 9990fafcea2..d1fa599bdd0 100644 --- a/packages/types/src/metadata/v16/Metadata.spec.ts +++ b/packages/types/src/metadata/v16/Metadata.spec.ts @@ -1,17 +1,18 @@ // Copyright 2017-2025 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -/* -import assetHubKusamaData from '@polkadot/types-support/metadata/v15/asset-hub-kusama-hex'; -import assetHubPolkadotData from '@polkadot/types-support/metadata/v15/asset-hub-polkadot-hex'; -import kusamaData from '@polkadot/types-support/metadata/v15/kusama-hex'; -import polkadotData from '@polkadot/types-support/metadata/v15/polkadot-hex'; -import substrateData from '@polkadot/types-support/metadata/v15/substrate-hex'; +/* import assetHubKusamaData from '@polkadot/types-support/metadata/v16/asset-hub-kusama-hex'; +import assetHubPolkadotData from '@polkadot/types-support/metadata/v16/asset-hub-polkadot-hex'; +import kusamaData from '@polkadot/types-support/metadata/v16/kusama-hex'; +import polkadotData from '@polkadot/types-support/metadata/v16/polkadot-hex'; +import substrateData from '@polkadot/types-support/metadata/v16/substrate-hex';*/ import { testMeta } from '../util/testUtil.js'; +// TODO: Once MetadataV16 lands in an official release, pull the +// latest metadata for each chain and update the tests testMeta(16, { - 'asset-hub-kusama': { +/* 'asset-hub-kusama': { data: assetHubKusamaData }, 'asset-hub-polkadot': { @@ -25,6 +26,5 @@ testMeta(16, { }, substrate: { data: substrateData - } + }*/ }); - */ From 302c7127badfb6538d496872d1b3eee7a02ea54e Mon Sep 17 00:00:00 2001 From: Valentin Fernandez Date: Thu, 15 May 2025 12:15:10 -0300 Subject: [PATCH 18/18] Address feedback --- packages/api/src/base/Init.ts | 1 - packages/typegen/src/generate/consts.ts | 20 ++------------------ packages/typegen/src/generate/errors.ts | 17 +---------------- packages/typegen/src/generate/events.ts | 17 +---------------- packages/typegen/src/generate/query.ts | 19 ++----------------- packages/typegen/src/generate/runtime.ts | 19 ++----------------- packages/typegen/src/generate/tx.ts | 19 ++----------------- packages/typegen/src/generate/types.ts | 19 +++++++++++++++++++ packages/types/src/extrinsic/Extrinsic.ts | 1 - scripts/metadata-get.mjs | 4 ++-- 10 files changed, 31 insertions(+), 105 deletions(-) diff --git a/packages/api/src/base/Init.ts b/packages/api/src/base/Init.ts index 104ef4d2173..c0d9a8e2aaa 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -24,7 +24,6 @@ import { Decorate } from './Decorate.js'; const KEEPALIVE_INTERVAL = 10000; const WITH_VERSION_SHORTCUT = false; -// TODO: Remove U32::MAX when metadata 16 is stabilized. const SUPPORTED_METADATA_VERSIONS = [16, 15, 14]; const l = logger('api/init'); diff --git a/packages/typegen/src/generate/consts.ts b/packages/typegen/src/generate/consts.ts index bf87f4da215..45fb311f9a9 100644 --- a/packages/typegen/src/generate/consts.ts +++ b/packages/typegen/src/generate/consts.ts @@ -1,11 +1,9 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { ItemDeprecationInfoV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { Definitions } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; -import type { ExtraTypes } from './types.js'; import Handlebars from 'handlebars'; @@ -15,24 +13,10 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; +import { type ExtraTypes, getDeprecationNotice } from './types.js'; const generateForMetaTemplate = Handlebars.compile(readTemplate('consts')); -function getDeprecationNotice (deprecationInfo: ItemDeprecationInfoV16, name: string): string { - let deprecationNotice = '@deprecated'; - - if (deprecationInfo.isDeprecated) { - const { note, since } = deprecationInfo.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - - deprecationNotice += ` ${note.toString()}${sinceText}`; - } else { - deprecationNotice += ` Constant ${name} has been deprecated`; - } - - return deprecationNotice; -} - /** @internal */ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void { writeFile(dest, (): string => { @@ -66,7 +50,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, const returnType = typeDef.lookupName || formatType(registry, allDefs, typeDef, imports); if (!deprecationInfo.isNotDeprecated) { - const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name)); + const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name), 'Constant'); const items = docs.length ? ['', deprecationNotice] diff --git a/packages/typegen/src/generate/errors.ts b/packages/typegen/src/generate/errors.ts index 4dcc4c11677..95b23372817 100644 --- a/packages/typegen/src/generate/errors.ts +++ b/packages/typegen/src/generate/errors.ts @@ -4,31 +4,16 @@ import type { VariantDeprecationInfoV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { HexString } from '@polkadot/util/types'; -import type { ExtraTypes } from './types.js'; import Handlebars from 'handlebars'; import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, initMeta, readTemplate, writeFile } from '../util/index.js'; +import { type ExtraTypes, getDeprecationNotice } from './types.js'; const generateForMetaTemplate = Handlebars.compile(readTemplate('errors')); -function getDeprecationNotice (deprecationInfo: VariantDeprecationInfoV16, name: string): string { - let deprecationNotice = '@deprecated'; - - if (deprecationInfo.isDeprecated) { - const { note, since } = deprecationInfo.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - - deprecationNotice += ` ${note.toString()}${sinceText}`; - } else { - deprecationNotice += ` ${name} has been deprecated`; - } - - return deprecationNotice; -} - /** @internal */ function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void { writeFile(dest, (): string => { diff --git a/packages/typegen/src/generate/events.ts b/packages/typegen/src/generate/events.ts index 54abcdc400c..e877bd44654 100644 --- a/packages/typegen/src/generate/events.ts +++ b/packages/typegen/src/generate/events.ts @@ -5,7 +5,6 @@ import type { VariantDeprecationInfoV16 } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { Definitions } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; -import type { ExtraTypes } from './types.js'; import Handlebars from 'handlebars'; @@ -15,6 +14,7 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; +import { type ExtraTypes, getDeprecationNotice } from './types.js'; const generateForMetaTemplate = Handlebars.compile(readTemplate('events')); @@ -62,21 +62,6 @@ const ALIAS = [ 'yield' ]; -function getDeprecationNotice (deprecationInfo: VariantDeprecationInfoV16, name: string): string { - let deprecationNotice = '@deprecated'; - - if (deprecationInfo.isDeprecated) { - const { note, since } = deprecationInfo.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - - deprecationNotice += ` ${note.toString()}${sinceText}`; - } else { - deprecationNotice += ` ${name} has been deprecated`; - } - - return deprecationNotice; -} - /** @internal */ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void { writeFile(dest, (): string => { diff --git a/packages/typegen/src/generate/query.ts b/packages/typegen/src/generate/query.ts index 5901f515c02..583530859bc 100644 --- a/packages/typegen/src/generate/query.ts +++ b/packages/typegen/src/generate/query.ts @@ -1,12 +1,11 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { ItemDeprecationInfoV16, StorageEntryMetadataLatest } from '@polkadot/types/interfaces'; +import type { StorageEntryMetadataLatest } from '@polkadot/types/interfaces'; import type { Metadata, PortableRegistry } from '@polkadot/types/metadata'; import type { Definitions, Registry } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; import type { ModuleTypes, TypeImports } from '../util/imports.js'; -import type { ExtraTypes } from './types.js'; import Handlebars from 'handlebars'; @@ -17,24 +16,10 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, getSimilarTypes, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; +import { type ExtraTypes, getDeprecationNotice } from './types.js'; const generateForMetaTemplate = Handlebars.compile(readTemplate('query')); -function getDeprecationNotice (deprecationInfo: ItemDeprecationInfoV16, name: string): string { - let deprecationNotice = '@deprecated'; - - if (deprecationInfo.isDeprecated) { - const { note, since } = deprecationInfo.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - - deprecationNotice += ` ${note.toString()}${sinceText}`; - } else { - deprecationNotice += ` ${name} has been deprecated`; - } - - return deprecationNotice; -} - // From a storage entry metadata, we return [args, returnType] /** @internal */ function entrySignature (lookup: PortableRegistry, allDefs: Record, registry: Registry, section: string, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [boolean, string, string, string] { diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index 26c27df5a10..e6e89fad38b 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -1,12 +1,11 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { ItemDeprecationInfoV16, RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@polkadot/types/interfaces'; +import type { RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@polkadot/types/interfaces'; import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { DefinitionCall, DefinitionCallNamed, Definitions, DefinitionsCall, Registry } from '@polkadot/types/types'; import type { Vec } from '@polkadot/types-codec'; import type { HexString } from '@polkadot/util/types'; -import type { ExtraTypes } from './types.js'; import Handlebars from 'handlebars'; @@ -16,6 +15,7 @@ import { objectSpread, stringCamelCase } from '@polkadot/util'; import { blake2AsHex } from '@polkadot/util-crypto'; import { createImports, formatType, getSimilarTypes, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; +import { type ExtraTypes, getDeprecationNotice } from './types.js'; type Apis = [HexString, number][]; @@ -51,21 +51,6 @@ const getTypesViaAlias = (registry: Registry, id: SiLookupTypeId) => { return typeName; }; -function getDeprecationNotice (deprecationInfo: ItemDeprecationInfoV16, name: string): string { - let deprecationNotice = '@deprecated'; - - if (deprecationInfo.isDeprecated) { - const { note, since } = deprecationInfo.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - - deprecationNotice += ` ${note.toString()}${sinceText}`; - } else { - deprecationNotice += ` ${name} has been deprecated`; - } - - return deprecationNotice; -} - /** @internal */ function getMethods (registry: Registry, methods: Vec) { const result: Record = {}; diff --git a/packages/typegen/src/generate/tx.ts b/packages/typegen/src/generate/tx.ts index a667ca6ce39..6f48b9cf24f 100644 --- a/packages/typegen/src/generate/tx.ts +++ b/packages/typegen/src/generate/tx.ts @@ -6,7 +6,6 @@ import type { Metadata } from '@polkadot/types/metadata/Metadata'; import type { Text } from '@polkadot/types/primitive'; import type { Definitions, Registry } from '@polkadot/types/types'; import type { HexString } from '@polkadot/util/types'; -import type { ExtraTypes } from './types.js'; import Handlebars from 'handlebars'; @@ -16,6 +15,7 @@ import { stringCamelCase } from '@polkadot/util'; import { compareName, createImports, formatType, getSimilarTypes, initMeta, readTemplate, setImports, writeFile } from '../util/index.js'; import { ignoreUnusedLookups } from './lookup.js'; +import { type ExtraTypes, getDeprecationNotice } from './types.js'; const MAPPED_NAMES: Record = { class: 'clazz', @@ -30,21 +30,6 @@ function mapName (_name: Text): string { return MAPPED_NAMES[name] || name; } -function getDeprecationNotice (deprecationInfo: VariantDeprecationInfoV16, name: string): string { - let deprecationNotice = '@deprecated'; - - if (deprecationInfo.isDeprecated) { - const { note, since } = deprecationInfo.asDeprecated; - const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; - - deprecationNotice += ` ${note.toString()}${sinceText}`; - } else { - deprecationNotice += ` Call ${name}() has been deprecated`; - } - - return deprecationNotice; -} - /** @internal */ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void { writeFile(dest, (): string => { @@ -81,7 +66,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr if (rawStatus) { const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]); - const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString()); + const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString(), 'Call'); const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice]; docs.push(...notice.map((text) => meta.registry.createType('Text', text))); diff --git a/packages/typegen/src/generate/types.ts b/packages/typegen/src/generate/types.ts index bec6b415aed..30ebe5abafd 100644 --- a/packages/typegen/src/generate/types.ts +++ b/packages/typegen/src/generate/types.ts @@ -1,7 +1,26 @@ // Copyright 2017-2025 @polkadot/typegen authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { Option, Text } from '@polkadot/types-codec'; + export type ExtraTypes = Record; types: Record; }>>; + +export function getDeprecationNotice }}> (deprecationInfo: T, name: string, label?: string): string { + let deprecationNotice = '@deprecated'; + + if (deprecationInfo.isDeprecated) { + const { note, since } = deprecationInfo.asDeprecated; + const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : ''; + + deprecationNotice += ` ${note.toString()}${sinceText}`; + } else { + const labelText = label ? `${label} ` : ''; + + deprecationNotice += ` ${labelText}${name} has been deprecated`; + } + + return deprecationNotice; +} diff --git a/packages/types/src/extrinsic/Extrinsic.ts b/packages/types/src/extrinsic/Extrinsic.ts index 777ee0f5995..294e28af763 100644 --- a/packages/types/src/extrinsic/Extrinsic.ts +++ b/packages/types/src/extrinsic/Extrinsic.ts @@ -332,7 +332,6 @@ export class GenericExtrinsic extends ExtrinsicBa const versionsLength = registry.metadata.extrinsic.versions.length; const highestSupportedVersion = versionsLength ? registry.metadata.extrinsic.versions[versionsLength - 1] : undefined; - console.log(registry.metadata.extrinsic.versions); super(registry, decodeExtrinsic(registry, value, version || highestSupportedVersion, preamble), undefined, preamble); } diff --git a/scripts/metadata-get.mjs b/scripts/metadata-get.mjs index 60818c20315..0a47a32d930 100644 --- a/scripts/metadata-get.mjs +++ b/scripts/metadata-get.mjs @@ -16,8 +16,8 @@ const CMD = { }; // V15 -const META_VERSION_HEX = '0x10000000'; -const META_VERSION = 16; +const META_VERSION_HEX = '0x0f000000'; +const META_VERSION = 15; /** * Parse the specName given any exceptions.