UNPKG

@ledgerhq/coin-stellar

Version:
38 lines 1.42 kB
"use strict"; // 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 Stellar closed ledger at the given sequence. * * Fetches the ledger once. When `height > 1` and Horizon provides `prev_hash`, * `BlockInfo.parent` is derived without a second request; otherwise the parent * ledger is loaded explicitly. Genesis ledger sequence 1 has no parent. */ async function getBlockInfo(height) { if (!Number.isSafeInteger(height) || height <= 0) { throw new Error(`getBlockInfo: height must be a positive integer, got ${height}`); } const ledger = await (0, network_1.fetchLedgerRecord)(height); const info = { height: ledger.sequence, hash: ledger.hash, time: new Date(ledger.closed_at), }; let parent; if (height > 1) { const prevHash = ledger.prev_hash; if (prevHash) { parent = { height: height - 1, hash: prevHash }; } else { const parentLedger = await (0, network_1.fetchLedgerRecord)(height - 1); parent = { height: parentLedger.sequence, hash: parentLedger.hash }; } info.parent = parent; } return info; } //# sourceMappingURL=getBlockInfo.js.map