From 1b6012879b0439ccd3222b19956d4280a2d02dc8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 19 Oct 2016 12:02:27 +1030 Subject: [PATCH] contrib/lightning-pay: helper to make a payment. Signed-off-by: Rusty Russell --- contrib/lightning-pay | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 contrib/lightning-pay diff --git a/contrib/lightning-pay b/contrib/lightning-pay new file mode 100755 index 000000000..fed8438a9 --- /dev/null +++ b/contrib/lightning-pay @@ -0,0 +1,32 @@ +#! /bin/sh -e +# A terrible script to make a payment. + +if [ $# -ne 3 ]; then + echo "Usage: " >&2 + exit 1 +fi +DEST="$1" +AMOUNT="$2" +PHASH="$3" + +if ROUTE=`daemon/lightning-cli getroute $DEST $AMOUNT 1`; then + # Strip down to raw array. + ROUTE=`echo $ROUTE | sed 's/^{ "route" : \(.*\) }$/\1/'` + # Get first amount. + PAID=`echo $ROUTE | tr , '\012' | sed -n 's/.*msatoshi[^0-9]*\([0-9]*\).*/\1/p' | head -n1` + echo -n "Paying fee $(($PAID - $AMOUNT)) on $AMOUNT ("`echo "scale=3; ($PAID - $AMOUNT) * 100 / $AMOUNT" | bc`"%). Send [Y/n]? " + read REPLY + case $REPLY in + ""|y*|Y) + daemon/lightning-cli sendpay "$ROUTE" "$PHASH" + exit + ;; + *) + echo Not sending. + exit 1 + ;; + esac +else + echo Routing failed >&2 + exit 1 +fi