Skip to content

Instantly share code, notes, and snippets.

@frennkie
Created October 12, 2019 22:23
Show Gist options
  • Select an option

  • Save frennkie/9d834753e9b5d383af4cb35dee7a6180 to your computer and use it in GitHub Desktop.

Select an option

Save frennkie/9d834753e9b5d383af4cb35dee7a6180 to your computer and use it in GitHub Desktop.
#!/bin/bash
function usage() {
echo -e "This checks if a LND invoice has been payed using the rhash"
echo -e ""
echo -e "Usage: $0 [-h|--help] [-v*|--verbose] [-r|--rhash STRING]"
echo -e ""
echo -e " -h, --help\t\tprint this help message"
echo -e " -v, --verbose\t\tbe more verbose"
echo -e " -r, --rhash STRING\tthe payment hash of the invoice (as HEX not BASE64!)"
echo -e ""
}
function check_program() {
command -v $1 >/dev/null 2>&1 || { echo >&2 "The program $1 is required but not installed. Aborting."; exit 1; }
}
# Default Values
verbose=0
amt=0
memo=""
while [[ "$1" == -* ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-v*)
(( verbose += ${#1} - 1 ))
;;
--verbose)
(( verbose++ ))
;;
-r|--rhash)
shift
rhash="$1"
;;
--)
shift
break
;;
*)
echo "Unrecognized option $1."
echo ""
usage
exit 1
;;
esac
shift
done
if [[ -z "$rhash" ]]; then
echo "Error: Argument not set: --rhash"
exit 1
fi
if [[ "$rhash" =~ "=" ]]; then
echo "Error: '${rhash}' contains a \"=\""
exit 1
fi
if [[ "$rhash" =~ "+" ]]; then
echo "Error: '${rhash}' contains a \"+\""
exit 1
fi
if [[ "$rhash" =~ "/" ]]; then
echo "Error: '${rhash}' contains a \"/\""
exit 1
fi
# CONFIGFILE - configuration of RaspiBlitz
configFile="/mnt/hdd/raspiblitz.conf"
configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf')
if [ ${configExists} -eq 1 ]; then
source ${configFile}
else
echo "file not found: ${configFile}!"
exit 1
fi
# make sure required programs are installed
check_program jq
check_program lncli
## SETUP DONE
ln_result=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net lookupinvoice --rhash ${rhash} 2>/dev/null)
if [[ -z "$ln_result" ]]; then
echo "Error: invoice not found"
exit 1
fi
bool_result=$(echo "${ln_result}" | jq .settled)
echo ${bool_result}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment