Skip to content

Commit

Permalink
update ledger types
Browse files Browse the repository at this point in the history
  • Loading branch information
TarikGul committed Jan 2, 2024
1 parent 530749c commit 6f026a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
25 changes: 15 additions & 10 deletions src/services/accounts/AccountsStakingPayoutsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { ApiPromise } from '@polkadot/api';
import { ApiDecoration } from '@polkadot/api/types';
import { DeriveEraExposure, DeriveEraExposureNominating } from '@polkadot/api-derive/staking/types';
import { Option, u32 } from '@polkadot/types';
import { BalanceOf, BlockHash, EraIndex, Perbill, StakingLedger } from '@polkadot/types/interfaces';
import { PalletStakingEraRewardPoints } from '@polkadot/types/lookup';
import type { ApiDecoration } from '@polkadot/api/types';
import type { DeriveEraExposure, DeriveEraExposureNominating } from '@polkadot/api-derive/staking/types';
import type { Option, u32 } from '@polkadot/types';
import type { BalanceOf, BlockHash, EraIndex, Perbill, StakingLedger } from '@polkadot/types/interfaces';
import type { PalletStakingEraRewardPoints, PalletStakingStakingLedger } from '@polkadot/types/lookup';
import { CalcPayout } from '@substrate/calc';
import { BadRequest } from 'http-errors';

import { IAccountStakingPayouts, IEraPayouts, IPayout } from '../../types/responses';
import type { IAccountStakingPayouts, IEraPayouts, IPayout } from '../../types/responses';
import { AbstractService } from '../AbstractService';

/**
Expand All @@ -37,7 +37,7 @@ type IErasGeneral = [DeriveEraExposure, PalletStakingEraRewardPoints, Option<Bal
*/
interface ICommissionAndLedger {
commission: Perbill;
validatorLedger?: StakingLedger;
validatorLedger?: PalletStakingStakingLedger;
}

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ export class AccountsStakingPayoutsService extends AbstractService {
deriveErasExposures: DeriveEraExposure[],
): Promise<ICommissionAndLedger[][]> {
// Cache StakingLedger to reduce redundant queries to node
const validatorLedgerCache: { [id: string]: StakingLedger } = {};
const validatorLedgerCache: { [id: string]: PalletStakingStakingLedger } = {};

const allErasCommissions = deriveErasExposures.map((deriveEraExposure, idx) => {
const currEra = idx + startEra;
Expand Down Expand Up @@ -272,7 +272,12 @@ export class AccountsStakingPayoutsService extends AbstractService {
continue;
}
// Check if the reward has already been claimed
const claimed = validatorLedger.claimedRewards.includes(eraIndex);
let claimed: boolean;
if (validatorLedger.legacyClaimedRewards) {
claimed = validatorLedger.legacyClaimedRewards.includes(eraIndex);
} else {
claimed = (validatorLedger as unknown as StakingLedger).claimedRewards.includes(eraIndex);
}
if (unclaimedOnly && claimed) {
continue;
}
Expand Down Expand Up @@ -317,7 +322,7 @@ export class AccountsStakingPayoutsService extends AbstractService {
historicApi: ApiDecoration<'promise'>,
validatorId: string,
era: number,
validatorLedgerCache: { [id: string]: StakingLedger },
validatorLedgerCache: { [id: string]: PalletStakingStakingLedger },
): Promise<ICommissionAndLedger> {
let commission;
let validatorLedger;
Expand Down
7 changes: 4 additions & 3 deletions src/types/responses/AccountStakingInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { RewardDestination, StakingLedger } from '@polkadot/types/interfaces';
import { AccountId } from '@polkadot/types/interfaces/runtime';
import type { RewardDestination } from '@polkadot/types/interfaces';
import type { AccountId } from '@polkadot/types/interfaces/runtime';
import type { PalletStakingStakingLedger } from '@polkadot/types/lookup';

import { IAt } from '.';

Expand All @@ -24,5 +25,5 @@ export interface IAccountStakingInfo {
controller: AccountId;
rewardDestination: RewardDestination;
numSlashingSpans: number;
staking: StakingLedger;
staking: PalletStakingStakingLedger;
}

0 comments on commit 6f026a5

Please sign in to comment.