// Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { EventRecord, Hash, SignedBlock } from '@polkadot/types/interfaces'; import type { Observable } from '@polkadot/x-rxjs'; import { combineLatest } from '@polkadot/x-rxjs'; import { map } from '@polkadot/x-rxjs/operators'; import { memo } from '../util'; interface Result { block: SignedBlock; events: EventRecord[]; } export function events (instanceId: string, api: ApiInterfaceRx): (at: Hash) => Observable { return memo(instanceId, (at: Hash): Observable => combineLatest([ api.query.system.events.at(at), api.rpc.chain.getBlock(at) ]).pipe( map(([events, block]) => ({ block, events })) ) ); }