Skip to content

Commit 8b37ed6

Browse files
authored
nimbus author mapping correction (#5590)
1 parent d2a7df9 commit 8b37ed6

File tree

1 file changed

+13
-7
lines changed
  • packages/api-derive/src/chain

1 file changed

+13
-7
lines changed

packages/api-derive/src/chain/util.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import type { Observable } from 'rxjs';
55
import type { QueryableStorage } from '@polkadot/api-base/types';
66
import type { Compact, Vec } from '@polkadot/types';
7-
import type { AccountId, Address, BlockNumber, Header } from '@polkadot/types/interfaces';
7+
import type { AccountId, BlockNumber, Header } from '@polkadot/types/interfaces';
8+
import type { SpCoreSr25519Public } from '@polkadot/types/lookup';
89
import type { Codec, IOption } from '@polkadot/types/types';
910
import type { DeriveApi } from '../types.js';
1011

11-
import { combineLatest, map, of } from 'rxjs';
12+
import { combineLatest, map, mergeMap, of } from 'rxjs';
1213

1314
import { memo, unwrapBlockNumber } from '../util/index.js';
1415

@@ -46,14 +47,19 @@ export function getAuthorDetails (header: Header, queryAt: QueryableStorage<'rxj
4647
]);
4748
}
4849

49-
// fall back to session pallet, if available (ie: manta, calamari), to map session (nimbus) key to author (collator/validator) key
50-
if (queryAt.session && queryAt.session.queuedKeys) {
50+
// fall back to session and parachain staking pallets, if available (ie: manta, calamari), to map session (nimbus) key to author (collator) key
51+
if (queryAt.parachainStaking && queryAt.parachainStaking.selectedCandidates && queryAt.session && queryAt.session.nextKeys && queryAt.session.nextKeys.multi) {
5152
return combineLatest([
5253
of(header),
5354
validators,
54-
queryAt.session.queuedKeys<[AccountId, { nimbus: Address }][]>().pipe(
55-
map((queuedKeys) => queuedKeys.find((sessionKey) => sessionKey[1].nimbus.toHex() === loggedAuthor.toHex())),
56-
map((sessionKey) => (sessionKey) ? sessionKey[0] : null)
55+
queryAt.parachainStaking.selectedCandidates<AccountId[]>().pipe(
56+
mergeMap((selectedCandidates) => combineLatest([
57+
of(selectedCandidates),
58+
queryAt.session.nextKeys.multi<IOption<{ nimbus: SpCoreSr25519Public } & Codec>>(selectedCandidates).pipe(
59+
map((nextKeys) => nextKeys.findIndex((option) => option.unwrapOrDefault().nimbus.toHex() === loggedAuthor.toHex()))
60+
)
61+
])),
62+
map(([selectedCandidates, index]) => selectedCandidates[index])
5763
)
5864
]);
5965
}

0 commit comments

Comments
 (0)