@ledgerhq/coin-tezos
Version:
30 lines • 1.12 kB
JavaScript
;
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBlockInfo = getBlockInfo;
const network_1 = require("../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.
*/
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 = (0, network_1.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