Skip to content

Instantly share code, notes, and snippets.

@assafmo
Last active October 10, 2023 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save assafmo/01d7ee0d131a99518d2a4189a9250460 to your computer and use it in GitHub Desktop.
Save assafmo/01d7ee0d131a99518d2a4189a9250460 to your computer and use it in GitHub Desktop.
#!/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