Last active
October 10, 2023 06:06
-
-
Save assafmo/01d7ee0d131a99518d2a4189a9250460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://gist.github.com/assafmo/01d7ee0d131a99518d2a4189a9250460 | |
BLOCK_WINDOW="${1}" # e.g. 100000 blocks in the past | |
UPGRADE_TIME="${2}" # e.g. 2023-03-02T19:07:13Z | |
LCD="${3}" # e.g. https://lcd.secret.express or https://api.pulsar.scrttestnet.com | |
LATEST="$(curl -s "$LCD/cosmos/base/tendermint/v1beta1/blocks/latest")" | |
echo "$LATEST" | jq -r .block.header.chain_id | |
LATEST_HEIGHT="$(echo "${LATEST}" | jq -r .block.header.height)" | |
LATEST_TIME="$(echo "${LATEST}" | jq -r .block.header.time)" | |
PAST_HEIGHT="$(node -p "${LATEST_HEIGHT} - ${BLOCK_WINDOW}")" | |
PAST="$(curl -s "$LCD/cosmos/base/tendermint/v1beta1/blocks/${PAST_HEIGHT}")" | |
PAST_TIME="$(echo "${PAST}" | jq -r .block.header.time)" | |
BLOCK_TIME=$(node -p "(new Date('${LATEST_TIME}').getTime() - new Date('${PAST_TIME}').getTime()) / 1000 / ${BLOCK_WINDOW}") | |
node -p "Math.floor((new Date('${UPGRADE_TIME}').getTime()-Date.now())/1000/${BLOCK_TIME} + ${LATEST_HEIGHT})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment