Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions to metadata v15 (extrinsic details) #5642

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/types/src/interfaces/metadata/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 10 additions & 1 deletion packages/types/src/interfaces/metadata/v15.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SignedExtensionMetadataV14>'
},
PalletMetadataV15: {
name: 'Text',
storage: 'Option<PalletStorageMetadataV14>',
Expand Down Expand Up @@ -38,7 +47,7 @@ export const v15: DefinitionsTypes = {
MetadataV15: {
lookup: 'PortableRegistry',
pallets: 'Vec<PalletMetadataV15>',
extrinsic: 'ExtrinsicMetadataV14',
extrinsic: 'ExtrinsicMetadataV15',
type: 'SiLookupTypeId',
apis: 'Vec<RuntimeApiMetadataV15>'
}
Expand Down
27 changes: 25 additions & 2 deletions packages/types/src/metadata/v14/toV15.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
]);
}