Created
October 12, 2019 22:24
-
-
Save frennkie/d12c4cd8ed7e7fd294afca316f5a024d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function usage() { | |
echo -e "This script generates a LND invoice and prints the payment request" | |
echo -e "" | |
echo -e "Usage: $0 [-h|--help] [-v*|--verbose] [-a|--amt STRING] [-m|--memo STRING]" | |
echo -e "" | |
echo -e " -h, --help\t\tprint this help message" | |
echo -e " -v, --verbose\t\tbe more verbose" | |
echo -e " -a, --amt STRING\tAmount in Satoshi" | |
echo -e " -m, --memo STRING\tMemo to add to invoice" | |
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++ )) | |
;; | |
-a|--amt) | |
shift | |
amt="$1" | |
;; | |
-m|--memo) | |
shift | |
memo="$1" | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
echo "Unrecognized option $1." | |
echo "" | |
usage | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
if ! [[ "$amt" =~ ^[[:digit:]]+$ ]]; then | |
echo "Error: amt must be a positive integer or 0." >&2 | |
exit 1 | |
fi | |
if [[ ${memo//[^[:space:]]} ]]; then | |
echo "Error: '${memo}' contains a space" | |
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 | |
amt_flag="" | |
if [ "$amt" -ne "0" ]; then | |
amt_flag=" --amt=${amt}" | |
fi | |
if [ ! -z "$memo" ]; then | |
memo_flag=" --memo=${memo}" | |
fi | |
ln_result=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net addinvoice ${amt_flag} ${memo_flag} 2>/dev/null) | |
#payReq=$(echo "${ln_result}" | jq .pay_req | sed s/\"//g) | |
#echo ${payReq} | |
echo ${ln_result} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment