echo BLOCK: $(curl -s 127.0.0.1:26657/status |\
jq -r '.result.sync_info.latest_block_time');\
echo "NOW: $(LC_TIME=C date -u +%Y-%m-%dT%X.%NZ)"
Blockchain perspective
If you deal with a Cosmos based blockchain, this command (actually there are 2 commands) helps to visualise the difference between the time of the latest block and current time. That's helpful if a node needs to catch up (e.g. after restarting from a snapshot).
UNIX perspective
The command has a few interesting "UNIX features". First, the curl from the localhost is silent (-s option) to avoid showing download stats. Its output is redirected to jq, which presents the raw (-r option) the time of latest block (.result.sync_info.lastest_block_time field).
The second command returns the current time. The LC_TIME=Csets the locale to a standard, non-localized format, ensuring the output is always in a 24-hour clock and not a 12-hour AM/PM format, which can vary by location. The option -u forces the output in the UTC, rather than the local time. Finally, +%Y-%m-%dT%X.%NZ
formats date identical like the cosmos endpoint.
No comments:
Post a Comment