Parsing for latest metadata v15 (#5720)

* Parsing for latest metadata v15

* ExtrinsicMetadataLatest = 15

* ExtrinsicMetadataV14 -> ExtrinsicMetadataV15 conversion

* V15 conversion type unwrap

* Cleanup checks

* Adjust (again)

* Start outerEnums population

* Add Event outer enum extraction

* Adjust expectations
This commit is contained in:
Jaco
2023-08-29 16:15:45 +03:00
committed by GitHub
parent b82bf68954
commit 21425900bb
9 changed files with 15078 additions and 9745 deletions
@@ -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',
@@ -2,9 +2,20 @@
/* eslint-disable */
import type { PortableRegistry } from '@polkadot/types';
import type { Bytes, Enum, Option, Struct, Text, Type, Vec, WrapperOpaque, bool, u8 } from '@polkadot/types-codec';
import type { BTreeMap, Bytes, Enum, Option, Struct, Text, Type, Vec, WrapperOpaque, bool, u8 } from '@polkadot/types-codec';
import type { Si1Field, Si1LookupTypeId, Si1Type, SiLookupTypeId } from '@polkadot/types/interfaces/scaleInfo';
/** @name CustomMetadata15 */
export interface CustomMetadata15 extends Struct {
readonly map: BTreeMap<Text, CustomValueMetadata15>;
}
/** @name CustomValueMetadata15 */
export interface CustomValueMetadata15 extends Struct {
readonly type: SiLookupTypeId;
readonly value: Bytes;
}
/** @name ErrorMetadataLatest */
export interface ErrorMetadataLatest extends ErrorMetadataV14 {}
@@ -67,7 +78,7 @@ export interface EventMetadataV9 extends Struct {
}
/** @name ExtrinsicMetadataLatest */
export interface ExtrinsicMetadataLatest extends ExtrinsicMetadataV14 {}
export interface ExtrinsicMetadataLatest extends ExtrinsicMetadataV15 {}
/** @name ExtrinsicMetadataV11 */
export interface ExtrinsicMetadataV11 extends Struct {
@@ -88,6 +99,16 @@ export interface ExtrinsicMetadataV14 extends Struct {
readonly signedExtensions: Vec<SignedExtensionMetadataV14>;
}
/** @name ExtrinsicMetadataV15 */
export interface ExtrinsicMetadataV15 extends Struct {
readonly version: u8;
readonly addressType: SiLookupTypeId;
readonly callType: SiLookupTypeId;
readonly signatureType: SiLookupTypeId;
readonly extraType: SiLookupTypeId;
readonly signedExtensions: Vec<SignedExtensionMetadataV14>;
}
/** @name FunctionArgumentMetadataLatest */
export interface FunctionArgumentMetadataLatest extends FunctionArgumentMetadataV14 {}
@@ -204,9 +225,11 @@ export interface MetadataV14 extends Struct {
export interface MetadataV15 extends Struct {
readonly lookup: PortableRegistry;
readonly pallets: Vec<PalletMetadataV15>;
readonly extrinsic: ExtrinsicMetadataV14;
readonly extrinsic: ExtrinsicMetadataV15;
readonly type: SiLookupTypeId;
readonly apis: Vec<RuntimeApiMetadataV15>;
readonly outerEnums: OuterEnums15;
readonly custom: CustomMetadata15;
}
/** @name MetadataV9 */
@@ -289,6 +312,13 @@ export interface ModuleMetadataV9 extends Struct {
/** @name OpaqueMetadata */
export interface OpaqueMetadata extends WrapperOpaque<Bytes> {}
/** @name OuterEnums15 */
export interface OuterEnums15 extends Struct {
readonly callType: SiLookupTypeId;
readonly eventType: SiLookupTypeId;
readonly errorType: SiLookupTypeId;
}
/** @name PalletCallMetadataLatest */
export interface PalletCallMetadataLatest extends PalletCallMetadataV14 {}
+24 -2
View File
@@ -8,6 +8,26 @@ import type { DefinitionsTypes } from '../../types/index.js';
export const v15: DefinitionsTypes = {
// new/adjusted in v15
CustomMetadata15: {
map: 'BTreeMap<Text, CustomValueMetadata15>'
},
CustomValueMetadata15: {
type: 'SiLookupTypeId',
value: 'Bytes'
},
ExtrinsicMetadataV15: {
version: 'u8',
addressType: 'SiLookupTypeId',
callType: 'SiLookupTypeId',
signatureType: 'SiLookupTypeId',
extraType: 'SiLookupTypeId',
signedExtensions: 'Vec<SignedExtensionMetadataV14>'
},
OuterEnums15: {
callType: 'SiLookupTypeId',
eventType: 'SiLookupTypeId',
errorType: 'SiLookupTypeId'
},
PalletMetadataV15: {
name: 'Text',
storage: 'Option<PalletStorageMetadataV14>',
@@ -38,8 +58,10 @@ export const v15: DefinitionsTypes = {
MetadataV15: {
lookup: 'PortableRegistry',
pallets: 'Vec<PalletMetadataV15>',
extrinsic: 'ExtrinsicMetadataV14',
extrinsic: 'ExtrinsicMetadataV15',
type: 'SiLookupTypeId',
apis: 'Vec<RuntimeApiMetadataV15>'
apis: 'Vec<RuntimeApiMetadataV15>',
outerEnums: 'OuterEnums15',
custom: 'CustomMetadata15'
}
};
@@ -542,6 +542,13 @@ export class PortableRegistry extends Struct implements ILookup {
return Object.values(this.#names).sort();
}
/**
* @description Returns all the available parameterized types for this chain
**/
public get paramTypes (): TypeInfoParams {
return this.#params;
}
/**
* @description The types of the registry
*/
+26 -1
View File
@@ -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,30 @@ 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]);
// 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.paramTypes.SpRuntimeUncheckedExtrinsic;
return registry.createTypeUnsafe('MetadataV15', [
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)
}])
})
]);
}