Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/services/pallets/PalletsStakingProgressService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { InternalServerError } from 'http-errors';

import { ApiPromiseRegistry } from '../../apiRegistry';
import { sanitizeNumbers } from '../../sanitize/sanitizeNumbers';
import { polkadotRegistry } from '../../test-helpers/registries';
import { polkadotRegistry, polkadotRegistryV1003000 } from '../../test-helpers/registries';
import {
activeEraAt,
blockHash100000,
Expand Down Expand Up @@ -123,23 +123,25 @@ const mockApi = {
} as unknown as ApiPromise;

const unappliedSlashes = {
validator: '5CD2Q2EnKaKvjWza3ufMxaXizBTTDgm9kPB3DCZ4VA9j7Ud6',
validator: '19KYMVrBMbQB4161YiN6jMsqoT6uzKHpsuXNVYR3FBFHrvW',
own: '0',
others: [['5GxDBrTuFgCAN49xrpRFWJiA969R2Ny5NnTa8cSPBh8hWHY9', '6902377436592']],
others: [['15tWLBiy7TTdobAUpTUFeTYJzi94igXDTHC4HuRjjnADgZuw', '6902377436592']],
reporters: [],
payout: '345118871829',
toJSON: function () {
return {
validator: this.validator,
own: this.own,
others: this.others.map(([account, amount]) => ({ account, amount })),
others: this.others.map(([account, amount]) => [account, amount]),
reporters: this.reporters,
payout: this.payout,
};
},
};
const unappliedSlashesEntriesUnappliedSlashes = () => {
return Promise.resolve([['5640', unappliedSlashes]]);
return Promise.resolve([
[{ args: [5640] }, polkadotRegistryV1003000.createType('Option<PalletStakingUnappliedSlash>', unappliedSlashes)],
]);
};

const mockHistoricApiUnappliedSlashes = {
Expand Down
25 changes: 21 additions & 4 deletions src/services/pallets/PalletsStakingProgressService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import { ApiPromise } from '@polkadot/api';
import { ApiDecoration } from '@polkadot/api/types';
import { Option, StorageKey } from '@polkadot/types';
import { BlockHash, EraIndex } from '@polkadot/types/interfaces';
import { PalletStakingAsyncUnappliedSlash } from '@polkadot/types/lookup';
import { AnyJson, ITuple } from '@polkadot/types/types';
import { u32, u64, Vec } from '@polkadot/types-codec';
import BN from 'bn.js';
Expand Down Expand Up @@ -104,7 +106,8 @@ export class PalletsStakingProgressService extends AbstractService {
const [eraElectionStatus, { eraLength, eraProgress, sessionLength, sessionProgress, activeEra }] =
await Promise.all([eraElectionPromise, deriveSessionAndEra]);

const unappliedSlashesAtActiveEra = await historicApi.query.staking.unappliedSlashes.entries();
const unappliedSlashesAtActiveEra: [StorageKey<[u32]>, Option<PalletStakingAsyncUnappliedSlash>][] =
await historicApi.query.staking.unappliedSlashes.entries();

const currentBlockNumber = number.toBn();

Expand All @@ -120,10 +123,24 @@ export class PalletsStakingProgressService extends AbstractService {
nextSessionEstimate: nextSession.toString(10),
unappliedSlashes:
Array.isArray(unappliedSlashesAtActiveEra) && unappliedSlashesAtActiveEra.length > 0
? unappliedSlashesAtActiveEra.map(([_key, slash]) =>
slash && Object.keys(slash).length > 0 ? slash.toJSON() : {},
)
? unappliedSlashesAtActiveEra.flatMap(([key, slashOption]) => {
if (!slashOption || !slashOption.isSome) return [];
const slashes: PalletStakingAsyncUnappliedSlash = slashOption.unwrap();
const era = key.args[0]?.toString();
return Array.isArray(slashes)
? slashes.map((slash: PalletStakingAsyncUnappliedSlash) => ({
era,
...slash.toJSON(),
}))
: [
{
era,
...slashes.toJSON(),
},
];
})
: ([] as AnyJson[]),

validatorSet: validators && validators.length ? validators.map((accountId) => accountId.toString()) : [],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"activeEra": "49",
"forceEra": "NotForcing",
"nextSessionEstimate": "791868",
"unappliedSlashes": [{}],
"unappliedSlashes": [],
"nextActiveEraEstimate": "803868",
"electionStatus": {
"status": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"activeEra": "49",
"forceEra": "NotForcing",
"nextSessionEstimate": "789999",
"unappliedSlashes": [{}],
"unappliedSlashes": [],
"nextActiveEraEstimate": "-20369001",
"electionStatus": {
"status": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"nextSessionEstimate": "791868",
"unappliedSlashes": [
{
"validator": "5CD2Q2EnKaKvjWza3ufMxaXizBTTDgm9kPB3DCZ4VA9j7Ud6",
"era": "5640",
"validator": "19KYMVrBMbQB4161YiN6jMsqoT6uzKHpsuXNVYR3FBFHrvW",
"own": "0",
"others": [
{
[

"account": "5GxDBrTuFgCAN49xrpRFWJiA969R2Ny5NnTa8cSPBh8hWHY9",
"amount": "6902377436592"
}
"15tWLBiy7TTdobAUpTUFeTYJzi94igXDTHC4HuRjjnADgZuw",
"6902377436592"
]
],
"reporters": [],
"payout": "345118871829"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
"nextSessionEstimate": "789999",
"unappliedSlashes": [
{
"validator": "5CD2Q2EnKaKvjWza3ufMxaXizBTTDgm9kPB3DCZ4VA9j7Ud6",
"era": "5640",
"validator": "19KYMVrBMbQB4161YiN6jMsqoT6uzKHpsuXNVYR3FBFHrvW",
"own": "0",
"others": [
{
[

"account": "5GxDBrTuFgCAN49xrpRFWJiA969R2Ny5NnTa8cSPBh8hWHY9",
"amount": "6902377436592"
}
"15tWLBiy7TTdobAUpTUFeTYJzi94igXDTHC4HuRjjnADgZuw",
"6902377436592"
]
],
"reporters": [],
"payout": "345118871829"
Expand Down
Loading