2016-06-02 17:15:36 +02:00
|
|
|
#!/bin/bash
|
2019-03-26 18:10:09 +01:00
|
|
|
|
2021-02-08 11:20:23 +01:00
|
|
|
# default script values, can be overridden for convenience.
|
2019-03-26 18:10:09 +01:00
|
|
|
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
|
|
|
|
-----
|
2021-02-22 18:14:49 +01:00
|
|
|
\x1b[93meclair-cli\x1b[39m [\x1b[93mOPTIONS\x1b[39m]... <\x1b[93mCOMMAND\x1b[39m> [--command-param=command-value]...
|
2019-03-26 18:10:09 +01:00
|
|
|
|
|
|
|
where OPTIONS can be:
|
|
|
|
-p <password> API's password
|
|
|
|
-a <address> Override the API URL with <address>
|
2019-04-03 19:19:56 +02:00
|
|
|
-h Show this help
|
|
|
|
-s Some commands can print a trimmed JSON
|
2019-03-26 18:10:09 +01:00
|
|
|
|
2020-06-19 18:02:39 +02:00
|
|
|
and COMMAND is one of the available commands:
|
|
|
|
|
|
|
|
=== Node ===
|
|
|
|
- getinfo
|
|
|
|
- connect
|
|
|
|
- disconnect
|
|
|
|
- peers
|
|
|
|
- audit
|
|
|
|
|
|
|
|
=== Channel ===
|
|
|
|
- open
|
|
|
|
- close
|
|
|
|
- forceclose
|
|
|
|
- channel
|
|
|
|
- channels
|
|
|
|
- allchannels
|
|
|
|
- allupdates
|
|
|
|
- channelstats
|
2022-03-29 11:10:42 +02:00
|
|
|
- channelbalances
|
2021-03-09 15:23:50 +01:00
|
|
|
|
|
|
|
=== Fees ===
|
2020-06-19 18:02:39 +02:00
|
|
|
- networkfees
|
|
|
|
- updaterelayfee
|
|
|
|
|
|
|
|
=== Path-finding ===
|
|
|
|
- findroute
|
|
|
|
- findroutetonode
|
2021-02-22 18:14:49 +01:00
|
|
|
- findroutebetweennodes
|
2021-03-09 15:23:50 +01:00
|
|
|
- nodes
|
2020-06-19 18:02:39 +02:00
|
|
|
|
|
|
|
=== Invoice ===
|
|
|
|
- createinvoice
|
|
|
|
- getinvoice
|
|
|
|
- listinvoices
|
|
|
|
- listpendinginvoices
|
|
|
|
- parseinvoice
|
|
|
|
|
|
|
|
=== Payment ===
|
|
|
|
- usablebalances
|
|
|
|
- payinvoice
|
|
|
|
- sendtonode
|
|
|
|
- sendtoroute
|
|
|
|
- getsentinfo
|
|
|
|
- getreceivedinfo
|
2021-03-09 15:23:50 +01:00
|
|
|
|
|
|
|
=== Message ===
|
|
|
|
- signmessage
|
|
|
|
- verifymessage
|
|
|
|
|
|
|
|
=== OnChain ===
|
|
|
|
- getnewaddress
|
|
|
|
- sendonchain
|
|
|
|
- onchainbalance
|
2020-06-19 18:02:39 +02:00
|
|
|
- onchaintransactions
|
2019-03-26 18:10:09 +01:00
|
|
|
|
|
|
|
Examples
|
|
|
|
--------
|
2020-06-19 18:02:39 +02:00
|
|
|
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...
|
2019-03-26 18:10:09 +01:00
|
|
|
|
2019-04-03 19:19:56 +02:00
|
|
|
Full documentation here: <https://acinq.github.io/eclair>" 1>&2;
|
2019-03-26 18:10:09 +01:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# -- script's logic begins here
|
|
|
|
|
2018-01-11 19:23:17 +01:00
|
|
|
# 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; }
|
|
|
|
|
2018-11-13 17:35:16 +01:00
|
|
|
# curl installed? If not, give a hint
|
|
|
|
command -v curl >/dev/null 2>&1 || { echo -e "This tool requires curl.\n\nAborting..."; exit 1; }
|
|
|
|
|
2019-03-26 18:10:09 +01:00
|
|
|
# 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
|
2018-01-11 19:23:17 +01:00
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
2019-03-26 18:10:09 +01:00
|
|
|
# extract api's endpoint (e.g. sendpayment, connect, ...) from params
|
|
|
|
api_endpoint=${1}
|
2018-01-11 19:23:17 +01:00
|
|
|
shift 1
|
|
|
|
|
2019-03-26 18:10:09 +01:00
|
|
|
# display a usage method if no method given or help requested
|
|
|
|
if [ -z $api_endpoint ] || [ "$api_endpoint" == "help" ]; then
|
|
|
|
usage;
|
|
|
|
fi
|
|
|
|
|
2019-04-03 19:19:56 +02:00
|
|
|
# long options are expected to be of format: --param=param_value
|
2019-03-26 18:10:09 +01:00
|
|
|
api_payload=""
|
2018-01-11 19:23:17 +01:00
|
|
|
for arg in "${@}"; do
|
2019-03-26 18:10:09 +01:00
|
|
|
case ${arg} in
|
2019-04-03 19:19:56 +02:00
|
|
|
"--"*) api_payload="$api_payload --data-urlencode \"${arg:2}\"";
|
2019-03-26 18:10:09 +01:00
|
|
|
;;
|
2019-04-03 19:19:56 +02:00
|
|
|
*) echo "incorrect argument, please use --arg=value"; usage;
|
2019-03-26 18:10:09 +01:00
|
|
|
;;
|
|
|
|
esac
|
2018-01-11 19:23:17 +01:00
|
|
|
done;
|
|
|
|
|
2019-03-26 18:10:09 +01:00
|
|
|
# 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" ouput mode -- only for specific commands such as 'channels'
|
|
|
|
if [ "$short" = true ]; then
|
2019-08-07 17:37:38 +02:00
|
|
|
jq_channel_filter="{ nodeId, shortChannelId: .data.shortChannelId, channelId, state, balanceSat: (try (.data.commitments.localCommit.spec.toLocal / 1000 | floor) catch null), capacitySat: .data.commitments.commitInput.amountSatoshis, channelPoint: .data.commitments.commitInput.outPoint }";
|
2019-03-26 18:10:09 +01:00
|
|
|
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
|
2019-04-03 19:19:56 +02:00
|
|
|
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"
|