Add Weight{V1, V2} aliases (#5257)

This commit is contained in:
Jaco
2022-10-04 08:51:38 +03:00
committed by GitHub
parent ed33850c62
commit 26d1d0d695
12 changed files with 79 additions and 28 deletions
+1
View File
@@ -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
+2 -2
View File
@@ -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';
+3 -2
View File
@@ -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);
+2 -7
View File
@@ -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<INumber>;
proofSize: ICompact<INumber>;
}
export interface WeightAll {
v1Weight: BN;
v2Weight: {
@@ -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;
+12 -3
View File
@@ -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'
}
}
];
+12 -3
View File
@@ -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'
}
}
];
+12 -3
View File
@@ -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'
}
}
];
+4 -2
View File
@@ -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'
}
}
];
+12 -3
View File
@@ -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'
}
}
];
@@ -212,7 +212,12 @@ export default {
},
ValidatorId: 'AccountId',
ValidatorIdOf: 'ValidatorId',
Weight: 'u64',
WeightV1: 'u64',
WeightV2: {
refTime: 'Compact<u64>',
proofSize: 'Compact<u64>'
},
Weight: 'WeightV1',
WeightMultiplier: 'Fixed64',
// digest
+10 -1
View File
@@ -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<u64>;
readonly proofSize: Compact<u64>;
}
export type PHANTOM_RUNTIME = 'runtime';