Rework derives to ensure cached registries (#4021)

This commit is contained in:
Jaco
2021-10-05 08:57:30 +03:00
committed by GitHub
parent 32881d73a0
commit d45a9cfe58
4 changed files with 55 additions and 42 deletions
+12 -10
View File
@@ -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
}))
)
)
)
);
}