UNPKG

@hyperlane-xyz/cli

Version:

A command-line utility for common Hyperlane operations

46 lines 1.99 kB
import { getValidatorFromStorageLocation } from '@hyperlane-xyz/sdk'; import { logDebug } from '../logger.js'; export const getLatestMerkleTreeCheckpointIndex = async (merkleTreeHook, chainName) => { try { const [_, latestCheckpointIndex] = await merkleTreeHook.latestCheckpoint(); return latestCheckpointIndex; } catch (err) { const debugMessage = `Failed to get latest checkpoint index from merkleTreeHook contract ${chainName ? `on ${chainName}` : ''} : ${err}`; logDebug(debugMessage); return undefined; } }; export const getValidatorStorageLocations = async (validatorAnnounce, validators, chainName) => { try { return await validatorAnnounce.getAnnouncedStorageLocations(validators); } catch (err) { const debugMessage = `Failed to get announced storage locations from validatorAnnounce contract ${chainName ? `on ${chainName}` : ''} : ${err}`; logDebug(debugMessage); return undefined; } }; export const getLatestValidatorCheckpointIndexAndUrl = async (storageLocation) => { let validator; try { validator = await getValidatorFromStorageLocation(storageLocation); } catch (err) { logDebug(`Failed to instantiate Validator at location ${storageLocation}: ${err}`); return undefined; } try { const latestCheckpointIndex = await validator.getLatestCheckpointIndex(); return [latestCheckpointIndex, validator.getLatestCheckpointUrl()]; } catch (err) { logDebug(`Failed to get latest checkpoint index from Validator at location ${storageLocation}: ${err}`); return undefined; } }; export const isValidatorSigningLatestCheckpoint = (latestValidatorCheckpointIndex, latestMerkleTreeCheckpointIndex) => { const diff = Math.abs(latestValidatorCheckpointIndex - latestMerkleTreeCheckpointIndex); return diff < latestMerkleTreeCheckpointIndex / 100; }; //# sourceMappingURL=utils.js.map