-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrebalance_to_node
executable file
·56 lines (50 loc) · 1.46 KB
/
rebalance_to_node
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
if [[ -z "$1" || -z "$2" ]] ; then
usage="usage: $0 node_id amount_mBTC"
echo $usage
exit 1
fi
TARGET_NODEID=$1
AMOUNT_MBTC=$2
echo "amount: "$AMOUNT_MBTC"mBTC"
AMOUNT_MSAT="$AMOUNT_MBTC"00000000
MY_NODEID=$($MAINNET_ECLAIR getinfo | jq -r .nodeId)
INV=$($MAINNET_ECLAIR createinvoice --description=rebalance | jq -r .serialized)
echo $INV
ignore_list=""
while true
do
CMD="$MAINNET_ECLAIR findroutetonode --nodeId=$TARGET_NODEID --amountMsat=$AMOUNT_MSAT"
if [ "$ignore_list" != "" ]; then
CMD=$CMD" --ignoreNodeIds=$ignore_list"
fi
ROUTES=$($CMD)
echo $ROUTES | jq
echo "choose route"
read route
# todo: select non-trivial route
ROUTE=$(echo $ROUTES | jq -r --arg route $route '.routes|.[($route|tonumber)].nodeIds| join(",")')
ROUTE=$ROUTE,$MY_NODEID
PARENTID=$($MAINNET_ECLAIR sendtoroute --invoice=$INV --amountMsat=$AMOUNT_MSAT --finalCltvExpiry=147 --nodeIds=$ROUTE | jq .parentId)
while true
do
sleep 1
INFO=$($MAINNET_ECLAIR getsentinfo --id=$PARENTID)
status=$(echo $INFO | jq -r '.[0]| .status.type')
if [ "$status" != "pending" ]; then
break
fi
done
echo $INFO | jq
if [ "$status" == "sent" ]; then
echo "success"
exit 0
fi
failed_node=$(echo $INFO | jq -r '.[0]| .status.failures[0].failedNode')
if [ "$ignore_list" != "" ]; then
ignore_list=$ignore_list,$failed_node
else
ignore_list=$failed_node
fi
echo "ignore_list: "$ignore_list
done