-
Notifications
You must be signed in to change notification settings - Fork 267
/
Copy patheclair-cli
executable file
·177 lines (148 loc) · 4.92 KB
/
eclair-cli
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
# default script values, can be overridden for convenience.
api_url='http://localhost:8080'
# uncomment the line below if you don't want to provide a password each time you call eclair-cli
# api_password='your_api_password'
# for some commands the json output can be shortened for better readability
short=false
# prints help message
usage() {
echo -e "==============================
Command line client for eclair
==============================
This tool requires the eclair node's API to be enabled and listening
on <$api_url>.
Usage
-----
\x1b[93meclair-cli\x1b[39m [\x1b[93mOPTIONS\x1b[39m]... <\x1b[93mCOMMAND\x1b[39m> [--command-param=command-value]...
where OPTIONS can be:
-p <password> API's password
-a <address> Override the API URL with <address>
-h Show this help
-s Some commands can print a trimmed JSON
and COMMAND is one of the available commands:
=== Node ===
- getinfo
- connect
- disconnect
- peers
- audit
- stop
=== Channel ===
- open
- rbfopen
- splicein
- spliceout
- close
- forceclose
- bumpforceclose
- channel
- channels
- closedchannels
- allchannels
- allupdates
- channelstats
- channelbalances
=== Fees ===
- networkfees
- updaterelayfee
=== Path-finding ===
- findroute
- findroutetonode
- findroutebetweennodes
- node
- nodes
=== Invoice ===
- createinvoice
- getinvoice
- listinvoices
- listpendinginvoices
- parseinvoice
- deleteinvoice
=== Payment ===
- usablebalances
- payinvoice
- payoffer
- sendtonode
- sendtoroute
- getsentinfo
- getreceivedinfo
- listreceivedpayments
=== Message ===
- signmessage
- verifymessage
- sendonionmessage
=== OnChain ===
- getnewaddress
- sendonchain
- cpfpbumpfees
- onchainbalance
- onchaintransactions
- globalbalance
- getmasterxpub
- getdescriptors
=== Control ===
- enablefromfuturehtlc
Examples
--------
eclair-cli -a localhost:1234 peers list the peers of a node hosted on localhost:1234
eclair-cli connect --nodeId=03864e... connect to node with id 03864e...
eclair-cli open --nodeId=... --fundingSatoshis=... open a channel to a given node
eclair-cli close --channelId=006fb... closes the channel with id 006fb...
Full documentation here: <https://acinq.github.io/eclair>" 1>&2;
exit 1;
}
# -- script's logic begins here
# Check if jq is installed. If not, display instructions and abort program
command -v jq >/dev/null 2>&1 || { echo -e "This tool requires jq.\nFor installation instructions, visit https://stedolan.github.io/jq/download/.\n\nAborting..."; exit 1; }
# curl installed? If not, give a hint
command -v curl >/dev/null 2>&1 || { echo -e "This tool requires curl.\n\nAborting..."; exit 1; }
# extract script options
while getopts ':cu:su:p:a:hu:' flag; do
case "${flag}" in
p) api_password="${OPTARG}" ;;
a) api_url="${OPTARG}" ;;
h) usage ;;
s) short=true ;;
*) ;;
esac
done
shift $(($OPTIND - 1))
# extract api's endpoint (e.g. sendpayment, connect, ...) from params
api_endpoint=${1}
shift 1
# display a usage method if no method given or help requested
if [ -z $api_endpoint ] || [ "$api_endpoint" == "help" ]; then
usage;
fi
# long options are expected to be of format: --param=param_value
api_payload=""
for arg in "${@}"; do
case ${arg} in
"--"*) api_payload="$api_payload --data-urlencode \"${arg:2}\"";
;;
*) echo "incorrect argument, please use --arg=value"; usage;
;;
esac
done;
# jq filter parses response body for error message
jq_filter='if type=="object" and .error != null then .error else .';
# apply special jq filter if we are in "short" output mode -- only for specific commands such as 'channels'
if [ "$short" = true ]; then
jq_channel_filter="{ nodeId, shortChannelId: .data.lastAnnouncement_opt.shortChannelId, channelId, state, commitments: (.data.commitments.active | map({balanceSat: (try (.localCommit.spec.toLocal / 1000 | floor) catch null), capacitySat: .fundingTx.amountSatoshis, fundingTxIndex: .fundingTxIndex, channelPoint: .fundingTx.outPoint})) }";
case $api_endpoint in
"channels") jq_filter="$jq_filter | map( $jq_channel_filter )" ;;
"channel") jq_filter="$jq_filter | $jq_channel_filter" ;;
*) ;;
esac
fi
jq_filter="$jq_filter end";
# if no password is provided, auth should only contain user login so that curl prompts for the api password
if [ -z $api_password ]; then
auth="eclair-cli";
else
auth="eclair-cli:$api_password";
fi
# we're now ready to execute the API call
set -o pipefail # ensures we preserve curl error code in case of HTTP issue
eval curl "--user $auth --silent --show-error -X POST -H \"Content-Type: application/x-www-form-urlencoded\" $api_payload $api_url/$api_endpoint" | jq -r "$jq_filter"