-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathget_route
executable file
·36 lines (31 loc) · 937 Bytes
/
get_route
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
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
set -e -o pipefail
source _toolbox_lib.sh
FROM_PERSON=${1:-alice}
TO_PERSON=${2:-bob}
AMOUNT_BTC=${3:-$(sat2btc 1)} # 1 sat by default
RISK_FACTOR=${4:-10}
TO_PERSON_ID=$(pubkey "$TO_PERSON")
FLAVOR=$(get_flavor "$FROM_PERSON")
case "$FLAVOR" in
lnd)
AMOUNT_SAT=$(btc2sat "$AMOUNT_BTC")
exec "$FROM_PERSON" queryroutes "$TO_PERSON_ID" "$AMOUNT_SAT"
;;
lightning)
AMOUNT_MSAT=$(btc2msat "$AMOUNT_BTC")
exec "$FROM_PERSON" getroute "$TO_PERSON_ID" "$AMOUNT_MSAT" "$RISK_FACTOR"
;;
eclair)
AMOUNT_MSAT=$(btc2msat "$AMOUNT_BTC")
ROUTE=$("$FROM_PERSON" findroutetonode --nodeId="$TO_PERSON_ID" --amountMsat="$AMOUNT_MSAT")
echo "$ROUTE"
# see https://github.com/ACINQ/eclair/issues/998
if [[ "$ROUTE" == "route not found"* ]]; then
exit 1
else
exit 0
fi
;;
*) echo_err "unsupported flavor type '$FLAVOR' for '$FROM_PERSON'"; exit 1; ;;
esac