diff --git a/CHANGELOG.md b/CHANGELOG.md index f523e5c44a..967e7b3971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Changes: - Adjust handling of `Weight` type for V2 structures +- Add alis definitions for `Weight{V1, V2}` (used for type overrides) - Cater for weight v2 (along with v1 pass-through) extrinsics in `api-contract` - Update to latest Substrate, Polkadot & Kusama metadata diff --git a/packages/api-contract/src/base/Contract.ts b/packages/api-contract/src/base/Contract.ts index 89f50b1c6b..1b480ad044 100644 --- a/packages/api-contract/src/base/Contract.ts +++ b/packages/api-contract/src/base/Contract.ts @@ -4,9 +4,9 @@ import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types'; import type { ApiTypes, DecorateMethod } from '@polkadot/api/types'; import type { Bytes } from '@polkadot/types'; -import type { AccountId, ContractExecResult, EventRecord, Weight } from '@polkadot/types/interfaces'; +import type { AccountId, ContractExecResult, EventRecord, Weight, WeightV2 } from '@polkadot/types/interfaces'; import type { ISubmittableResult } from '@polkadot/types/types'; -import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent, WeightAll, WeightV2 } from '../types'; +import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent, WeightAll } from '../types'; import type { ContractCallResult, ContractCallSend, ContractQuery, ContractTx, MapMessageQuery, MapMessageTx } from './types'; import { map } from 'rxjs'; diff --git a/packages/api-contract/src/base/util.ts b/packages/api-contract/src/base/util.ts index 55fcb6f5b2..19e41201e3 100644 --- a/packages/api-contract/src/base/util.ts +++ b/packages/api-contract/src/base/util.ts @@ -4,8 +4,9 @@ import type { SubmittableResult } from '@polkadot/api'; import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types'; import type { ApiTypes } from '@polkadot/api/types'; +import type { WeightV1, WeightV2 } from '@polkadot/types/interfaces'; import type { BN } from '@polkadot/util'; -import type { AbiConstructor, AbiMessage, BlueprintOptions, WeightAll, WeightV2 } from '../types'; +import type { AbiConstructor, AbiMessage, BlueprintOptions, WeightAll } from '../types'; import type { BlueprintDeploy, ContractGeneric } from './types'; import { Bytes } from '@polkadot/types'; @@ -39,7 +40,7 @@ export function encodeSalt (salt: Uint8Array | string | null = randomAsU8a()): U : EMPTY_SALT; } -export function convertWeight (orig: WeightV2 | bigint | string | number | BN): WeightAll { +export function convertWeight (orig: WeightV1 | WeightV2 | bigint | string | number | BN): WeightAll { const refTime = (orig as WeightV2).proofSize ? (orig as WeightV2).refTime.toBn() : bnToBn(orig as BN); diff --git a/packages/api-contract/src/types.ts b/packages/api-contract/src/types.ts index c5b859a41e..5ab721de67 100644 --- a/packages/api-contract/src/types.ts +++ b/packages/api-contract/src/types.ts @@ -4,8 +4,8 @@ import type { ApiBase } from '@polkadot/api/base'; import type { ApiTypes } from '@polkadot/api/types'; import type { Text, u64 } from '@polkadot/types'; -import type { ContractExecResultResult, ContractSelector, StorageDeposit } from '@polkadot/types/interfaces'; -import type { Codec, ICompact, INumber, TypeDef } from '@polkadot/types/types'; +import type { ContractExecResultResult, ContractSelector, StorageDeposit, WeightV2 } from '@polkadot/types/interfaces'; +import type { Codec, TypeDef } from '@polkadot/types/types'; import type { BN } from '@polkadot/util'; import type { Abi } from '.'; @@ -82,11 +82,6 @@ export interface BlueprintOptions extends ContractOptions { salt?: Uint8Array | string | null; } -export interface WeightV2 { - refTime: ICompact; - proofSize: ICompact; -} - export interface WeightAll { v1Weight: BN; v2Weight: { diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index 198a9ead4a..046e818518 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -52,7 +52,7 @@ import type { ProxyAnnouncement, ProxyDefinition, ProxyType } from '@polkadot/ty import type { AccountStatus, AccountValidity } from '@polkadot/types/interfaces/purchase'; import type { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery'; import type { RpcMethods } from '@polkadot/types/interfaces/rpc'; -import type { AccountId, AccountId20, AccountId32, AccountId33, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, BlockNumberFor, BlockNumberOf, Call, CallHash, CallHashOf, ChangesTrieConfiguration, ChangesTrieSignal, CodecHash, Consensus, ConsensusEngineId, CrateVersion, 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, SlotDuration, StorageData, StorageInfo, StorageProof, TransactionInfo, TransactionLongevity, TransactionPriority, TransactionStorageProof, TransactionTag, U32F32, ValidatorId, ValidatorIdOf, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime'; +import type { AccountId, AccountId20, AccountId32, AccountId33, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, BlockNumberFor, BlockNumberOf, Call, CallHash, CallHashOf, ChangesTrieConfiguration, ChangesTrieSignal, CodecHash, Consensus, ConsensusEngineId, CrateVersion, 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, SlotDuration, StorageData, StorageInfo, StorageProof, TransactionInfo, TransactionLongevity, TransactionPriority, TransactionStorageProof, TransactionTag, U32F32, ValidatorId, ValidatorIdOf, Weight, WeightMultiplier, WeightV1, WeightV2 } from '@polkadot/types/interfaces/runtime'; import type { Si0Field, Si0LookupTypeId, Si0Path, Si0Type, Si0TypeDef, Si0TypeDefArray, Si0TypeDefBitSequence, Si0TypeDefCompact, Si0TypeDefComposite, Si0TypeDefPhantom, Si0TypeDefPrimitive, Si0TypeDefSequence, Si0TypeDefTuple, Si0TypeDefVariant, Si0TypeParameter, Si0Variant, Si1Field, Si1LookupTypeId, Si1Path, Si1Type, Si1TypeDef, Si1TypeDefArray, Si1TypeDefBitSequence, Si1TypeDefCompact, Si1TypeDefComposite, Si1TypeDefPrimitive, Si1TypeDefSequence, Si1TypeDefTuple, Si1TypeDefVariant, Si1TypeParameter, Si1Variant, 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'; @@ -1149,6 +1149,8 @@ declare module '@polkadot/types/types/registry' { WeightMultiplier: WeightMultiplier; WeightPerClass: WeightPerClass; WeightToFeeCoefficient: WeightToFeeCoefficient; + WeightV1: WeightV1; + WeightV2: WeightV2; WildFungibility: WildFungibility; WildFungibilityV0: WildFungibilityV0; WildFungibilityV1: WildFungibilityV1; diff --git a/packages/types-known/src/spec/kusama.ts b/packages/types-known/src/spec/kusama.ts index 93e65105e8..f561667792 100644 --- a/packages/types-known/src/spec/kusama.ts +++ b/packages/types-known/src/spec/kusama.ts @@ -16,7 +16,7 @@ const sharedTypes = { ProxyType: { _enum: ['Any', 'NonTransfer', 'Governance', 'Staking', 'IdentityJudgement', 'CancelProxy', 'Auction'] }, - Weight: 'u64' + Weight: 'WeightV1' }; const addrIndicesTypes = { @@ -201,8 +201,17 @@ const versioned: OverrideVersionedType[] = [ }, { // metadata v14 - minmax: [9106, undefined], - types: {} + minmax: [9106, 9299], + types: { + Weight: 'WeightV1' + } + }, + { + // metadata v14 + minmax: [9300, undefined], + types: { + Weight: 'WeightV2' + } } ]; diff --git a/packages/types-known/src/spec/polkadot.ts b/packages/types-known/src/spec/polkadot.ts index 3e272fa365..9e6211b96d 100644 --- a/packages/types-known/src/spec/polkadot.ts +++ b/packages/types-known/src/spec/polkadot.ts @@ -24,7 +24,7 @@ const sharedTypes = { Auction: 7 } }, - Weight: 'u64' + Weight: 'WeightV1' }; const addrAccountIdTypes = { @@ -75,8 +75,17 @@ const versioned: OverrideVersionedType[] = [ }, { // metadata v14 - minmax: [9110, undefined], - types: {} + minmax: [9110, 9299], + types: { + Weight: 'WeightV1' + } + }, + { + // metadata v14 + minmax: [9300, undefined], + types: { + Weight: 'WeightV2' + } } ]; diff --git a/packages/types-known/src/spec/rococo.ts b/packages/types-known/src/spec/rococo.ts index 0f48a4c0a6..c79a724489 100644 --- a/packages/types-known/src/spec/rococo.ts +++ b/packages/types-known/src/spec/rococo.ts @@ -15,7 +15,7 @@ const sharedTypes = { DispatchErrorModule: 'DispatchErrorModuleU8', FullIdentification: '()', // No staking, only session (as per config) Keys: 'SessionKeys7B', - Weight: 'u64' + Weight: 'WeightV1' }; const versioned: OverrideVersionedType[] = [ @@ -49,8 +49,17 @@ const versioned: OverrideVersionedType[] = [ }, { // metadata v14 - minmax: [9106, undefined], - types: {} + minmax: [9106, 9299], + types: { + Weight: 'WeightV1' + } + }, + { + // metadata v14 + minmax: [9300, undefined], + types: { + Weight: 'WeightV2' + } } ]; diff --git a/packages/types-known/src/spec/statemint.ts b/packages/types-known/src/spec/statemint.ts index 3b2b12ff3a..6b878ec178 100644 --- a/packages/types-known/src/spec/statemint.ts +++ b/packages/types-known/src/spec/statemint.ts @@ -22,7 +22,7 @@ const sharedTypes = { 'Staking' ] }, - Weight: 'u64' + Weight: 'WeightV1' }; // these are override types for Statemine, Statemint, Westmint @@ -42,7 +42,9 @@ const versioned: OverrideVersionedType[] = [ { // metadata V14 minmax: [500, undefined], - types: {} + types: { + Weight: 'WeightV1' + } } ]; diff --git a/packages/types-known/src/spec/westend.ts b/packages/types-known/src/spec/westend.ts index 439cd7cf85..1b13900021 100644 --- a/packages/types-known/src/spec/westend.ts +++ b/packages/types-known/src/spec/westend.ts @@ -18,7 +18,7 @@ const sharedTypes = { ProxyType: { _enum: ['Any', 'NonTransfer', 'Staking', 'SudoBalances', 'IdentityJudgement', 'CancelProxy'] }, - Weight: 'u64' + Weight: 'WeightV1' }; const addrAccountIdTypes = { @@ -92,8 +92,17 @@ const versioned: OverrideVersionedType[] = [ }, { // metadata v14 - minmax: [9106, undefined], - types: {} + minmax: [9106, 9299], + types: { + Weight: 'WeightV1' + } + }, + { + // metadata v14 + minmax: [9300, undefined], + types: { + Weight: 'WeightV2' + } } ]; diff --git a/packages/types/src/interfaces/runtime/definitions.ts b/packages/types/src/interfaces/runtime/definitions.ts index fed46ec39e..767548b722 100644 --- a/packages/types/src/interfaces/runtime/definitions.ts +++ b/packages/types/src/interfaces/runtime/definitions.ts @@ -212,7 +212,12 @@ export default { }, ValidatorId: 'AccountId', ValidatorIdOf: 'ValidatorId', - Weight: 'u64', + WeightV1: 'u64', + WeightV2: { + refTime: 'Compact', + proofSize: 'Compact' + }, + Weight: 'WeightV1', WeightMultiplier: 'Fixed64', // digest diff --git a/packages/types/src/interfaces/runtime/types.ts b/packages/types/src/interfaces/runtime/types.ts index 68632ae538..0f2ae07ce4 100644 --- a/packages/types/src/interfaces/runtime/types.ts +++ b/packages/types/src/interfaces/runtime/types.ts @@ -389,9 +389,18 @@ export interface ValidatorId extends AccountId {} export interface ValidatorIdOf extends ValidatorId {} /** @name Weight */ -export interface Weight extends u64 {} +export interface Weight extends WeightV1 {} /** @name WeightMultiplier */ export interface WeightMultiplier extends Fixed64 {} +/** @name WeightV1 */ +export interface WeightV1 extends u64 {} + +/** @name WeightV2 */ +export interface WeightV2 extends Struct { + readonly refTime: Compact; + readonly proofSize: Compact; +} + export type PHANTOM_RUNTIME = 'runtime';