From 70d3e59e14b227dbacdaa0d260e8ed3a9d427d3c Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 12 May 2023 12:46:52 +0300 Subject: [PATCH] Extensions to metadata v15 (extrinsic details) --- .../src/interfaces/metadata/definitions.ts | 2 +- packages/types/src/interfaces/metadata/v15.ts | 11 +++++++- packages/types/src/metadata/v14/toV15.ts | 27 +++++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/types/src/interfaces/metadata/definitions.ts b/packages/types/src/interfaces/metadata/definitions.ts index 7463c0d97247..e248a18df985 100644 --- a/packages/types/src/interfaces/metadata/definitions.ts +++ b/packages/types/src/interfaces/metadata/definitions.ts @@ -36,7 +36,7 @@ export default { // hence latest for most pointing to the previous V14 ErrorMetadataLatest: 'ErrorMetadataV14', EventMetadataLatest: 'EventMetadataV14', - ExtrinsicMetadataLatest: 'ExtrinsicMetadataV14', + ExtrinsicMetadataLatest: 'ExtrinsicMetadataV15', FunctionArgumentMetadataLatest: 'FunctionArgumentMetadataV14', FunctionMetadataLatest: 'FunctionMetadataV14', MetadataLatest: 'MetadataV15', diff --git a/packages/types/src/interfaces/metadata/v15.ts b/packages/types/src/interfaces/metadata/v15.ts index 28fcc3bf41a7..9fc5d9b5df4e 100644 --- a/packages/types/src/interfaces/metadata/v15.ts +++ b/packages/types/src/interfaces/metadata/v15.ts @@ -8,6 +8,15 @@ import type { DefinitionsTypes } from '../../types/index.js'; export const v15: DefinitionsTypes = { // new/adjusted in v15 + ExtrinsicMetadataV15: { + type: 'SiLookupTypeId', + version: 'u8', + addressType: 'SiLookupTypeId', + callType: 'SiLookupTypeId', + signatureType: 'SiLookupTypeId', + extraType: 'SiLookupTypeId', + signedExtensions: 'Vec' + }, PalletMetadataV15: { name: 'Text', storage: 'Option', @@ -38,7 +47,7 @@ export const v15: DefinitionsTypes = { MetadataV15: { lookup: 'PortableRegistry', pallets: 'Vec', - extrinsic: 'ExtrinsicMetadataV14', + extrinsic: 'ExtrinsicMetadataV15', type: 'SiLookupTypeId', apis: 'Vec' } diff --git a/packages/types/src/metadata/v14/toV15.ts b/packages/types/src/metadata/v14/toV15.ts index 61c9b28b8ddd..fd62590a29b3 100644 --- a/packages/types/src/metadata/v14/toV15.ts +++ b/packages/types/src/metadata/v14/toV15.ts @@ -4,6 +4,8 @@ import type { MetadataV14, MetadataV15 } from '../../interfaces/metadata/index.js'; import type { Registry } from '../../types/index.js'; +import { objectSpread } from '@polkadot/util'; + /** * Convert the Metadata to v15 * @internal @@ -14,7 +16,28 @@ export function toV15 (registry: Registry, v14: MetadataV14, _: number): Metadat // 1. The top-level apis entry - it is assumed that in usage we would // just check for all-empty (like this would construct) // 2. A docs param on the pallet itself + // 3. Additional extrinsic parameters // - // A straight conversion with createTypeUndafe magic fills in details - return registry.createTypeUnsafe('MetadataV15', [v14]); + // A straight conversion with createTypeUnsafe magic fills in details + + // We need the UncheckedExtrinsic to extract the types, at least for v14 + // which does have these details embedded (previous-gen won't populate) + const unchecked = v14.lookup.types.find(({ type: { path } }) => + path.join('::') === 'sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic' + ); + + return registry.createTypeUnsafe('MetadataV15', [ + unchecked + ? objectSpread({}, v14, { + extrinsic: registry.createTypeUnsafe('ExtrinsicMetadataV15', [ + objectSpread({}, v14.extrinsic, { + addressType: unchecked.type.params[0], + callType: unchecked.type.params[1], + extraType: unchecked.type.params[3], + signatureType: unchecked.type.params[2] + }) + ]) + }) + : v14 + ]); }