Metadata v14 only has combined Map (#3843)
* Metadata v14 only has combined Map * v14 Map conversion de-duped * Substrate Map conversion * v13 tests * Apply suggestions from code review * Housekeeping * v14 bump
This commit is contained in:
+3
-2
@@ -5,8 +5,9 @@
|
||||
Changes:
|
||||
|
||||
- Handle `BitSequence` in `PortableRegistry`
|
||||
- Move all test-support static files into `@polkadot/types-support`
|
||||
- Align static Metadata with latest Substrate
|
||||
- Move all static test support files into `@polkadot/types-support`
|
||||
- Align static Metadata with latest Substrate, Polkadot & Kusama
|
||||
- Adjust v14 Metadata definitions to latest version
|
||||
|
||||
|
||||
## 5.3.2 Aug 3, 2021
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-support#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.8"
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/util": "^7.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/types-support authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as typesInfo } from '@polkadot/types/packageInfo';
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [typesInfo]);
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, []);
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2021 @polkadot/types-support authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Be able to import json in TS
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/types-support authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import metadata from './v13/kusama-hex';
|
||||
|
||||
export default metadata;
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2021 @polkadot/types-support authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import metadata from './v13/polkadot-hex';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// Copyright 2017-2021 @polkadot/types-support authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import metadata from './v13/substrate-hex';
|
||||
|
||||
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 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
File diff suppressed because one or more lines are too long
@@ -499,7 +499,7 @@
|
||||
{
|
||||
"name": "Version",
|
||||
"type": "RuntimeVersion",
|
||||
"value": "0x20706f6c6b61646f743c7061726974792d706f6c6b61646f7400000000822300000000000038df6acb689907609b0300000037e397fc7c91f5e40100000040fe3ad401f8959a05000000d2bc9897eed08f1503000000f78b278be53f454c02000000af2c0297a23e6d3d0100000049eaaf1b548a0cb00100000091d5df18b0d2cf5801000000ed99c5acb25eedf502000000cbca25e39f14238702000000687ad44ad37f03c201000000ab3c0572291feb8b01000000bc9d89904f5b923f0100000037c8bb1350a9a2a80100000007000000",
|
||||
"value": "0x20706f6c6b61646f743c7061726974792d706f6c6b61646f7400000000822300000000000038df6acb689907609b0300000037e397fc7c91f5e40100000040fe3ad401f8959a05000000d2bc9897eed08f1503000000f78b278be53f454c02000000af2c0297a23e6d3d0100000049eaaf1b548a0cb00100000091d5df18b0d2cf5801000000ed99c5acb25eedf503000000cbca25e39f14238702000000687ad44ad37f03c201000000ab3c0572291feb8b01000000bc9d89904f5b923f0100000037c8bb1350a9a2a80100000007000000",
|
||||
"docs": [
|
||||
" Get the chain's current version."
|
||||
]
|
||||
@@ -3306,7 +3306,7 @@
|
||||
],
|
||||
"events": [
|
||||
{
|
||||
"name": "EraPayout",
|
||||
"name": "EraPaid",
|
||||
"args": [
|
||||
"EraIndex",
|
||||
"Balance",
|
||||
@@ -3319,17 +3319,17 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Reward",
|
||||
"name": "Rewarded",
|
||||
"args": [
|
||||
"AccountId",
|
||||
"Balance"
|
||||
],
|
||||
"docs": [
|
||||
" The staker has been rewarded by this amount. \\[stash, amount\\]"
|
||||
" The nominator has been rewarded by this amount. \\[stash, amount\\]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Slash",
|
||||
"name": "Slashed",
|
||||
"args": [
|
||||
"AccountId",
|
||||
"Balance"
|
||||
@@ -3350,7 +3350,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "StakingElection",
|
||||
"name": "StakersElected",
|
||||
"args": [],
|
||||
"docs": [
|
||||
" A new set of stakers was elected."
|
||||
@@ -3416,6 +3416,16 @@
|
||||
" An account has stopped participating as either a validator or nominator.",
|
||||
" \\[stash\\]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "PayoutStarted",
|
||||
"args": [
|
||||
"EraIndex",
|
||||
"AccountId"
|
||||
],
|
||||
"docs": [
|
||||
" The stakers' rewards are getting paid. \\[era_index, validator_stash\\]"
|
||||
]
|
||||
}
|
||||
],
|
||||
"constants": [
|
||||
@@ -7995,6 +8005,13 @@
|
||||
"docs": [
|
||||
" Batch of dispatches completed fully with no error."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ItemCompleted",
|
||||
"args": [],
|
||||
"docs": [
|
||||
" A single item within a Batch of dispatches has completed with no error."
|
||||
]
|
||||
}
|
||||
],
|
||||
"constants": [],
|
||||
|
||||
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
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -36,7 +36,7 @@ import type { ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMeta
|
||||
import type { MmrLeafProof } from '@polkadot/types/interfaces/mmr';
|
||||
import type { StorageKind } from '@polkadot/types/interfaces/offchain';
|
||||
import type { DeferredOffenceOf, Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
|
||||
import type { AbridgedCandidateReceipt, AbridgedHostConfiguration, AbridgedHrmpChannel, AssignmentId, AssignmentKind, AttestedCandidate, AuctionIndex, AuthorityDiscoveryId, AvailabilityBitfield, AvailabilityBitfieldRecord, BackedCandidate, Bidder, BufferedSessionChange, CandidateCommitments, CandidateDescriptor, CandidateHash, CandidateInfo, CandidatePendingAvailability, CandidateReceipt, CollatorId, CollatorSignature, CommittedCandidateReceipt, CoreAssignment, CoreIndex, CoreOccupied, DisputeStatement, DisputeStatementSet, DoubleVoteReport, DownwardMessage, ExplicitDisputeStatement, GlobalValidationData, GlobalValidationSchedule, GroupIndex, HeadData, HostConfiguration, HrmpChannel, HrmpChannelId, HrmpOpenChannelRequest, InboundDownwardMessage, InboundHrmpMessage, InboundHrmpMessages, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, InvalidDisputeStatementKind, LeasePeriod, LeasePeriodOf, LocalValidationData, MessageIngestionType, MessageQueueChain, MessagingStateSnapshot, MessagingStateSnapshotEgressEntry, MultiDisputeStatementSet, NewBidder, OutboundHrmpMessage, ParaGenesisArgs, ParaId, ParaInfo, ParaLifecycle, ParaPastCodeMeta, ParaScheduling, ParaValidatorIndex, ParachainDispatchOrigin, ParachainInherentData, ParachainProposal, ParachainsInherentData, ParathreadClaim, ParathreadClaimQueue, ParathreadEntry, PersistedValidationData, QueuedParathread, RegisteredParachainInfo, RelayBlockNumber, RelayChainBlockNumber, RelayChainHash, RelayHash, Remark, ReplacementTimes, Retriable, Scheduling, ServiceQuality, SessionInfo, SessionInfoValidatorGroup, SignedAvailabilityBitfield, SignedAvailabilityBitfields, SigningContext, SlotRange, Statement, SubId, SystemInherentData, TransientValidationData, UpwardMessage, ValidDisputeStatementKind, ValidationCode, ValidationCodeHash, ValidationData, ValidationDataType, ValidationFunctionParams, ValidatorSignature, ValidityAttestation, VecInboundHrmpMessage, WinnersData, WinnersDataTuple, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
|
||||
import type { AbridgedCandidateReceipt, AbridgedHostConfiguration, AbridgedHrmpChannel, AssignmentId, AssignmentKind, AttestedCandidate, AuctionIndex, AuthorityDiscoveryId, AvailabilityBitfield, AvailabilityBitfieldRecord, BackedCandidate, Bidder, BufferedSessionChange, CandidateCommitments, CandidateDescriptor, CandidateHash, CandidateInfo, CandidatePendingAvailability, CandidateReceipt, CollatorId, CollatorSignature, CommittedCandidateReceipt, CoreAssignment, CoreIndex, CoreOccupied, DisputeStatement, DisputeStatementSet, DoubleVoteReport, DownwardMessage, ExplicitDisputeStatement, GlobalValidationData, GlobalValidationSchedule, GroupIndex, HeadData, HostConfiguration, HrmpChannel, HrmpChannelId, HrmpOpenChannelRequest, InboundDownwardMessage, InboundHrmpMessage, InboundHrmpMessages, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, InvalidDisputeStatementKind, LeasePeriod, LeasePeriodOf, LocalValidationData, MessageIngestionType, MessageQueueChain, MessagingStateSnapshot, MessagingStateSnapshotEgressEntry, MultiDisputeStatementSet, NewBidder, OutboundHrmpMessage, ParaGenesisArgs, ParaId, ParaInfo, ParaLifecycle, ParaPastCodeMeta, ParaScheduling, ParaValidatorIndex, ParachainDispatchOrigin, ParachainInherentData, ParachainProposal, ParachainsInherentData, ParathreadClaim, ParathreadClaimQueue, ParathreadEntry, PersistedValidationData, QueuedParathread, RegisteredParachainInfo, RelayBlockNumber, RelayChainBlockNumber, RelayChainHash, RelayHash, Remark, ReplacementTimes, Retriable, Scheduling, ServiceQuality, SessionInfo, SessionInfoValidatorGroup, SignedAvailabilityBitfield, SignedAvailabilityBitfields, SigningContext, SlotRange, Statement, SubId, SystemInherentData, TransientValidationData, UpgradeGoAhead, UpgradeRestriction, UpwardMessage, ValidDisputeStatementKind, ValidationCode, ValidationCodeHash, ValidationData, ValidationDataType, ValidationFunctionParams, ValidatorSignature, ValidityAttestation, VecInboundHrmpMessage, WinnersData, WinnersDataTuple, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
|
||||
import type { FeeDetails, InclusionFee, RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment';
|
||||
import type { Approvals } from '@polkadot/types/interfaces/poll';
|
||||
import type { ProxyAnnouncement, ProxyDefinition, ProxyType } from '@polkadot/types/interfaces/proxy';
|
||||
@@ -1019,6 +1019,8 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Option<UnlockChunk>': Option<UnlockChunk>;
|
||||
'Option<UnrewardedRelayer>': Option<UnrewardedRelayer>;
|
||||
'Option<UnrewardedRelayersState>': Option<UnrewardedRelayersState>;
|
||||
'Option<UpgradeGoAhead>': Option<UpgradeGoAhead>;
|
||||
'Option<UpgradeRestriction>': Option<UpgradeRestriction>;
|
||||
'Option<UpwardMessage>': Option<UpwardMessage>;
|
||||
'Option<usize>': Option<usize>;
|
||||
'Option<USize>': Option<USize>;
|
||||
@@ -1958,6 +1960,8 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Vec<UnlockChunk>': Vec<UnlockChunk>;
|
||||
'Vec<UnrewardedRelayer>': Vec<UnrewardedRelayer>;
|
||||
'Vec<UnrewardedRelayersState>': Vec<UnrewardedRelayersState>;
|
||||
'Vec<UpgradeGoAhead>': Vec<UpgradeGoAhead>;
|
||||
'Vec<UpgradeRestriction>': Vec<UpgradeRestriction>;
|
||||
'Vec<UpwardMessage>': Vec<UpwardMessage>;
|
||||
'Vec<usize>': Vec<usize>;
|
||||
'Vec<USize>': Vec<USize>;
|
||||
@@ -2897,6 +2901,8 @@ declare module '@polkadot/types/types/registry' {
|
||||
UnlockChunk: UnlockChunk;
|
||||
UnrewardedRelayer: UnrewardedRelayer;
|
||||
UnrewardedRelayersState: UnrewardedRelayersState;
|
||||
UpgradeGoAhead: UpgradeGoAhead;
|
||||
UpgradeRestriction: UpgradeRestriction;
|
||||
UpwardMessage: UpwardMessage;
|
||||
usize: usize;
|
||||
USize: USize;
|
||||
|
||||
@@ -508,22 +508,8 @@ export interface StorageEntryTypeV14 extends Enum {
|
||||
readonly asPlain: SiLookupTypeId;
|
||||
readonly isMap: boolean;
|
||||
readonly asMap: {
|
||||
readonly hasher: StorageHasherV14;
|
||||
readonly key: SiLookupTypeId;
|
||||
readonly value: SiLookupTypeId;
|
||||
} & Struct;
|
||||
readonly isDoubleMap: boolean;
|
||||
readonly asDoubleMap: {
|
||||
readonly hasher: StorageHasherV14;
|
||||
readonly key1: SiLookupTypeId;
|
||||
readonly key2: SiLookupTypeId;
|
||||
readonly value: SiLookupTypeId;
|
||||
readonly key2Hasher: StorageHasherV14;
|
||||
} & Struct;
|
||||
readonly isNMap: boolean;
|
||||
readonly asNMap: {
|
||||
readonly key: SiLookupTypeId;
|
||||
readonly hashers: Vec<StorageHasherV14>;
|
||||
readonly key: SiLookupTypeId;
|
||||
readonly value: SiLookupTypeId;
|
||||
} & Struct;
|
||||
}
|
||||
|
||||
@@ -88,21 +88,8 @@ export const v14: DefinitionsTypes = {
|
||||
_enum: {
|
||||
Plain: 'SiLookupTypeId',
|
||||
Map: {
|
||||
hasher: 'StorageHasherV14',
|
||||
key: 'SiLookupTypeId',
|
||||
value: 'SiLookupTypeId'
|
||||
},
|
||||
DoubleMap: {
|
||||
hasher: 'StorageHasherV14',
|
||||
key1: 'SiLookupTypeId',
|
||||
key2: 'SiLookupTypeId',
|
||||
value: 'SiLookupTypeId',
|
||||
key2Hasher: 'StorageHasherV14'
|
||||
},
|
||||
NMap: {
|
||||
// NOTE: Renamed from "keys"
|
||||
key: 'SiLookupTypeId',
|
||||
hashers: 'Vec<StorageHasherV14>',
|
||||
key: 'SiLookupTypeId', // NOTE: Renamed from "keys"
|
||||
value: 'SiLookupTypeId'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,6 +378,12 @@ export default {
|
||||
codeUpgradeAllowed: 'Option<BlockNumber>',
|
||||
dmqLength: 'u32'
|
||||
},
|
||||
UpgradeGoAhead: {
|
||||
_enum: ['Abort', 'GoAhead']
|
||||
},
|
||||
UpgradeRestriction: {
|
||||
_enum: ['Present']
|
||||
},
|
||||
UpwardMessage: 'Bytes',
|
||||
ValidationFunctionParams: {
|
||||
maxCodeSize: 'u32',
|
||||
|
||||
@@ -615,6 +615,17 @@ export interface TransientValidationData extends Struct {
|
||||
readonly dmqLength: u32;
|
||||
}
|
||||
|
||||
/** @name UpgradeGoAhead */
|
||||
export interface UpgradeGoAhead extends Enum {
|
||||
readonly isAbort: boolean;
|
||||
readonly isGoAhead: boolean;
|
||||
}
|
||||
|
||||
/** @name UpgradeRestriction */
|
||||
export interface UpgradeRestriction extends Enum {
|
||||
readonly isPresent: boolean;
|
||||
}
|
||||
|
||||
/** @name UpwardMessage */
|
||||
export interface UpwardMessage extends Bytes {}
|
||||
|
||||
|
||||
@@ -44,9 +44,9 @@ export function decodeLatestMeta<Modules extends Codec> (registry: Registry, typ
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function toLatest<Modules extends Codec> (registry: Registry, version: number, rpcData: string, withThrow = true): void {
|
||||
export function toLatest<Modules extends Codec> (registry: Registry, version: number, { data }: Check, withThrow = true): void {
|
||||
it(`converts v${version} to latest`, (): void => {
|
||||
const metadata = new Metadata(registry, rpcData);
|
||||
const metadata = new Metadata(registry, data);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
@@ -62,14 +62,14 @@ export function toLatest<Modules extends Codec> (registry: Registry, version: nu
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function defaultValues (registry: Registry, rpcData: string, withThrow = true, withFallbackCheck = false): void {
|
||||
export function defaultValues (registry: Registry, { data, fails = [] }: Check, withThrow = true, withFallbackCheck = false): void {
|
||||
describe('storage with default values', (): void => {
|
||||
const metadata = new Metadata(registry, rpcData);
|
||||
const metadata = new Metadata(registry, data);
|
||||
|
||||
metadata.asLatest.modules.filter(({ storage }): boolean => storage.isSome).forEach((mod): void => {
|
||||
mod.storage.unwrap().items.forEach(({ fallback, modifier, name, type }): void => {
|
||||
metadata.asLatest.modules.filter(({ storage }) => storage.isSome).forEach((m): void => {
|
||||
m.storage.unwrap().items.forEach(({ fallback, modifier, name, type }): void => {
|
||||
const inner = unwrapStorageType(registry, type, modifier.isOptional);
|
||||
const location = `${mod.name.toString()}.${name.toString()}: ${inner}`;
|
||||
const location = `${m.name.toString()}.${name.toString()}: ${inner}`;
|
||||
|
||||
it(location, (): void => {
|
||||
expect((): void => {
|
||||
@@ -84,7 +84,7 @@ export function defaultValues (registry: Registry, rpcData: string, withThrow =
|
||||
} catch (error) {
|
||||
const message = `${location}:: ${(error as Error).message}`;
|
||||
|
||||
if (withThrow) {
|
||||
if (withThrow && !fails.some((f) => location.includes(f))) {
|
||||
throw new Error(message);
|
||||
} else {
|
||||
console.warn(message);
|
||||
@@ -105,9 +105,9 @@ export function testMeta (version: number, matchers: Record<string, Check>, with
|
||||
|
||||
decodeLatestMeta(registry, type, version, matcher);
|
||||
|
||||
toLatest(registry, version, matcher.data);
|
||||
toLatest(registry, version, matcher);
|
||||
|
||||
defaultValues(registry, matcher.data, true, withFallback);
|
||||
defaultValues(registry, matcher, true, withFallback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
export interface Check {
|
||||
compare: Record<string, unknown>;
|
||||
data: string;
|
||||
fails?: string[];
|
||||
types?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import kusamaData from '@polkadot/types-support/metadata/v13/kusama-hex';
|
||||
import kusamaJson from '@polkadot/types-support/metadata/v13/kusama-json.json';
|
||||
import polkadotData from '@polkadot/types-support/metadata/v13/polkadot-hex';
|
||||
import polkadotJson from '@polkadot/types-support/metadata/v13/polkadot-json.json';
|
||||
import substrateData from '@polkadot/types-support/metadata/v13/substrate-hex';
|
||||
@@ -9,6 +11,14 @@ import substrateJson from '@polkadot/types-support/metadata/v13/substrate-json.j
|
||||
import { testMeta } from '../util/testUtil';
|
||||
|
||||
testMeta(13, {
|
||||
kusama: {
|
||||
compare: kusamaJson as Record<string, unknown>,
|
||||
data: kusamaData,
|
||||
fails: [
|
||||
// RawSolution has 24 entries
|
||||
'SignedSubmissionOf'
|
||||
]
|
||||
},
|
||||
polkadot: {
|
||||
compare: polkadotJson as Record<string, unknown>,
|
||||
data: polkadotData
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ErrorMetadataV13, EventMetadataV13, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionMetadataV13, MetadataV13, MetadataV14, ModuleConstantMetadataV13, ModuleMetadataV13, PalletCallMetadataV14, PalletConstantMetadataV14, PalletErrorMetadataV14, PalletEventMetadataV14, PalletMetadataV14, PalletStorageMetadataV14, StorageEntryMetadataV14, StorageEntryTypeV14, StorageMetadataV13 } from '../../interfaces/metadata';
|
||||
import type { ErrorMetadataV13, EventMetadataV13, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionMetadataV13, MetadataV13, MetadataV14, ModuleConstantMetadataV13, ModuleMetadataV13, PalletCallMetadataV14, PalletConstantMetadataV14, PalletErrorMetadataV14, PalletEventMetadataV14, PalletMetadataV14, PalletStorageMetadataV14, StorageEntryMetadataV14, StorageEntryTypeV14, StorageHasherV13, StorageMetadataV13 } from '../../interfaces/metadata';
|
||||
import type { SiVariant } from '../../interfaces/scaleInfo';
|
||||
import type { Text } from '../../primitive/Text';
|
||||
import type { Type } from '../../primitive/Type';
|
||||
@@ -19,6 +19,12 @@ interface TypeSpec {
|
||||
path?: string[];
|
||||
}
|
||||
|
||||
interface MapDef {
|
||||
hashers: StorageHasherV13[];
|
||||
keys: Type[];
|
||||
value: Type;
|
||||
}
|
||||
|
||||
const BOXES = [['<', '>'], ['<', ','], [',', '>'], ['(', ')'], ['(', ','], [',', ','], [',', ')']];
|
||||
|
||||
/**
|
||||
@@ -92,9 +98,9 @@ function setTypeOverride (sectionTypes: OverrideModuleType, types: Type[]): void
|
||||
const orig = type.toString();
|
||||
const alias = Object
|
||||
.entries(sectionTypes)
|
||||
.reduce((result: string, [from, to]) =>
|
||||
BOXES.reduce((result, [one, two]) =>
|
||||
result.replace(`${one}${from}${two}`, `${one}${to}${two}`), result), orig);
|
||||
.reduce((result: string, [src, dst]) =>
|
||||
BOXES.reduce((result, [a, z]) =>
|
||||
result.replace(`${a}${src}${z}`, `${a}${dst}${z}`), result), orig);
|
||||
|
||||
if (orig !== alias) {
|
||||
type.setOverride(alias);
|
||||
@@ -173,8 +179,8 @@ function convertEvents (registry: Registry, types: TypeSpec[], modName: Text, ev
|
||||
|
||||
return registry.createType('SiVariant', {
|
||||
docs,
|
||||
fields: args.map((type) =>
|
||||
registry.createType('SiField', { type: compatType(types, type) })
|
||||
fields: args.map((t) =>
|
||||
registry.createType('SiField', { type: compatType(types, t) })
|
||||
),
|
||||
index,
|
||||
name
|
||||
@@ -186,6 +192,22 @@ function convertEvents (registry: Registry, types: TypeSpec[], modName: Text, ev
|
||||
});
|
||||
}
|
||||
|
||||
function createMapEntry (registry: Registry, sectionTypes: OverrideModuleType, types: TypeSpec[], { hashers, keys, value }: MapDef): StorageEntryTypeV14 {
|
||||
setTypeOverride(sectionTypes, [value, ...keys]);
|
||||
|
||||
return registry.createType('StorageEntryTypeV14', {
|
||||
Map: {
|
||||
hashers,
|
||||
key: types.push({
|
||||
def: {
|
||||
Tuple: keys.map((t) => compatType(types, t))
|
||||
}
|
||||
}) - 1,
|
||||
value: compatType(types, value)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply module-specific storage type overrides (always part of toV14)
|
||||
* @internal
|
||||
@@ -206,48 +228,26 @@ function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix
|
||||
} else if (type.isMap) {
|
||||
const map = type.asMap;
|
||||
|
||||
setTypeOverride(sectionTypes, [map.value, map.key]);
|
||||
|
||||
entryType = registry.createType('StorageEntryTypeV14', {
|
||||
Map: {
|
||||
hasher: map.hasher,
|
||||
key: compatType(types, map.key),
|
||||
value: compatType(types, map.value)
|
||||
}
|
||||
entryType = createMapEntry(registry, sectionTypes, types, {
|
||||
hashers: [map.hasher],
|
||||
keys: [map.key],
|
||||
value: map.value
|
||||
});
|
||||
} else if (type.isDoubleMap) {
|
||||
const dm = type.asDoubleMap;
|
||||
|
||||
setTypeOverride(sectionTypes, [dm.value, dm.key1, dm.key2]);
|
||||
|
||||
entryType = registry.createType('StorageEntryTypeV14', {
|
||||
DoubleMap: {
|
||||
hasher: dm.hasher,
|
||||
key1: compatType(types, dm.key1),
|
||||
key2: compatType(types, dm.key2),
|
||||
key2Hasher: dm.key2Hasher,
|
||||
value: compatType(types, dm.value)
|
||||
}
|
||||
entryType = createMapEntry(registry, sectionTypes, types, {
|
||||
hashers: [dm.hasher, dm.key2Hasher],
|
||||
keys: [dm.key1, dm.key2],
|
||||
value: dm.value
|
||||
});
|
||||
} else {
|
||||
const nm = type.asNMap;
|
||||
|
||||
setTypeOverride(sectionTypes, [nm.value, ...nm.keyVec]);
|
||||
|
||||
const key = types.push({
|
||||
def: {
|
||||
Tuple: nm.keyVec.map((type) =>
|
||||
compatType(types, type)
|
||||
)
|
||||
}
|
||||
}) - 1;
|
||||
|
||||
entryType = registry.createType('StorageEntryTypeV14', {
|
||||
NMap: {
|
||||
hashers: nm.hashers,
|
||||
key,
|
||||
value: compatType(types, nm.value)
|
||||
}
|
||||
entryType = createMapEntry(registry, sectionTypes, types, {
|
||||
hashers: nm.hashers,
|
||||
keys: nm.keyVec,
|
||||
value: nm.value
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ import path from 'path';
|
||||
import kusamaData from '@polkadot/types-support/metadata/v14/kusama-hex';
|
||||
import kusamaJson from '@polkadot/types-support/metadata/v14/kusama-json.json';
|
||||
import kusamaTypes from '@polkadot/types-support/metadata/v14/kusama-types.json';
|
||||
import polkadotData from '@polkadot/types-support/metadata/v14/polkadot-hex';
|
||||
import polkadotJson from '@polkadot/types-support/metadata/v14/polkadot-json.json';
|
||||
import polkadotTypes from '@polkadot/types-support/metadata/v14/polkadot-types.json';
|
||||
import substrateData from '@polkadot/types-support/metadata/v14/substrate-hex';
|
||||
import substrateJson from '@polkadot/types-support/metadata/v14/substrate-json.json';
|
||||
import substrateTypes from '@polkadot/types-support/metadata/v14/substrate-types.json';
|
||||
@@ -83,6 +86,11 @@ testMeta(14, {
|
||||
data: kusamaData,
|
||||
types: kusamaTypes as Record<string, unknown>
|
||||
},
|
||||
polkadot: {
|
||||
compare: polkadotJson as Record<string, unknown>,
|
||||
data: polkadotData,
|
||||
types: polkadotTypes as Record<string, unknown>
|
||||
},
|
||||
substrate: {
|
||||
compare: substrateJson as Record<string, unknown>,
|
||||
data: substrateData,
|
||||
|
||||
Reference in New Issue
Block a user