@@ -7,7 +7,7 @@ import type { SpCoreSr25519Public } from 'https://deno.land/x/polkadot/types/loo
77import type { Codec , IOption } from 'https://deno.land/x/polkadot/types/types/index.ts' ;
88import type { DeriveApi } from '../types.ts' ;
99
10- import { combineLatest , map , mergeMap , of } from 'https://esm.sh/rxjs@7.8.0' ;
10+ import { combineLatest , map , mergeMap , of , switchMap } from 'https://esm.sh/rxjs@7.8.0' ;
1111
1212import { memo , unwrapBlockNumber } from '../util/index.ts' ;
1313
@@ -22,7 +22,8 @@ export function createBlockNumberDerive <T extends { number: Compact<BlockNumber
2222 ) ;
2323}
2424
25- export function getAuthorDetails ( header : Header , queryAt : QueryableStorage < 'rxjs' > ) : Observable < [ Header , Vec < AccountId > | null , AccountId | null ] > {
25+ /** @internal */
26+ function getAuthorDetailsWithAt ( header : Header , queryAt : QueryableStorage < 'rxjs' > ) : Observable < [ Header , Vec < AccountId > | null , AccountId | null ] > {
2627 const validators = queryAt . session
2728 ? queryAt . session . validators ( )
2829 : of ( null ) ;
@@ -70,3 +71,22 @@ export function getAuthorDetails (header: Header, queryAt: QueryableStorage<'rxj
7071 of ( null )
7172 ] ) ;
7273}
74+
75+ export function getAuthorDetails ( api : DeriveApi , header : Header , blockHash ?: Uint8Array | string ) : Observable < [ Header , Vec < AccountId > | null , AccountId | null ] > {
76+ // For on-chain state, we need to retrieve it as per the start
77+ // of the block being constructed, i.e. session validators would
78+ // be at the point of the block construction, not when all operations
79+ // has been supplied.
80+ //
81+ // However for the first block (no parentHash available), we would
82+ // just use the as-is
83+ return api . queryAt (
84+ header . parentHash . isEmpty
85+ ? blockHash || header . hash
86+ : header . parentHash
87+ ) . pipe (
88+ switchMap ( ( queryAt ) =>
89+ getAuthorDetailsWithAt ( header , queryAt )
90+ )
91+ ) ;
92+ }
0 commit comments