UNPKG

@ledgerhq/coin-hedera

Version:
28 lines 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.lastBlock = lastBlock; const constants_1 = require("../constants"); const api_1 = require("../network/api"); const utils_1 = require("./utils"); /** * Gets the latest "block" information for Hedera. * * Hedera doesn't have actual blocks - it uses a timestamp-based consensus model. * To make Hedera compatible with block-based architecture: * 1. We fetch the most recent transaction from the mirror node * 2. Extract its consensus timestamp * 3. Convert this timestamp into a synthetic block using a hardcoded time window (10 seconds by default) */ async function lastBlock() { // see getBlock implementation, block data should be immutable: we do not allow querying blocks on non-finalized time range. // => we search the most recent transaction, but only in finalized time range (ending 10 seconds ago). const before = new Date(Date.now() - constants_1.FINALITY_MS - constants_1.SYNTHETIC_BLOCK_WINDOW_SECONDS * 1000); const latestTransaction = await api_1.apiClient.getLatestTransaction(before); const syntheticBlock = (0, utils_1.getSyntheticBlock)(latestTransaction.consensus_timestamp); return { height: syntheticBlock.blockHeight, hash: syntheticBlock.blockHash, time: syntheticBlock.blockTime, }; } //# sourceMappingURL=lastBlock.js.map