|
4 | 4 | import type { Observable } from 'rxjs'; |
5 | 5 | import type { QueryableStorage } from '@polkadot/api-base/types'; |
6 | 6 | 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'; |
8 | 9 | import type { Codec, IOption } from '@polkadot/types/types'; |
9 | 10 | import type { DeriveApi } from '../types.js'; |
10 | 11 |
|
11 | | -import { combineLatest, map, of } from 'rxjs'; |
| 12 | +import { combineLatest, map, mergeMap, of } from 'rxjs'; |
12 | 13 |
|
13 | 14 | import { memo, unwrapBlockNumber } from '../util/index.js'; |
14 | 15 |
|
@@ -46,14 +47,19 @@ export function getAuthorDetails (header: Header, queryAt: QueryableStorage<'rxj |
46 | 47 | ]); |
47 | 48 | } |
48 | 49 |
|
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) { |
51 | 52 | return combineLatest([ |
52 | 53 | of(header), |
53 | 54 | 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]) |
57 | 63 | ) |
58 | 64 | ]); |
59 | 65 | } |
|
0 commit comments