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:
@@ -41,7 +41,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 { ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, 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, 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, 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 { MmrBatchProof, MmrEncodableOpaqueLeaf, MmrError, MmrHash, MmrLeafBatchProof, MmrLeafIndex, MmrLeafProof, MmrNodeIndex, MmrProof } from '@polkadot/types/interfaces/mmr';
|
||||
import type { NftCollectionId, NftItemId } from '@polkadot/types/interfaces/nfts';
|
||||
import type { NpApiError, NpPoolId } from '@polkadot/types/interfaces/nompools';
|
||||
@@ -324,6 +324,8 @@ declare module '@polkadot/types/types/registry' {
|
||||
CoreState: CoreState;
|
||||
CrateVersion: CrateVersion;
|
||||
CreatedBlock: CreatedBlock;
|
||||
CustomMetadata15: CustomMetadata15;
|
||||
CustomValueMetadata15: CustomValueMetadata15;
|
||||
Data: Data;
|
||||
DeferredOffenceOf: DeferredOffenceOf;
|
||||
DefunctVoter: DefunctVoter;
|
||||
@@ -468,6 +470,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
ExtrinsicMetadataV12: ExtrinsicMetadataV12;
|
||||
ExtrinsicMetadataV13: ExtrinsicMetadataV13;
|
||||
ExtrinsicMetadataV14: ExtrinsicMetadataV14;
|
||||
ExtrinsicMetadataV15: ExtrinsicMetadataV15;
|
||||
ExtrinsicOrHash: ExtrinsicOrHash;
|
||||
ExtrinsicPayload: ExtrinsicPayload;
|
||||
ExtrinsicPayloadUnknown: ExtrinsicPayloadUnknown;
|
||||
@@ -753,6 +756,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
OutboundPayload: OutboundPayload;
|
||||
OutboundStatus: OutboundStatus;
|
||||
Outcome: Outcome;
|
||||
OuterEnums15: OuterEnums15;
|
||||
OverweightIndex: OverweightIndex;
|
||||
Owner: Owner;
|
||||
PageCounter: PageCounter;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -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 {}
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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)
|
||||
}])
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user