Metadata v16 (#6130)

* Initial scafolding

* metadatav16 generated types

* Correct registry setSignedExtension

* toV16() impl

* Remove references to MetadataV15

* Fix toV16() conversion

* Progress on deprecation notice

* Add deprecationInfo to code generation

* Fix compilation issues

* lint

* Remove console.log()

* Update metadata DeprecationInfo

* Add PalletViewFunctionMetadataV16 and PalletAssociatedTypeMetadataV16

* Add view functions and associatedTypes in toV16

* lint

* Remove u32::max from supported versions

* Tweak v16 types

* Address feedback
This commit is contained in:
Valentin Fernandez
2025-05-16 09:06:40 -03:00
committed by GitHub
parent 08d373ea2c
commit 4e9c3d1978
23 changed files with 728 additions and 94 deletions
+3 -3
View File
@@ -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';
@@ -608,9 +608,9 @@ export class TypeRegistry implements Registry {
// setup the available extensions
this.setSignedExtensions(
signedExtensions || (
this.#metadata.extrinsic.version.gt(BN_ZERO)
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.signedExtensions.map(({ identifier }) => identifier.toString())
? this.#metadata.extrinsic.transactionExtensions.map(({ identifier }) => identifier.toString())
: fallbackExtensions
),
userExtensions,
+4 -1
View File
@@ -329,7 +329,10 @@ export class GenericExtrinsic<A extends AnyTuple = AnyTuple> 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;
super(registry, decodeExtrinsic(registry, value, version || highestSupportedVersion, preamble), undefined, preamble);
}
/**
@@ -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,26 +31,28 @@ export default {
...v13,
...v14,
...v15,
...v16,
// latest mappings
// NOTE: For v15, we only added the runtime defintions,
// 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',
@@ -76,7 +79,8 @@ export default {
V12: 'MetadataV12',
V13: 'MetadataV13',
V14: 'MetadataV14',
V15: 'MetadataV15'
V15: 'MetadataV15',
V16: 'MetadataV16'
}
}
}
+164 -12
View File
@@ -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, U8aFixed, 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,9 @@ export interface CustomValueMetadata15 extends Struct {
readonly value: Bytes;
}
/** @name EnumDeprecationInfoV16 */
export interface EnumDeprecationInfoV16 extends BTreeMap<u8, VariantDeprecationInfoV16> {}
/** @name ErrorMetadataLatest */
export interface ErrorMetadataLatest extends ErrorMetadataV14 {}
@@ -78,7 +81,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 +112,16 @@ export interface ExtrinsicMetadataV15 extends Struct {
readonly signedExtensions: Vec<SignedExtensionMetadataV14>;
}
/** @name ExtrinsicMetadataV16 */
export interface ExtrinsicMetadataV16 extends Struct {
readonly versions: Bytes;
readonly addressType: SiLookupTypeId;
readonly callType: SiLookupTypeId;
readonly signatureType: SiLookupTypeId;
readonly transactionExtensionsByVersion: BTreeMap<u8, Vec<Compact<u32>>>;
readonly transactionExtensions: Vec<TransactionExtensionMetadataV16>;
}
/** @name FunctionArgumentMetadataLatest */
export interface FunctionArgumentMetadataLatest extends FunctionArgumentMetadataV14 {}
@@ -168,6 +181,18 @@ export interface FunctionMetadataV9 extends Struct {
readonly docs: Vec<Text>;
}
/** @name ItemDeprecationInfoV16 */
export interface ItemDeprecationInfoV16 extends Enum {
readonly isNotDeprecated: boolean;
readonly isDeprecatedWithoutNote: boolean;
readonly isDeprecated: boolean;
readonly asDeprecated: {
readonly note: Text;
readonly since: Option<Text>;
} & Struct;
readonly type: 'NotDeprecated' | 'DeprecatedWithoutNote' | 'Deprecated';
}
/** @name MetadataAll */
export interface MetadataAll extends Enum {
readonly isV9: boolean;
@@ -184,11 +209,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 +259,16 @@ export interface MetadataV15 extends Struct {
readonly custom: CustomMetadata15;
}
/** @name MetadataV16 */
export interface MetadataV16 extends Struct {
readonly lookup: PortableRegistry;
readonly pallets: Vec<PalletMetadataV16>;
readonly extrinsic: ExtrinsicMetadataV16;
readonly apis: Vec<RuntimeApiMetadataV16>;
readonly outerEnums: OuterEnums15;
readonly custom: CustomMetadata15;
}
/** @name MetadataV9 */
export interface MetadataV9 extends Struct {
readonly modules: Vec<ModuleMetadataV9>;
@@ -319,16 +356,29 @@ export interface OuterEnums15 extends Struct {
readonly errorType: SiLookupTypeId;
}
/** @name PalletAssociatedTypeMetadataV16 */
export interface PalletAssociatedTypeMetadataV16 extends Struct {
readonly name: Text;
readonly type: SiLookupTypeId;
readonly docs: Vec<Text>;
}
/** @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: EnumDeprecationInfoV16;
}
/** @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<Text>;
}
/** @name PalletConstantMetadataV16 */
export interface PalletConstantMetadataV16 extends Struct {
readonly name: Text;
readonly type: SiLookupTypeId;
readonly value: Bytes;
readonly docs: Vec<Text>;
readonly deprecationInfo: ItemDeprecationInfoV16;
}
/** @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: EnumDeprecationInfoV16;
}
/** @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: EnumDeprecationInfoV16;
}
/** @name PalletMetadataLatest */
export interface PalletMetadataLatest extends PalletMetadataV15 {}
export interface PalletMetadataLatest extends PalletMetadataV16 {}
/** @name PalletMetadataV14 */
export interface PalletMetadataV14 extends Struct {
@@ -380,8 +451,23 @@ export interface PalletMetadataV15 extends Struct {
readonly docs: Vec<Text>;
}
/** @name PalletMetadataV16 */
export interface PalletMetadataV16 extends Struct {
readonly name: Text;
readonly storage: Option<PalletStorageMetadataV16>;
readonly calls: Option<PalletCallMetadataV16>;
readonly events: Option<PalletEventMetadataV16>;
readonly constants: Vec<PalletConstantMetadataV16>;
readonly errors: Option<PalletErrorMetadataV16>;
readonly associatedTypes: Vec<PalletAssociatedTypeMetadataV16>;
readonly viewFunctions: Vec<PalletViewFunctionMetadataV16>;
readonly index: u8;
readonly docs: Vec<Text>;
readonly deprecationInfo: ItemDeprecationInfoV16;
}
/** @name PalletStorageMetadataLatest */
export interface PalletStorageMetadataLatest extends PalletStorageMetadataV14 {}
export interface PalletStorageMetadataLatest extends PalletStorageMetadataV16 {}
/** @name PalletStorageMetadataV14 */
export interface PalletStorageMetadataV14 extends Struct {
@@ -389,6 +475,22 @@ export interface PalletStorageMetadataV14 extends Struct {
readonly items: Vec<StorageEntryMetadataV14>;
}
/** @name PalletStorageMetadataV16 */
export interface PalletStorageMetadataV16 extends Struct {
readonly prefix: Text;
readonly items: Vec<StorageEntryMetadataV16>;
}
/** @name PalletViewFunctionMetadataV16 */
export interface PalletViewFunctionMetadataV16 extends Struct {
readonly id: U8aFixed;
readonly name: Text;
readonly inputs: Vec<RuntimeApiMethodParamMetadataV15>;
readonly output: SiLookupTypeId;
readonly docs: Vec<Text>;
readonly deprecationInfo: ItemDeprecationInfoV16;
}
/** @name PortableType */
export interface PortableType extends PortableTypeV14 {}
@@ -399,7 +501,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 +510,15 @@ export interface RuntimeApiMetadataV15 extends Struct {
readonly docs: Vec<Text>;
}
/** @name RuntimeApiMetadataV16 */
export interface RuntimeApiMetadataV16 extends Struct {
readonly name: Text;
readonly methods: Vec<RuntimeApiMethodMetadataV16>;
readonly docs: Vec<Text>;
readonly version: Compact<u32>;
readonly deprecationInfo: ItemDeprecationInfoV16;
}
/** @name RuntimeApiMethodMetadataV15 */
export interface RuntimeApiMethodMetadataV15 extends Struct {
readonly name: Text;
@@ -416,6 +527,15 @@ export interface RuntimeApiMethodMetadataV15 extends Struct {
readonly docs: Vec<Text>;
}
/** @name RuntimeApiMethodMetadataV16 */
export interface RuntimeApiMethodMetadataV16 extends Struct {
readonly name: Text;
readonly inputs: Vec<RuntimeApiMethodParamMetadataV15>;
readonly output: SiLookupTypeId;
readonly docs: Vec<Text>;
readonly deprecationInfo: ItemDeprecationInfoV16;
}
/** @name RuntimeApiMethodParamMetadataV15 */
export interface RuntimeApiMethodParamMetadataV15 extends Struct {
readonly name: Text;
@@ -433,7 +553,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 +594,16 @@ export interface StorageEntryMetadataV14 extends Struct {
readonly docs: Vec<Text>;
}
/** @name StorageEntryMetadataV16 */
export interface StorageEntryMetadataV16 extends Struct {
readonly name: Text;
readonly modifier: StorageEntryModifierV14;
readonly type: StorageEntryTypeV14;
readonly fallback: Bytes;
readonly docs: Vec<Text>;
readonly deprecationInfo: ItemDeprecationInfoV16;
}
/** @name StorageEntryMetadataV9 */
export interface StorageEntryMetadataV9 extends Struct {
readonly name: Text;
@@ -694,4 +824,26 @@ export interface StorageMetadataV9 extends Struct {
readonly items: Vec<StorageEntryMetadataV9>;
}
/** @name TransactionExtensionMetadataLatest */
export interface TransactionExtensionMetadataLatest extends TransactionExtensionMetadataV16 {}
/** @name TransactionExtensionMetadataV16 */
export interface TransactionExtensionMetadataV16 extends Struct {
readonly identifier: Text;
readonly type: SiLookupTypeId;
readonly implicit: SiLookupTypeId;
}
/** @name VariantDeprecationInfoV16 */
export interface VariantDeprecationInfoV16 extends Enum {
readonly isDummyVariant: boolean;
readonly isDeprecatedWithoutNote: boolean;
readonly isDeprecated: boolean;
readonly asDeprecated: {
readonly note: Text;
readonly since: Option<Text>;
} & Struct;
readonly type: 'DummyVariant' | 'DeprecatedWithoutNote' | 'Deprecated';
}
export type PHANTOM_METADATA = 'metadata';
@@ -0,0 +1,168 @@
// 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<PalletMetadataV16>',
extrinsic: 'ExtrinsicMetadataV16',
apis: 'Vec<RuntimeApiMetadataV16>',
outerEnums: 'OuterEnums15',
custom: 'CustomMetadata15'
},
// ---- Pallet definitions ----
PalletMetadataV16: {
name: 'Text',
storage: 'Option<PalletStorageMetadataV16>',
calls: 'Option<PalletCallMetadataV16>',
events: 'Option<PalletEventMetadataV16>',
constants: 'Vec<PalletConstantMetadataV16>',
errors: 'Option<PalletErrorMetadataV16>',
associatedTypes: 'Vec<PalletAssociatedTypeMetadataV16>',
viewFunctions: 'Vec<PalletViewFunctionMetadataV16>',
index: 'u8',
docs: 'Vec<Text>',
// Deprecation info
deprecationInfo: 'ItemDeprecationInfoV16'
},
PalletStorageMetadataV16: {
prefix: 'Text',
items: 'Vec<StorageEntryMetadataV16>'
},
StorageEntryMetadataV16: {
name: 'Text',
modifier: 'StorageEntryModifierV14',
type: 'StorageEntryTypeV14',
fallback: 'Bytes',
docs: 'Vec<Text>',
deprecationInfo: 'ItemDeprecationInfoV16'
},
ItemDeprecationInfoV16: {
_enum: {
// Item is not deprecated.
NotDeprecated: 'Null',
// Item is fully deprecated without a note.
DeprecatedWithoutNote: 'Null',
// Item is fully 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<Text>'
}
}
},
PalletCallMetadataV16: {
type: 'SiLookupTypeId',
// Deprecation status of the pallet call
deprecationInfo: 'EnumDeprecationInfoV16'
},
// Deprecation information for enums in which specific variants can be deprecated.
// If the map is empty, then nothing is deprecated.
EnumDeprecationInfoV16: 'BTreeMap<u8, VariantDeprecationInfoV16>',
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.
Deprecated: {
// Note explaining the deprecation
note: 'Text',
// Optional value for noting the version when the deprecation occurred.
since: 'Option<Text>'
}
}
},
PalletEventMetadataV16: {
type: 'SiLookupTypeId',
// Deprecation info
deprecationInfo: 'EnumDeprecationInfoV16'
},
PalletConstantMetadataV16: {
name: 'Text',
type: 'SiLookupTypeId',
value: 'Bytes',
docs: 'Vec<Text>',
// Deprecation info
deprecationInfo: 'ItemDeprecationInfoV16'
},
PalletErrorMetadataV16: {
type: 'SiLookupTypeId',
// Deprecation info
deprecationInfo: 'EnumDeprecationInfoV16'
},
PalletAssociatedTypeMetadataV16: {
name: 'Text',
type: 'SiLookupTypeId',
docs: 'Vec<Text>'
},
PalletViewFunctionMetadataV16: {
id: '[u8; 32]',
// Method name.
name: 'Text',
// Method par ameters.
inputs: 'Vec<RuntimeApiMethodParamMetadataV15>',
// Method output.
output: 'SiLookupTypeId',
// Method documentation.
docs: 'Vec<T::String>',
// Deprecation info
deprecationInfo: 'ItemDeprecationInfoV16'
},
// ---- Extrinsic definitions ----
ExtrinsicMetadataV16: {
// Extrinsic versions supported by the runtime.
versions: 'Vec<u8>',
// 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.
//
// For each supported version number, list the indexes, in order, of the extensions used.
transactionExtensionsByVersion: 'BTreeMap<u8, Vec<Compact<u32>>>',
// The transaction extensions in the order they appear in the extrinsic.
transactionExtensions: 'Vec<TransactionExtensionMetadataV16>'
},
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<RuntimeApiMethodMetadataV16>',
docs: 'Vec<Text>',
// Runtime API version.
version: 'Compact<u32>',
// Deprecation info
deprecationInfo: 'ItemDeprecationInfoV16'
},
RuntimeApiMethodMetadataV16: {
name: 'Text',
inputs: 'Vec<RuntimeApiMethodParamMetadataV15>',
output: 'SiLookupTypeId',
docs: 'Vec<Text>',
// Deprecation info
deprecationInfo: 'ItemDeprecationInfoV16'
}
};
@@ -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,7 +16,8 @@ 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 { toLatest } from './v16/toLatest.js';
import { MagicNumber } from './MagicNumber.js';
import { LATEST_VERSION, TO_CALLS_VERSION } from './versions.js';
@@ -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
*/
@@ -34,6 +34,7 @@ interface MetadataJson {
v13: MetadataJsonDef;
v14: MetadataJsonDef;
v15: MetadataJsonDef;
v16: MetadataJsonDef;
}
}
+147
View File
@@ -0,0 +1,147 @@
// Copyright 2017-2025 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
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';
import { objectSpread } from '@polkadot/util';
function palletsFromV15 (registry: Registry, palletV15: PalletMetadataV15): PalletMetadataV16 {
const deprecationInfo: ItemDeprecationInfoV16 = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']);
const associatedTypes: Vec<PalletAssociatedTypeMetadataV16> = registry.createTypeUnsafe('Vec<PalletAssociatedTypeMetadataV16>', [[]]);
const viewFunctions: Vec<PalletAssociatedTypeMetadataV16> = registry.createTypeUnsafe('Vec<PalletViewFunctionMetadataV16>', [[]]);
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,
viewFunctions
})
]);
}
function convertStorage (registry: Registry, storage: PalletStorageMetadataV14): PalletStorageMetadataV16 {
const deprecationInfo: ItemDeprecationInfoV16 = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']);
const items: StorageEntryMetadataV16[] = storage.items.map((item) =>
registry.createTypeUnsafe('StorageEntryMetadataV16', [
objectSpread({}, item, { deprecationInfo })
])
);
return registry.createTypeUnsafe('PalletStorageMetadataV16', [{
items: registry.createTypeUnsafe('Vec<StorageEntryMetadataV16>', [items]),
prefix: storage.prefix
}]);
}
function convertCalls (registry: Registry, calls: PalletCallMetadataV14): PalletCallMetadataV16 {
const deprecationInfo = registry.createTypeUnsafe('EnumDeprecationInfoV16', []);
return registry.createTypeUnsafe('PalletCallMetadataV16', [{
deprecationInfo,
type: calls.type
}]);
}
function convertEvents (registry: Registry, events: PalletEventMetadataV14): PalletEventMetadataV16 {
const deprecationInfo = registry.createTypeUnsafe('EnumDeprecationInfoV16', []);
return registry.createTypeUnsafe('PalletEventMetadataV16', [{
deprecationInfo,
type: events.type
}]);
}
function convertConstants (registry: Registry, constants: Vec<PalletConstantMetadataV14>): Vec<PalletConstantMetadataV16> {
const deprecationInfo: ItemDeprecationInfoV16 = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']);
return registry.createTypeUnsafe('Vec<PalletConstantMetadataV16>', [
constants.map((constant) => registry.createTypeUnsafe('PalletConstantMetadataV16', [
objectSpread({}, constant, { deprecationInfo })
]))]
);
}
function converErrors (registry: Registry, errors: PalletErrorMetadataV14): PalletErrorMetadataV16 {
const deprecationInfo = registry.createTypeUnsafe('EnumDeprecationInfoV16', []);
return registry.createTypeUnsafe('PalletErrorMetadataV16', [{
deprecationInfo,
type: errors.type
}]);
}
function extrinsicFromV15 (registry: Registry, extrinsicV15: ExtrinsicMetadataV15): ExtrinsicMetadataV16 {
const transactionExtensions: TransactionExtensionMetadataV16[] = extrinsicV15.signedExtensions.map(({ additionalSigned, identifier, type }) =>
registry.createTypeUnsafe('TransactionExtensionMetadataV16', [{
identifier,
implict: additionalSigned,
type
}])
);
const indexes = transactionExtensions.map((_, i) =>
registry.createTypeUnsafe('Compact<u32>', [i])
);
const transactionExtensionsByVersion = registry.createTypeUnsafe(
'BTreeMap<u8, Vec<Compact<u32>>>',
[new Map([[registry.createTypeUnsafe('u8', [extrinsicV15.version]), registry.createTypeUnsafe('Vec<Compact<u32>>', [indexes])]])]
);
return registry.createTypeUnsafe('ExtrinsicMetadataV16', [
{
addressType: extrinsicV15.addressType,
callType: extrinsicV15.callType,
signatureType: extrinsicV15.signatureType,
transactionExtensions,
transactionExtensionsByVersion,
versions: [extrinsicV15.version]
}
]);
}
function apisFromV15 (registry: Registry, runtimeApiV15: RuntimeApiMetadataV15): RuntimeApiMetadataV16 {
const deprecationInfo = registry.createTypeUnsafe('ItemDeprecationInfoV16', ['NotDeprecated']);
const methods = runtimeApiV15.methods.map((method) =>
registry.createTypeUnsafe('RuntimeApiMethodMetadataV16',
[objectSpread({}, method, { deprecationInfo })]
)
);
return registry.createTypeUnsafe('RuntimeApiMetadataV16', [
objectSpread({}, runtimeApiV15, {
deprecationInfo,
methods,
version: registry.createTypeUnsafe('Compact<u32>', [0])
})
]);
}
/**
* Convert the Metadata to v16
* @internal
**/
export function toV16 (registry: Registry, v15: MetadataV15, _: number): MetadataV16 {
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({}, v15, {
apis,
extrinsic,
pallets
})
]);
}
@@ -0,0 +1,30 @@
// Copyright 2017-2025 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* 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': {
data: assetHubKusamaData
},
'asset-hub-polkadot': {
data: assetHubPolkadotData
},
kusama: {
data: kusamaData
},
polkadot: {
data: polkadotData
},
substrate: {
data: substrateData
}*/
});
@@ -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;
}
+1 -1
View File
@@ -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,