ghost-portal/packages/react-api/src/util/historic.ts
Tarik Gul 384049fb6b
2025 (#11172)
* 2025

* update ci scripts to add access to scripts
2025-01-03 03:59:53 +02:00

16 lines
688 B
TypeScript

// Copyright 2017-2025 @polkadot/react-api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Hash } from '@polkadot/types/interfaces';
import type { Codec } from '@polkadot/types/types';
type AtQuery <I extends unknown[]> = (hash: string | Uint8Array, ...params: I) => Promise<Codec>;
export async function getHistoric <T extends Codec, I extends unknown[] = unknown[]> (atQuery: AtQuery<I>, params: I, hashes: Hash[]): Promise<[Hash, T][]> {
return Promise
.all(hashes.map((hash): Promise<T> => atQuery(hash, ...params) as Promise<T>))
.then((results): [Hash, T][] =>
results.map((value, index): [Hash, T] => [hashes[index], value])
);
}