-
Notifications
You must be signed in to change notification settings - Fork 9
/
pay
executable file
·25 lines (20 loc) · 884 Bytes
/
pay
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env bash
set -e -o pipefail
source _toolbox_lib.sh
FROM_PERSON=${1:-alice}
TO_PERSON=${2:-bob}
AMOUNT_BTC=${3:-0.01}
PAY_REQUEST=$(req_pay "$TO_PERSON" ${AMOUNT_BTC})
FLAVOR=$(get_flavor "$FROM_PERSON")
case "$FLAVOR" in
lnd) "$FROM_PERSON" sendpayment --force --pay_req="${PAY_REQUEST}" ;;
lightning) "$FROM_PERSON" pay "${PAY_REQUEST}" ;;
eclair)
PAY_ATTEMPT_ID=$("$FROM_PERSON" payinvoice --maxAttempts=100 --invoice="${PAY_REQUEST}")
# see https://acinq.github.io/eclair/#getsentinfo
cmd="jq -e '.[] | select(.parentId == \"${PAY_ATTEMPT_ID}\").status.paymentPreimage' <<<\$(alice getsentinfo --id=${PAY_ATTEMPT_ID})"
cmd2="alice getsentinfo --id=${PAY_ATTEMPT_ID}"
wait_for "payment success between $FROM_PERSON and $TO_PERSON" "$cmd" "$cmd2"
;;
*) echo_err "unsupported flavor type '$FLAVOR' for '$FROM_PERSON'"; exit 1; ;;
esac