@@ -9,7 +9,7 @@ import type { SpCoreSr25519Public } from '@polkadot/types/lookup';
99import type { Codec , IOption } from '@polkadot/types/types' ;
1010import type { DeriveApi } from '../types.js' ;
1111
12- import { combineLatest , map , mergeMap , of } from 'rxjs' ;
12+ import { combineLatest , map , mergeMap , of , switchMap } from 'rxjs' ;
1313
1414import { memo , unwrapBlockNumber } from '../util/index.js' ;
1515
@@ -24,7 +24,8 @@ export function createBlockNumberDerive <T extends { number: Compact<BlockNumber
2424 ) ;
2525}
2626
27- export function getAuthorDetails ( header : Header , queryAt : QueryableStorage < 'rxjs' > ) : Observable < [ Header , Vec < AccountId > | null , AccountId | null ] > {
27+ /** @internal */
28+ function getAuthorDetailsWithAt ( header : Header , queryAt : QueryableStorage < 'rxjs' > ) : Observable < [ Header , Vec < AccountId > | null , AccountId | null ] > {
2829 const validators = queryAt . session
2930 ? queryAt . session . validators ( )
3031 : of ( null ) ;
@@ -72,3 +73,22 @@ export function getAuthorDetails (header: Header, queryAt: QueryableStorage<'rxj
7273 of ( null )
7374 ] ) ;
7475}
76+
77+ export function getAuthorDetails ( api : DeriveApi , header : Header , blockHash ?: Uint8Array | string ) : Observable < [ Header , Vec < AccountId > | null , AccountId | null ] > {
78+ // For on-chain state, we need to retrieve it as per the start
79+ // of the block being constructed, i.e. session validators would
80+ // be at the point of the block construction, not when all operations
81+ // has been supplied.
82+ //
83+ // However for the first block (no parentHash available), we would
84+ // just use the as-is
85+ return api . queryAt (
86+ header . parentHash . isEmpty
87+ ? blockHash || header . hash
88+ : header . parentHash
89+ ) . pipe (
90+ switchMap ( ( queryAt ) =>
91+ getAuthorDetailsWithAt ( header , queryAt )
92+ )
93+ ) ;
94+ }
0 commit comments