UNPKG

@ledgerhq/coin-stellar

Version:
35 lines 1.28 kB
// SPDX-FileCopyrightText: © 2026 LEDGER SAS // SPDX-License-Identifier: Apache-2.0 import { fetchLedgerRecord } from '../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. */ export 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 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 fetchLedgerRecord(height - 1); parent = { height: parentLedger.sequence, hash: parentLedger.hash }; } info.parent = parent; } return info; } //# sourceMappingURL=getBlockInfo.js.map