Rework derives to ensure cached registries (#4021)
This commit is contained in:
@@ -5,7 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { EventRecord, Hash, SignedBlock } from '@polkadot/types/interfaces';
|
||||
|
||||
import { combineLatest, map } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -15,15 +15,17 @@ interface Result {
|
||||
}
|
||||
|
||||
export function events (instanceId: string, api: ApiInterfaceRx): (at: Hash) => Observable<Result> {
|
||||
return memo(instanceId, (at: Hash): Observable<Result> =>
|
||||
combineLatest([
|
||||
api.query.system.events.at(at),
|
||||
api.rpc.chain.getBlock(at)
|
||||
]).pipe(
|
||||
map(([events, block]) => ({
|
||||
block,
|
||||
events
|
||||
}))
|
||||
return memo(instanceId, (at: Hash) =>
|
||||
// we get the block first, setting up the registry
|
||||
api.rpc.chain.getBlock(at).pipe(
|
||||
switchMap((block) =>
|
||||
api.query.system.events.at(at).pipe(
|
||||
map((events): Result => ({
|
||||
block,
|
||||
events
|
||||
}))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user