UNPKG

cosmic-interchain-cli

Version:

A command-line utility for Cosmic Wire's interchain messaging protocol

46 lines 1.99 kB
import { S3Validator } 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 (s3StorageLocation) => { let s3Validator; try { s3Validator = await S3Validator.fromStorageLocation(s3StorageLocation); } catch (err) { logDebug(`Failed to instantiate S3Validator at location ${s3StorageLocation}: ${err}`); return undefined; } try { const latestCheckpointIndex = await s3Validator.getLatestCheckpointIndex(); return [latestCheckpointIndex, s3Validator.getLatestCheckpointUrl()]; } catch (err) { logDebug(`Failed to get latest checkpoint index from S3Validator at location ${s3StorageLocation}: ${err}`); return undefined; } }; export const isValidatorSigningLatestCheckpoint = (latestValidatorCheckpointIndex, latestMerkleTreeCheckpointIndex) => { const diff = Math.abs(latestValidatorCheckpointIndex - latestMerkleTreeCheckpointIndex); return diff < latestMerkleTreeCheckpointIndex / 100; }; //# sourceMappingURL=utils.js.map