Bump to latest Substrate metadata (#5770)

This commit is contained in:
Jaco
2023-12-11 10:25:48 +02:00
committed by GitHub
parent 53f9abe4e2
commit db1a699c0a
20 changed files with 10457 additions and 7210 deletions
+17 -6
View File
@@ -2,8 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { AccountId, Balance, BlockNumber, Call, Hash, PreimageStatus } from '@polkadot/types/interfaces';
import type { FrameSupportPreimagesBounded, PalletPreimageRequestStatus } from '@polkadot/types/lookup';
import type { u128 } from '@polkadot/types';
import type { AccountId, AccountId32, Balance, BlockNumber, Call, Hash, PreimageStatus } from '@polkadot/types/interfaces';
import type { FrameSupportPreimagesBounded, PalletPreimageOldRequestStatus, PalletPreimageRequestStatus } from '@polkadot/types/lookup';
import type { Bytes, Option } from '@polkadot/types-codec';
import type { ITuple } from '@polkadot/types-codec/types';
import type { HexString } from '@polkadot/util/types';
@@ -18,6 +19,16 @@ import { getImageHashBounded } from './util.js';
type PreimageInfo = [Bytes, AccountId, Balance, BlockNumber];
type OldPreimage = ITuple<PreimageInfo>;
type CompatStatusU = PalletPreimageRequestStatus['asUnrequested'] & { deposit: ITuple<[AccountId32, u128]> };
type CompatStatusR = PalletPreimageRequestStatus['asRequested'] & { deposit: Option<ITuple<[AccountId32, u128]>> };
function getUnrequestedTicket (status: PalletPreimageRequestStatus['asUnrequested']): [AccountId32, u128] {
return status.ticket || (status as CompatStatusU).deposit;
}
function getRequestedTicket (status: PalletPreimageRequestStatus['asRequested']): [AccountId32, u128] {
return (status.maybeTicket || (status as CompatStatusR).deposit).unwrapOrDefault();
}
function isDemocracyPreimage (api: DeriveApi, imageOpt: Option<OldPreimage> | Option<PreimageStatus>): imageOpt is Option<PreimageStatus> {
return !!imageOpt && !api.query.democracy['dispatchQueue'];
@@ -55,14 +66,14 @@ function parseDemocracy (api: DeriveApi, imageOpt: Option<OldPreimage> | Option<
return constructProposal(api, imageOpt.unwrap());
}
function parseImage (api: DeriveApi, [proposalHash, status, bytes]: [HexString, PalletPreimageRequestStatus | null, Bytes | null]): DeriveProposalImage | undefined {
function parseImage (api: DeriveApi, [proposalHash, status, bytes]: [HexString, PalletPreimageRequestStatus | PalletPreimageOldRequestStatus | null, Bytes | null]): DeriveProposalImage | undefined {
if (!status) {
return undefined;
}
const [proposer, balance] = status.isUnrequested
? status.asUnrequested.deposit
: status.asRequested.deposit.unwrapOrDefault();
? getUnrequestedTicket((status as PalletPreimageRequestStatus).asUnrequested)
: getRequestedTicket((status as PalletPreimageRequestStatus).asRequested);
let proposal: Call | undefined;
if (bytes) {
@@ -112,7 +123,7 @@ function getImages (api: DeriveApi, bounded: (FrameSupportPreimagesBounded | Uin
let ptr = -1;
return statuses
.map((s, i): [HexString, PalletPreimageRequestStatus | null, Bytes | null] =>
.map((s, i): [HexString, PalletPreimageRequestStatus | PalletPreimageOldRequestStatus | null, Bytes | null] =>
s
? [hashes[i], s, optBytes[++ptr].unwrapOr(null)]
: [hashes[i], null, null]
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { u32, Vec } from '@polkadot/types';
import type { AccountId, EraIndex } from '@polkadot/types/interfaces';
import type { PalletStakingStakingLedger } from '@polkadot/types/lookup';
import type { BN } from '@polkadot/util';
@@ -16,6 +17,16 @@ import { firstMemo, memo } from '../util/index.js';
type ErasResult = [DeriveEraPoints[], DeriveEraPrefs[], DeriveEraRewards[]];
// handle compatibility between generations of structures
function extractCompatRewards (ledger?: PalletStakingStakingLedger): u32[] {
return ledger
? (
ledger.legacyClaimedRewards ||
(ledger as PalletStakingStakingLedger & { claimedRewards: Vec<u32> }).claimedRewards
)
: [];
}
function parseRewards (api: DeriveApi, stashId: AccountId, [erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] {
return exposures.map(({ era, isEmpty, isValidator, nominating, validators: eraValidators }): DeriveStakerReward => {
const { eraPoints, validators: allValPoints } = erasPoints.find((p) => p.era.eq(era)) || { eraPoints: BN_ZERO, validators: {} as DeriveEraValPoints };
@@ -97,7 +108,7 @@ function removeClaimed (validators: string[], queryValidators: DeriveStakingQuer
if (index !== -1) {
const valLedger = queryValidators[index].stakingLedger;
if (valLedger?.claimedRewards.some((e) => reward.era.eq(e))) {
if (extractCompatRewards(valLedger).some((e) => reward.era.eq(e))) {
rm.push(validatorId);
}
}
@@ -109,7 +120,7 @@ function removeClaimed (validators: string[], queryValidators: DeriveStakingQuer
}
function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][], { rewards, stakingLedger }: { rewards: DeriveStakerReward[]; stakingLedger: PalletStakingStakingLedger }): DeriveStakerReward[] {
const filter = eras.filter((e) => !stakingLedger.claimedRewards.some((s) => s.eq(e)));
const filter = eras.filter((e) => !extractCompatRewards(stakingLedger).some((s) => s.eq(e)));
const validators = valInfo.map(([v]) => v);
const queryValidators = valInfo.map(([, q]) => q);