Skip to content

Commit

Permalink
check all eras for points, even if validator wasn't active (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
divdev-source authored Nov 15, 2022
1 parent fe869c6 commit 6a366f6
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ActiveEraInfo,
Balance,
Exposure,
EraRewardPoints,
Nominations,
StakingLedger,
ValidatorPrefs,
Expand Down Expand Up @@ -151,16 +152,16 @@ export async function listPendingPayouts({
continue;
}

// Check they nominated that era
if (await isValidatingInEra(api, stash, e)) {
// Check they received points that era
if (await hasEraPoints(api, stash, e)) {
const payoutStakes = api.tx.staking.payoutStakers(stash, e);
payouts.push(payoutStakes);
}
}

// Check from the last collected era up until current
for (let e = lastEra + 1; e < currEra; e += 1) {
if (await isValidatingInEra(api, stash, e)) {
if (await hasEraPoints(api, stash, e)) {
// Get payouts for each era where payouts have not been claimed
const payoutStakes = api.tx.staking.payoutStakers(stash, e);
payouts.push(payoutStakes);
Expand Down Expand Up @@ -392,6 +393,24 @@ async function isValidatingInEra(
}
}

async function hasEraPoints(
api: ApiPromise,
stash: string,
eraToCheck: number
): Promise<boolean> {
try {
const rewardpoints =
await api.query.staking.erasRewardPoints<EraRewardPoints>(eraToCheck);
let found = false;
rewardpoints.individual.forEach((_record, validator) => {
if (stash === validator.toString()) found = true;
});
return found;
} catch {
return false;
}
}

async function signAndSendTxs(
api: ApiPromise,
payouts: SubmittableExtrinsic<'promise', ISubmittableResult>[],
Expand Down

0 comments on commit 6a366f6

Please sign in to comment.