diff --git a/packages/types/src/augment/registry.ts b/packages/types/src/augment/registry.ts index 024465382a..4227ba08c0 100644 --- a/packages/types/src/augment/registry.ts +++ b/packages/types/src/augment/registry.ts @@ -44,7 +44,7 @@ import type { AccountStatus, AccountValidity } from '@polkadot/types/interfaces/ import type { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery'; import type { RpcMethods } from '@polkadot/types/interfaces/rpc'; import type { AccountId, AccountId20, AccountId32, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, BlockNumberFor, BlockNumberOf, Call, CallHash, CallHashOf, ChangesTrieConfiguration, ChangesTrieSignal, CodecHash, Consensus, ConsensusEngineId, Digest, DigestItem, EncodedJustification, ExtrinsicsWeight, Fixed128, Fixed64, FixedI128, FixedI64, FixedU128, FixedU64, H1024, H128, H160, H2048, H256, H32, H512, H64, Hash, Header, HeaderPartial, I32F32, Index, IndicesLookupSource, Justification, Justifications, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, MultiAddress, MultiSigner, OpaqueCall, Origin, OriginCaller, PalletId, PalletVersion, PalletsOrigin, Pays, PerU16, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, SignedBlockWithJustification, SignedBlockWithJustifications, Slot, StorageData, StorageProof, TransactionInfo, TransactionPriority, TransactionStorageProof, U32F32, ValidatorId, ValidatorIdOf, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime'; -import type { Si0Field, Si0LookupTypeId, Si0Path, Si0Type, Si0TypeDef, Si0TypeDefArray, Si0TypeDefBitSequence, Si0TypeDefCompact, Si0TypeDefComposite, Si0TypeDefPhantom, Si0TypeDefPrimitive, Si0TypeDefSequence, Si0TypeDefTuple, Si0TypeDefVariant, Si0TypeParameter, Si0Variant, SiField, SiLookupTypeId, SiPath, SiType, SiTypeDef, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefPrimitive, SiTypeDefRange, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '@polkadot/types/interfaces/scaleInfo'; +import type { Si0Field, Si0LookupTypeId, Si0Path, Si0Type, Si0TypeDef, Si0TypeDefArray, Si0TypeDefBitSequence, Si0TypeDefCompact, Si0TypeDefComposite, Si0TypeDefPhantom, Si0TypeDefPrimitive, Si0TypeDefSequence, Si0TypeDefTuple, Si0TypeDefVariant, Si0TypeParameter, Si0Variant, SiField, SiLookupTypeId, SiPath, SiType, SiTypeDef, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefPrimitive, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '@polkadot/types/interfaces/scaleInfo'; import type { Period, Priority, SchedulePeriod, SchedulePriority, Scheduled, ScheduledTo254, TaskAddress } from '@polkadot/types/interfaces/scheduler'; import type { BeefyKey, FullIdentification, IdentificationTuple, Keys, MembershipProof, SessionIndex, SessionKeys1, SessionKeys10, SessionKeys10B, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6, SessionKeys6B, SessionKeys7, SessionKeys7B, SessionKeys8, SessionKeys8B, SessionKeys9, SessionKeys9B, ValidatorCount } from '@polkadot/types/interfaces/session'; import type { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society'; @@ -821,7 +821,6 @@ declare module '@polkadot/types/types/registry' { SiTypeDefCompact: SiTypeDefCompact; SiTypeDefComposite: SiTypeDefComposite; SiTypeDefPrimitive: SiTypeDefPrimitive; - SiTypeDefRange: SiTypeDefRange; SiTypeDefSequence: SiTypeDefSequence; SiTypeDefTuple: SiTypeDefTuple; SiTypeDefVariant: SiTypeDefVariant; diff --git a/packages/types/src/generic/PortableRegistry.ts b/packages/types/src/generic/PortableRegistry.ts index 6b5bb9b5af..a6a58fb6a8 100644 --- a/packages/types/src/generic/PortableRegistry.ts +++ b/packages/types/src/generic/PortableRegistry.ts @@ -3,7 +3,7 @@ import type { Vec } from '../codec/Vec'; import type { PortableType } from '../interfaces/metadata'; -import type { SiField, SiLookupTypeId, SiPath, SiType, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefRange, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '../interfaces/scaleInfo'; +import type { SiField, SiLookupTypeId, SiPath, SiType, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '../interfaces/scaleInfo'; import type { Text } from '../primitive/Text'; import type { Type } from '../primitive/Type'; import type { Registry, TypeDef } from '../types'; @@ -258,8 +258,6 @@ export class GenericPortableRegistry extends Struct { typeDef = this.#extractHistoric(lookupIndex, type.def.asHistoricMetaCompat); } else if (type.def.isPrimitive) { typeDef = this.#extractPrimitive(lookupIndex, type); - } else if (type.def.isRange) { - typeDef = this.#extractRange(lookupIndex, type.def.asRange); } else if (type.def.isSequence) { typeDef = this.#extractSequence(lookupIndex, type.def.asSequence); } else if (type.def.isTuple) { @@ -314,11 +312,23 @@ export class GenericPortableRegistry extends Struct { } #extractComposite (lookupIndex: number, { params, path }: SiType, { fields }: SiTypeDefComposite): TypeDef { - if (path.length === 1 && path[0].eq('BTreeMap')) { + const specialVariant = path[0].toString(); + + if (path.length === 1 && specialVariant === 'BTreeMap') { return withTypeString(this.registry, { info: TypeDefInfo.BTreeMap, sub: params.map(({ type }) => this.#createSiDef(type.unwrap())) }); + } else if (['Range', 'RangeInclusive'].includes(specialVariant)) { + return withTypeString(this.registry, { + info: TypeDefInfo.Range, + sub: fields.map(({ name, type }, index) => ({ + name: name.isSome + ? name.unwrap().toString() + : ['start', 'end'][index], + ...this.#createSiDef(type) + })) + }); } return SETS.some((p) => matchParts(p, path)) @@ -454,19 +464,6 @@ export class GenericPortableRegistry extends Struct { }; } - #extractRange (lookupIndex: number, { end, start }: SiTypeDefRange): TypeDef { - // NOTE Currently we don't handle SiTypeDefRange.inclusive - return withTypeString(this.registry, { - info: TypeDefInfo.Range, - lookupIndex, - lookupName: this.#names[lookupIndex], - sub: [ - this.#createSiDef(start), - this.#createSiDef(end) - ] - }); - } - #extractSequence (lookupIndex: number, { type }: SiTypeDefSequence): TypeDef { const sub = this.#createSiDef(type); diff --git a/packages/types/src/interfaces/scaleInfo/definitions.ts b/packages/types/src/interfaces/scaleInfo/definitions.ts index a243915592..a3c354cf48 100644 --- a/packages/types/src/interfaces/scaleInfo/definitions.ts +++ b/packages/types/src/interfaces/scaleInfo/definitions.ts @@ -43,7 +43,6 @@ export default { Primitive: 'SiTypeDefPrimitive', Compact: 'SiTypeDefCompact', BitSequence: 'SiTypeDefBitSequence', - Range: 'SiTypeDefRange', // NOTE: This is specific to the implementation for pre-v14 metadata // compatibility (always keep this as the last entry in the enum) HistoricMetaCompat: 'Type' @@ -66,11 +65,6 @@ export default { SiTypeDefPrimitive: { _enum: ['Bool', 'Char', 'Str', 'U8', 'U16', 'U32', 'U64', 'U128', 'U256', 'I8', 'I16', 'I32', 'I64', 'I128', 'I256'] }, - SiTypeDefRange: { - start: 'SiLookupTypeId', - end: 'SiLookupTypeId', - inclusive: 'bool' - }, SiTypeDefSequence: { type: 'SiLookupTypeId' }, diff --git a/packages/types/src/interfaces/scaleInfo/types.ts b/packages/types/src/interfaces/scaleInfo/types.ts index e73acc00a8..401f67c17f 100644 --- a/packages/types/src/interfaces/scaleInfo/types.ts +++ b/packages/types/src/interfaces/scaleInfo/types.ts @@ -1,7 +1,7 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit /* eslint-disable */ -import type { Compact, Enum, Null, Option, Struct, Text, Type, Vec, bool, u32, u64, u8 } from '@polkadot/types'; +import type { Compact, Enum, Null, Option, Struct, Text, Type, Vec, u32, u64, u8 } from '@polkadot/types'; /** @name Si0Field */ export interface Si0Field extends Struct { @@ -158,8 +158,6 @@ export interface SiTypeDef extends Enum { readonly asCompact: SiTypeDefCompact; readonly isBitSequence: boolean; readonly asBitSequence: SiTypeDefBitSequence; - readonly isRange: boolean; - readonly asRange: SiTypeDefRange; readonly isHistoricMetaCompat: boolean; readonly asHistoricMetaCompat: Type; } @@ -205,13 +203,6 @@ export interface SiTypeDefPrimitive extends Enum { readonly isI256: boolean; } -/** @name SiTypeDefRange */ -export interface SiTypeDefRange extends Struct { - readonly start: SiLookupTypeId; - readonly end: SiLookupTypeId; - readonly inclusive: bool; -} - /** @name SiTypeDefSequence */ export interface SiTypeDefSequence extends Struct { readonly type: SiLookupTypeId;