// Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { ApiInterfaceRx } from '@polkadot/api/types'; import type { Bytes, Option } from '@polkadot/types'; import type { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces'; import type { ITuple } from '@polkadot/types/types'; import type { Observable } from '@polkadot/x-rxjs'; import type { DeriveProposalImage } from '../types'; import { map } from '@polkadot/x-rxjs/operators'; import { memo } from '../util'; import { parseImage } from './util'; type PreImage = Option>; export function preimage (instanceId: string, api: ApiInterfaceRx): (hash: Hash) => Observable { return memo(instanceId, (hash: Hash): Observable => api.query.democracy.preimages(hash).pipe( map((imageOpt) => parseImage(api, imageOpt)) ) ); }