Skip to content

Instantly share code, notes, and snippets.

@clemensgg
Created April 15, 2023 14:05
Show Gist options
  • Save clemensgg/a0e3a59c89eb68e4137c343bc14f3b8a to your computer and use it in GitHub Desktop.
Save clemensgg/a0e3a59c89eb68e4137c343bc14f3b8a to your computer and use it in GitHub Desktop.
TM RPC fetch peerlist
#!/bin/bash
# fetch NET_INFO from tendermint RPC and convert it to a comma-seperated peerstring
RPC=${1%/}
if [ -z $RPC ] ; then
echo "no RPC endpoint provided!"
echo "usage: ./$0 <RPC-ENDPOINT>"
exit 1
fi
if ! JSON_DATA=$(curl -s $RPC/net_info --connect-timeout 5) ; then
echo "RPC $RPC didn't respond. exiting..."
exit 1
fi
OUTPUT=""
NODES=$(echo $JSON_DATA | jq '.result.peers[]')
for NODE in $(echo "${NODES}" | jq -r '. | @base64'); do
_jq() {
echo ${NODE} | base64 --decode | jq -r ${1}
}
NODE_ID=$(_jq '.node_info.id')
REMOTE_IP=$(_jq '.remote_ip')
LISTEN_PORT=$(echo $(_jq '.node_info.listen_addr') | cut -d':' -f3)
if [ -z "$OUTPUT" ]; then
OUTPUT="${NODE_ID}@${REMOTE_IP}:${LISTEN_PORT}"
else
OUTPUT="${OUTPUT},${NODE_ID}@${REMOTE_IP}:${LISTEN_PORT}"
fi
done
echo $OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment