#!/bin/bash

# Configuration
DISCORD_WEBHOOK_URL="YOUR_WEBHOOK_DISCORD" # FILL IT WITH YOUR WEBHOOK DISCORD
CHECK_INTERVAL=1  # Interval in seconds between checks

while true; do
    timestamp=$(date +"%Y-%m-%d %H:%M:%S")
    local_height=$(curl -s CHANGE_TO_YOUR_LOCAL_RPC | jq -r .result.sync_info.latest_block_height)# YOU CAN FILL IT WITH LINK RPC OR LOCAL IP OF SERVER
    network_height=$(curl -s https://b545809c-5562-4e60-b5a1-22e83df57748.initiation-1.mesa-rpc.ue1-prod.newmetric.xyz/status | jq -r .result.sync_info.latest_block_height) # YOU CAN CUSTOMIZE LINK RPC TO ANOTHER VALIDATOR, RIGHT NOW WAS LINKED TO OFFICIAL INITIA
    blocks_left=$((network_height - local_height))

    echo "[$timestamp] Your node height: $local_height"
    echo "[$timestamp] Network height: $network_height"
    echo "[$timestamp] Blocks left: $blocks_left"

    if [ "$blocks_left" -gt 0 ]; then
        alert_message="[$timestamp] Block height mismatch detected!\nYour node height: $local_height\nNetwork height: $network_height\nBlocks left: $blocks_left"
        curl -H "Content-Type: application/json" -d "{\"content\": \"$alert_message\"}" $DISCORD_WEBHOOK_URL
    fi

    sleep $CHECK_INTERVAL
done
