Skip to content

Instantly share code, notes, and snippets.

@mariodian
Last active January 23, 2019 05:25
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 mariodian/301a3e96cd017744defed359b738a13a to your computer and use it in GitHub Desktop.
Save mariodian/301a3e96cd017744defed359b738a13a to your computer and use it in GitHub Desktop.
Connect to peers that you have open channels with.
#!/bin/bash
jq --help >/dev/null 2>&1 || { echo >&2 "Error: 'jq' is required but not installed."; exit 1; }
LIST=$(lncli listchannels | jq -r '.[]')
LENGTH=$(echo $LIST | jq 'length')
for (( i=0; i<$LENGTH; i++ ));
do
NODE_PUBKEY=$(echo $LIST | jq ".[$i].remote_pubkey" | tr -d '"')
NODE=$(lncli getnodeinfo $NODE_PUBKEY | jq -r '.node')
NODE_ADDRESS=$(echo $NODE | jq -r '.addresses[0].addr')
if [[ $(lncli listpeers | grep -c $NODE_PUBKEY) -eq 0 ]] && [ "$NODE_ADDRESS" != "null" ] && [[ ! "$NODE_ADDRESS" =~ .*onion.* ]];
then
echo "Connecting to $(echo $NODE | jq '.alias') ($NODE_PUBKEY)"
lncli connect --perm $NODE_PUBKEY@$NODE_ADDRESS
echo ""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment