From 9cf02f7345ba72ebbf26e6dc88d083b4689e7560 Mon Sep 17 00:00:00 2001 From: tarikgul Date: Fri, 29 Oct 2021 12:10:49 -0400 Subject: [PATCH 1/2] add historicApi to staking-info --- .../AccountsStakingInfoService.spec.ts | 25 +++++++++++-------- .../accounts/AccountsStakingInfoService.ts | 9 ++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/services/accounts/AccountsStakingInfoService.spec.ts b/src/services/accounts/AccountsStakingInfoService.spec.ts index 9261e9e81..c8229f2cb 100644 --- a/src/services/accounts/AccountsStakingInfoService.spec.ts +++ b/src/services/accounts/AccountsStakingInfoService.spec.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { ApiPromise } from '@polkadot/api'; +import { ApiDecoration } from '@polkadot/api/types'; import { Option } from '@polkadot/types'; import { AccountId, Hash, StakingLedger } from '@polkadot/types/interfaces'; import { BadRequest, InternalServerError } from 'http-errors'; @@ -43,16 +44,20 @@ const payeeAt = (_hash: Hash, _address: string) => const slashingSpansAt = (_hash: Hash, _address: string) => Promise.resolve().then(() => polkadotRegistry.createType('SlashingSpans')); -const mockApi = { - ...defaultMockApi, +const historicApi = { query: { staking: { - bonded: { at: bondedAt }, - ledger: { at: ledgerAt }, - payee: { at: payeeAt }, - slashingSpans: { at: slashingSpansAt }, + bonded: bondedAt, + ledger: ledgerAt, + payee: payeeAt, + slashingSpans: slashingSpansAt, }, }, +} as unknown as ApiDecoration<'promise'> + +const mockApi = { + ...defaultMockApi, + at: (_hash: Hash) => historicApi, } as unknown as ApiPromise; const accountStakingInfoService = new AccountsStakingInfoService(mockApi); @@ -71,7 +76,7 @@ describe('AccountsStakingInfoService', () => { }); it('throws a 400 when the given address is not a stash', async () => { - (mockApi.query.staking.bonded as any).at = () => + (historicApi.query.staking.bonded as any) = () => Promise.resolve().then(() => polkadotRegistry.createType('Option', null) ); @@ -85,11 +90,11 @@ describe('AccountsStakingInfoService', () => { new BadRequest('The address NotStash is not a stash address.') ); - (mockApi.query.staking.bonded as any).at = bondedAt; + (historicApi.query.staking.bonded as any) = bondedAt; }); it('throws a 404 when the staking ledger cannot be found', async () => { - (mockApi.query.staking.ledger as any).at = () => + (historicApi.query.staking.ledger as any) = () => Promise.resolve().then(() => polkadotRegistry.createType('Option', null) ); @@ -105,7 +110,7 @@ describe('AccountsStakingInfoService', () => { ) ); - (mockApi.query.staking.ledger as any).at = ledgerAt; + (historicApi.query.staking.ledger as any) = ledgerAt; }); }); }); diff --git a/src/services/accounts/AccountsStakingInfoService.ts b/src/services/accounts/AccountsStakingInfoService.ts index 70a7c7a48..c8e2e3aed 100644 --- a/src/services/accounts/AccountsStakingInfoService.ts +++ b/src/services/accounts/AccountsStakingInfoService.ts @@ -16,10 +16,11 @@ export class AccountsStakingInfoService extends AbstractService { stash: string ): Promise { const { api } = this; + const historicApi = await api.at(hash); const [header, controllerOption] = await Promise.all([ api.rpc.chain.getHeader(hash), - api.query.staking.bonded.at(hash, stash), // Option representing the controller + historicApi.query.staking.bonded(stash), // Option representing the controller ]); const at = { @@ -35,9 +36,9 @@ export class AccountsStakingInfoService extends AbstractService { const [stakingLedgerOption, rewardDestination, slashingSpansOption] = await Promise.all([ - api.query.staking.ledger.at(hash, controller), - api.query.staking.payee.at(hash, stash), - api.query.staking.slashingSpans.at(hash, stash), + historicApi.query.staking.ledger(controller), + historicApi.query.staking.payee(stash), + historicApi.query.staking.slashingSpans(stash), ]); const stakingLedger = stakingLedgerOption.unwrapOr(null); From ce35a05976f416fe14179103b77fbab41ed9863f Mon Sep 17 00:00:00 2001 From: tarikgul Date: Fri, 29 Oct 2021 12:24:10 -0400 Subject: [PATCH 2/2] lint --- src/services/accounts/AccountsStakingInfoService.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/accounts/AccountsStakingInfoService.spec.ts b/src/services/accounts/AccountsStakingInfoService.spec.ts index c8229f2cb..e9da571c8 100644 --- a/src/services/accounts/AccountsStakingInfoService.spec.ts +++ b/src/services/accounts/AccountsStakingInfoService.spec.ts @@ -53,7 +53,7 @@ const historicApi = { slashingSpans: slashingSpansAt, }, }, -} as unknown as ApiDecoration<'promise'> +} as unknown as ApiDecoration<'promise'>; const mockApi = { ...defaultMockApi,