@ledgerhq/coin-tezos
Version:
27 lines • 1 kB
JavaScript
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
// SPDX-License-Identifier: Apache-2.0
import { createTzktApi } from '../network';
/**
* Returns lightweight metadata for a Tezos block at the given level.
*
* Fetches the block and its predecessor in parallel so that `BlockInfo.parent`
* is always populated without adding serial latency.
*/
export async function getBlockInfo(context, height) {
if (!Number.isSafeInteger(height) || height <= 0) {
throw new Error(`getBlockInfo: height must be a positive integer, got ${height}`);
}
const config = await context.config();
const tzkt = createTzktApi(config);
const [block, parentBlock] = await Promise.all([
tzkt.getBlockByLevel(height),
tzkt.getBlockByLevel(height - 1),
]);
return {
height: block.level,
hash: block.hash,
time: new Date(block.timestamp),
parent: { height: parentBlock.level, hash: parentBlock.hash },
};
}
//# sourceMappingURL=getBlockInfo.js.map