Lazy reaping types & updates (#1914)

* Lazy reaping types & updates

* system.account queries

* AccountInfo -> ContractAccountInfo tests
This commit is contained in:
Jaco Greeff
2020-02-21 12:37:17 +01:00
committed by GitHub
parent cb175b4bde
commit 85ec141b56
12 changed files with 76 additions and 25 deletions
+11 -5
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountData, AccountIndex, Address, Balance, Index } from '@polkadot/types/interfaces';
import { AccountId, AccountData, AccountIndex, AccountInfo, Address, Balance, Index } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import { DerivedBalancesAccount } from '../types';
@@ -52,10 +52,16 @@ function queryBalancesAccount (api: ApiInterfaceRx, accountId: AccountId): Obser
}
function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<Result> {
return api.query.system.account<ITuple<[Index, AccountData]>>(accountId).pipe(
map(([accountNonce, { free, reserved, miscFrozen, feeFrozen }]): Result =>
[free, reserved, feeFrozen, miscFrozen, accountNonce]
)
// AccountInfo is current, support old, eg. Edgeware
return api.query.system.account<AccountInfo | ITuple<[Index, AccountData]>>(accountId).pipe(
map((infoOrTuple): Result => {
const { free, reserved, miscFrozen, feeFrozen } = (infoOrTuple as AccountInfo).nonce
? (infoOrTuple as AccountInfo).data
: (infoOrTuple as [Index, AccountData])[1];
const accountNonce = (infoOrTuple as AccountInfo).nonce || (infoOrTuple as [Index, AccountData])[0];
return [free, reserved, feeFrozen, miscFrozen, accountNonce];
})
);
}
@@ -2879,7 +2879,7 @@
"type": {
"Map": {
"key": "AccountId",
"value": "AccountInfo",
"value": "ContractAccountInfo",
"linked": false
}
},
@@ -2982,7 +2982,7 @@
"type": {
"Map": {
"key": "AccountId",
"value": "AccountInfo",
"value": "ContractAccountInfo",
"linked": false
}
},
+1 -1
View File
@@ -95,7 +95,7 @@ export function createImports (importDefinitions: Record<string, object>, { type
Object.keys(moduleDef.types).forEach((type): void => {
if (typeToModule[type]) {
throw new Error(`Duplicated type: ${type}. Modules: ${name}, ${typeToModule[type]}`);
throw new Error(`Duplicated type: ${type}, found in: ${name}, ${typeToModule[type]}`);
}
typeToModule[type] = name;
+16 -6
View File
@@ -11,8 +11,8 @@ import { AccountData, BalanceLock, BalanceLockTo212, Reasons, VestingSchedule, W
import { MemberCount, ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { AliveContractInfo, CodeHash, ContractCallRequest, ContractExecResult, ContractExecResultSuccess, ContractInfo, ContractStorageKey, Gas, PrefabWasmModule, PrefabWasmModuleReserved, Schedule, ScheduleTo212, SeedOf, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts';
import { Conviction, PropIndex, Proposal, ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
import { AccountInfo, Amount, AssetOf, InherentOfflineReport, LockPeriods, NewAccountOutcome, OpaqueKey, SessionKey } from '@polkadot/types/interfaces/deprecated';
import { Conviction, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
import { Amount, AssetOf, ContractAccountInfo, InherentOfflineReport, LockPeriods, NewAccountOutcome, OpaqueKey, SessionKey } from '@polkadot/types/interfaces/deprecated';
import { ApprovalFlag, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } from '@polkadot/types/interfaces/elections';
import { CreatedBlock, ImportedAux } from '@polkadot/types/interfaces/engine';
import { Account, Log } from '@polkadot/types/interfaces/evm';
@@ -25,7 +25,7 @@ import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recov
import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6 } from '@polkadot/types/interfaces/session';
import { Bid, BidKind, BidKindVouch, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
import { CompactAssignments, ElectionCompute, ElectionResult, ElectionStatus, EraIndex, EraPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, PhragmenScore, Points, RewardDestination, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
import { DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Key, Phase } from '@polkadot/types/interfaces/system';
import { AccountInfo, DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Key, Phase, RefCount } from '@polkadot/types/interfaces/system';
import { OpenTip, OpenTipFinder, OpenTipTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
import { Multisig, Timepoint } from '@polkadot/types/interfaces/utility';
@@ -490,6 +490,9 @@ export interface InterfaceRegistry {
Proposal: Proposal;
'Option<Proposal>': Option<Proposal>;
'Vec<Proposal>': Vec<Proposal>;
ProxyState: ProxyState;
'Option<ProxyState>': Option<ProxyState>;
'Vec<ProxyState>': Vec<ProxyState>;
ReferendumIndex: ReferendumIndex;
'Compact<ReferendumIndex>': Compact<ReferendumIndex>;
'Option<ReferendumIndex>': Option<ReferendumIndex>;
@@ -507,9 +510,9 @@ export interface InterfaceRegistry {
'Compact<AssetOf>': Compact<AssetOf>;
'Option<AssetOf>': Option<AssetOf>;
'Vec<AssetOf>': Vec<AssetOf>;
AccountInfo: AccountInfo;
'Option<AccountInfo>': Option<AccountInfo>;
'Vec<AccountInfo>': Vec<AccountInfo>;
ContractAccountInfo: ContractAccountInfo;
'Option<ContractAccountInfo>': Option<ContractAccountInfo>;
'Vec<ContractAccountInfo>': Vec<ContractAccountInfo>;
LockPeriods: LockPeriods;
'Option<LockPeriods>': Option<LockPeriods>;
'Vec<LockPeriods>': Vec<LockPeriods>;
@@ -812,6 +815,9 @@ export interface InterfaceRegistry {
ValidatorPrefsTo145: ValidatorPrefsTo145;
'Option<ValidatorPrefsTo145>': Option<ValidatorPrefsTo145>;
'Vec<ValidatorPrefsTo145>': Vec<ValidatorPrefsTo145>;
AccountInfo: AccountInfo;
'Option<AccountInfo>': Option<AccountInfo>;
'Vec<AccountInfo>': Vec<AccountInfo>;
DigestOf: DigestOf;
'Option<DigestOf>': Option<DigestOf>;
'Vec<DigestOf>': Vec<DigestOf>;
@@ -855,6 +861,10 @@ export interface InterfaceRegistry {
Phase: Phase;
'Option<Phase>': Option<Phase>;
'Vec<Phase>': Vec<Phase>;
RefCount: RefCount;
'Compact<RefCount>': Compact<RefCount>;
'Option<RefCount>': Option<RefCount>;
'Vec<RefCount>': Vec<RefCount>;
OpenTipFinder: OpenTipFinder;
'Option<OpenTipFinder>': Option<OpenTipFinder>;
'Vec<OpenTipFinder>': Vec<OpenTipFinder>;
@@ -24,6 +24,10 @@ export default {
},
PropIndex: 'u32',
Proposal: 'Call',
ProxyState: {
Open: 'AccountId',
Active: 'AccountId'
},
ReferendumIndex: 'u32',
ReferendumInfo: {
end: 'BlockNumber',
@@ -3,7 +3,7 @@
import { Enum, Struct } from '@polkadot/types/codec';
import { u32 } from '@polkadot/types/primitive';
import { BlockNumber, Call, Hash } from '@polkadot/types/interfaces/runtime';
import { AccountId, BlockNumber, Call, Hash } from '@polkadot/types/interfaces/runtime';
import { VoteThreshold } from '@polkadot/types/interfaces/elections';
/** @name Conviction */
@@ -23,6 +23,12 @@ export interface PropIndex extends u32 {}
/** @name Proposal */
export interface Proposal extends Call {}
/** @name ProxyState */
export interface ProxyState extends Struct {
readonly Open: AccountId;
readonly Active: AccountId;
}
/** @name ReferendumIndex */
export interface ReferendumIndex extends u32 {}
@@ -14,12 +14,14 @@ export default {
Amount: 'Balance',
AssetOf: 'u32',
// Metadata v3
// Metadata v2
// :: contracts
AccountInfo: {
ContractAccountInfo: {
trieId: 'Bytes',
currentMemStored: 'u64'
},
// Metadata v3
// :: democracy
LockPeriods: 'i8',
@@ -6,18 +6,18 @@ import { Enum, Struct } from '@polkadot/types/codec';
import { Bytes, i8, u32, u64 } from '@polkadot/types/primitive';
import { AccountId, Balance } from '@polkadot/types/interfaces/runtime';
/** @name AccountInfo */
export interface AccountInfo extends Struct {
readonly trieId: Bytes;
readonly currentMemStored: u64;
}
/** @name Amount */
export interface Amount extends Balance {}
/** @name AssetOf */
export interface AssetOf extends u32 {}
/** @name ContractAccountInfo */
export interface ContractAccountInfo extends Struct {
readonly trieId: Bytes;
readonly currentMemStored: u64;
}
/** @name InherentOfflineReport */
export interface InherentOfflineReport extends ITuple<[]> {}
@@ -4,6 +4,11 @@
export default {
types: {
AccountInfo: {
nonce: 'Index',
refcount: 'RefCount',
data: 'AccountData'
},
DigestOf: 'Digest',
DispatchError: {
_enum: {
@@ -42,6 +47,7 @@ export default {
ApplyExtrinsic: 'u32',
Finalization: 'Null'
}
}
},
RefCount: 'u8'
}
};
+12 -1
View File
@@ -5,7 +5,15 @@ import { ITuple } from '@polkadot/types/types';
import { Enum, Option, Result, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
import { GenericEvent } from '@polkadot/types/generic';
import { Bytes, Text, u32, u8 } from '@polkadot/types/primitive';
import { Digest, Hash } from '@polkadot/types/interfaces/runtime';
import { Digest, Hash, Index } from '@polkadot/types/interfaces/runtime';
import { AccountData } from '@polkadot/types/interfaces/balances';
/** @name AccountInfo */
export interface AccountInfo extends Struct {
readonly nonce: Index;
readonly refcount: RefCount;
readonly data: AccountData;
}
/** @name DigestOf */
export interface DigestOf extends Digest {}
@@ -81,3 +89,6 @@ export interface Phase extends Enum {
readonly asApplyExtrinsic: u32;
readonly isFinalization: boolean;
}
/** @name RefCount */
export interface RefCount extends u8 {}
+6
View File
@@ -6,6 +6,12 @@ import { OverrideModuleType, OverrideVersionedType } from './types';
// type overrides for modules (where duplication between modules exist)
const TYPES_MODULES: Record<string, OverrideModuleType> = {
// old metadata & naming
contract: {
// v2 & v3
AccountInfo: 'ContractAccountInfo'
},
// current from here on
contracts: {
StorageKey: 'ContractStorageKey'
},