From 78dbfa46fa00d42d295aa4eb0e4e70635d8804ef Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 4 Mar 2021 08:03:25 +0100 Subject: [PATCH] AccountInfoWithTripleRefCount type & detection (#3228) * AccountInfoWithTripleRefCount * Update naming * build --- packages/api/src/base/util.ts | 20 +++++++++++++------ packages/types-known/src/spec/kusama.ts | 2 +- packages/types-known/src/spec/node.ts | 2 +- packages/types-known/src/spec/polkadot.ts | 2 +- packages/types-known/src/spec/rococo.ts | 2 +- packages/types-known/src/spec/westend.ts | 2 +- packages/types/src/augment/registry.ts | 8 +++++++- .../src/interfaces/system/definitions.ts | 11 +++++++++- packages/types/src/interfaces/system/types.ts | 16 +++++++++++++-- 9 files changed, 50 insertions(+), 15 deletions(-) diff --git a/packages/api/src/base/util.ts b/packages/api/src/base/util.ts index 053d5c5d13..3008c17cb1 100644 --- a/packages/api/src/base/util.ts +++ b/packages/api/src/base/util.ts @@ -10,25 +10,32 @@ import { combineLatest, Observable, of } from '@polkadot/x-rxjs'; import { map, take } from '@polkadot/x-rxjs/operators'; // the order and types needs to map with the all array setup below -type Extracted = [bool | null, bool | null, Releases | null]; +type Extracted = [bool | null, bool | null, bool | null, Releases | null]; type DetectedKeys = keyof Pick; type DetectedValues = keyof InterfaceTypes; interface DetectedTypes extends Record { - AccountInfo: 'AccountInfoWithRefCount' | 'AccountInfoWithProviders', + AccountInfo: 'AccountInfoWithRefCount' | 'AccountInfoWithDualRefCount' | 'AccountInfoWithTripleRefCount', + RefCount: 'u8' | 'u32', ValidatorPrefs: 'ValidatorPrefsWithBlocked' | 'ValidatorPrefsWithCommission'; } -function mapCapabilities ([systemRefcount32, systemRefcountDual, stakingVersion]: Extracted): Partial { +function mapCapabilities ([systemRefcount32, systemRefcountDual, systemRefcountTriple, stakingVersion]: Extracted): Partial { const types: Partial = {}; // AccountInfo - if (systemRefcountDual && systemRefcountDual.isTrue) { - types.AccountInfo = 'AccountInfoWithProviders'; - } else if (systemRefcount32 && systemRefcount32.isTrue) { + if (systemRefcountTriple && systemRefcountTriple.isTrue) { + types.AccountInfo = 'AccountInfoWithTripleRefCount'; + } else if (systemRefcountDual && systemRefcountDual.isTrue) { + types.AccountInfo = 'AccountInfoWithDualRefCount'; + } else { types.AccountInfo = 'AccountInfoWithRefCount'; + + if (!systemRefcount32 || systemRefcount32.isFalse) { + types.RefCount = 'u8'; + } } // ValidatorPrefs @@ -50,6 +57,7 @@ export function detectedCapabilities (api: ApiInterfaceRx, blockHash?: Uint8Arra const all = [ api.query.system?.upgradedToU32RefCount, api.query.system?.upgradedToDualRefCount, + api.query.system?.upgradedToTripleRefCount, api.query.staking?.storageVersion ]; const included = all.map((c) => !!c); diff --git a/packages/types-known/src/spec/kusama.ts b/packages/types-known/src/spec/kusama.ts index 2227cba0dc..071cc5ef3f 100644 --- a/packages/types-known/src/spec/kusama.ts +++ b/packages/types-known/src/spec/kusama.ts @@ -6,7 +6,7 @@ import type { OverrideVersionedType } from '@polkadot/types/types'; const sharedTypes = { - AccountInfo: 'AccountInfoWithProviders', + AccountInfo: 'AccountInfoWithDualRefCount', Address: 'MultiAddress', Keys: 'SessionKeys6', LookupSource: 'MultiAddress', diff --git a/packages/types-known/src/spec/node.ts b/packages/types-known/src/spec/node.ts index d4beb1b9a3..a7a936beb6 100644 --- a/packages/types-known/src/spec/node.ts +++ b/packages/types-known/src/spec/node.ts @@ -18,7 +18,7 @@ const versioned: OverrideVersionedType[] = [ { minmax: [261, undefined], types: { - AccountInfo: 'AccountInfoWithProviders', + AccountInfo: 'AccountInfoWithDualRefCount', Address: 'MultiAddress', LookupSource: 'MultiAddress' } diff --git a/packages/types-known/src/spec/polkadot.ts b/packages/types-known/src/spec/polkadot.ts index 9460b91af9..99ffdccceb 100644 --- a/packages/types-known/src/spec/polkadot.ts +++ b/packages/types-known/src/spec/polkadot.ts @@ -6,7 +6,7 @@ import type { OverrideVersionedType } from '@polkadot/types/types'; const sharedTypes = { - AccountInfo: 'AccountInfoWithProviders', + AccountInfo: 'AccountInfoWithDualRefCount', Address: 'MultiAddress', Keys: 'SessionKeys6', LookupSource: 'MultiAddress', diff --git a/packages/types-known/src/spec/rococo.ts b/packages/types-known/src/spec/rococo.ts index e104fae584..bd934ceaf4 100644 --- a/packages/types-known/src/spec/rococo.ts +++ b/packages/types-known/src/spec/rococo.ts @@ -9,7 +9,7 @@ import type { OverrideVersionedType } from '@polkadot/types/types'; /* eslint-disable sort-keys */ const sharedTypes = { - AccountInfo: 'AccountInfoWithProviders', + AccountInfo: 'AccountInfoWithDualRefCount', Address: 'MultiAddress', FullIdentification: '()', // No staking, only session (as per config) LookupSource: 'MultiAddress', diff --git a/packages/types-known/src/spec/westend.ts b/packages/types-known/src/spec/westend.ts index 24d5f4ba8b..d1a069231f 100644 --- a/packages/types-known/src/spec/westend.ts +++ b/packages/types-known/src/spec/westend.ts @@ -6,7 +6,7 @@ import type { OverrideVersionedType } from '@polkadot/types/types'; const sharedTypes = { - AccountInfo: 'AccountInfoWithProviders', + AccountInfo: 'AccountInfoWithDualRefCount', Address: 'MultiAddress', Keys: 'SessionKeys6', LookupSource: 'MultiAddress', diff --git a/packages/types/src/augment/registry.ts b/packages/types/src/augment/registry.ts index 9ffe650642..6254a804a6 100644 --- a/packages/types/src/augment/registry.ts +++ b/packages/types/src/augment/registry.ts @@ -47,7 +47,7 @@ import type { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, Vouching import type { ActiveEraInfo, CompactAssignments, CompactAssignmentsTo257, CompactScore, CompactScoreCompact, ElectionCompute, ElectionResult, ElectionScore, ElectionSize, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, ExtendedBalance, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, NominatorIndexCompact, OffchainAccuracy, OffchainAccuracyCompact, PhragmenScore, Points, RawSolution, ReadySolution, RewardDestination, RewardPoint, RoundSnapshot, SeatHolder, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SolutionOrSnapshotSize, SolutionSupport, SolutionSupports, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorIndexCompact, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196, ValidatorPrefsWithBlocked, ValidatorPrefsWithCommission, VoteWeight, Voter } from '@polkadot/types/interfaces/staking'; import type { ApiId, KeyValueOption, ReadProof, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/state'; import type { WeightToFeeCoefficient } from '@polkadot/types/interfaces/support'; -import type { AccountInfo, AccountInfoWithProviders, AccountInfoWithRefCount, ApplyExtrinsicResult, BlockLength, BlockWeights, ChainProperties, ChainType, ConsumedWeight, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, DispatchOutcome, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, Health, InvalidTransaction, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, PerDispatchClassU32, PerDispatchClassWeight, PerDispatchClassWeightsPerClass, Phase, RawOrigin, RefCount, RefCountTo259, SyncState, SystemOrigin, TransactionValidityError, UnknownTransaction, WeightPerClass } from '@polkadot/types/interfaces/system'; +import type { AccountInfo, AccountInfoWithDualRefCount, AccountInfoWithProviders, AccountInfoWithRefCount, AccountInfoWithTripleRefCount, ApplyExtrinsicResult, BlockLength, BlockWeights, ChainProperties, ChainType, ConsumedWeight, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, DispatchOutcome, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, Health, InvalidTransaction, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, PerDispatchClassU32, PerDispatchClassWeight, PerDispatchClassWeightsPerClass, Phase, RawOrigin, RefCount, RefCountTo259, SyncState, SystemOrigin, TransactionValidityError, UnknownTransaction, WeightPerClass } from '@polkadot/types/interfaces/system'; import type { Bounty, BountyIndex, BountyStatus, BountyStatusActive, BountyStatusCuratorProposed, BountyStatusPendingPayout, OpenTip, OpenTipFinderTo225, OpenTipTip, OpenTipTo225, TreasuryProposal } from '@polkadot/types/interfaces/treasury'; import type { Multiplier } from '@polkadot/types/interfaces/txpayment'; import type { Multisig, Timepoint } from '@polkadot/types/interfaces/utility'; @@ -152,8 +152,10 @@ declare module '@polkadot/types/types/registry' { 'Option': Option; 'Option': Option; 'Option': Option; + 'Option': Option; 'Option': Option; 'Option': Option; + 'Option': Option; 'Option': Option; 'Option': Option; 'Option': Option; @@ -895,8 +897,10 @@ declare module '@polkadot/types/types/registry' { 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; + 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; + 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; @@ -1638,8 +1642,10 @@ declare module '@polkadot/types/types/registry' { AccountIndex: AccountIndex; AccountIndex64Junction: AccountIndex64Junction; AccountInfo: AccountInfo; + AccountInfoWithDualRefCount: AccountInfoWithDualRefCount; AccountInfoWithProviders: AccountInfoWithProviders; AccountInfoWithRefCount: AccountInfoWithRefCount; + AccountInfoWithTripleRefCount: AccountInfoWithTripleRefCount; AccountKey20Junction: AccountKey20Junction; AccountStatus: AccountStatus; AccountValidity: AccountValidity; diff --git a/packages/types/src/interfaces/system/definitions.ts b/packages/types/src/interfaces/system/definitions.ts index a5de82c14e..374a6f83c7 100644 --- a/packages/types/src/interfaces/system/definitions.ts +++ b/packages/types/src/interfaces/system/definitions.ts @@ -140,12 +140,21 @@ export default { refcount: 'RefCount', data: 'AccountData' }, - AccountInfoWithProviders: { + AccountInfoWithDualRefCount: { nonce: 'Index', consumers: 'RefCount', providers: 'RefCount', data: 'AccountData' }, + // original naming + AccountInfoWithProviders: 'AccountInfoWithDualRefCount', + AccountInfoWithTripleRefCount: { + nonce: 'Index', + consumers: 'RefCount', + providers: 'RefCount', + sufficients: 'RefCount', + data: 'AccountData' + }, ApplyExtrinsicResult: 'Result', BlockLength: { max: 'PerDispatchClassU32' diff --git a/packages/types/src/interfaces/system/types.ts b/packages/types/src/interfaces/system/types.ts index b25eb94776..92d2e18880 100644 --- a/packages/types/src/interfaces/system/types.ts +++ b/packages/types/src/interfaces/system/types.ts @@ -9,14 +9,17 @@ import type { AccountId, BlockNumber, Digest, Hash, Index, Pays, Weight } from ' /** @name AccountInfo */ export interface AccountInfo extends AccountInfoWithRefCount {} -/** @name AccountInfoWithProviders */ -export interface AccountInfoWithProviders extends Struct { +/** @name AccountInfoWithDualRefCount */ +export interface AccountInfoWithDualRefCount extends Struct { readonly nonce: Index; readonly consumers: RefCount; readonly providers: RefCount; readonly data: AccountData; } +/** @name AccountInfoWithProviders */ +export interface AccountInfoWithProviders extends AccountInfoWithDualRefCount {} + /** @name AccountInfoWithRefCount */ export interface AccountInfoWithRefCount extends Struct { readonly nonce: Index; @@ -24,6 +27,15 @@ export interface AccountInfoWithRefCount extends Struct { readonly data: AccountData; } +/** @name AccountInfoWithTripleRefCount */ +export interface AccountInfoWithTripleRefCount extends Struct { + readonly nonce: Index; + readonly consumers: RefCount; + readonly providers: RefCount; + readonly sufficients: RefCount; + readonly data: AccountData; +} + /** @name ApplyExtrinsicResult */ export interface ApplyExtrinsicResult extends Result { readonly isErr: boolean;