alecalve / c-lightning-http-rpc

JSON RPC HTTP proxy to c-lightning's unix socket based interface.
Apache License 2.0
7 stars 7 forks source link

Quick CLI hack for the same thing for informational purposes #6

Open gr0kchain opened 5 years ago

gr0kchain commented 5 years ago

Caught wind of this on the https://www.youtube.com/watch?v=Tiyvrh53Yp8

Had a similar issue, but wasn't aware for this project :) So thanks for contributing. Here is the solution I used myself. On linux, c-lightning exposes it's rpc interface via a unix domain socket, you can communicate to this directly as follows

nc -U ~/.lightning/lightning-rpc

The provide the following JSON rpc request

{ "method" : "getinfo", "params" : [], "id" : "1" }

It's a bit pedantic on JSON parse errors and will segfaults on any format issues

To expose this over a TCP socket try

socat TCP-LISTEN:12345 UNIX-CONNECT:/path/to/.lightning/lightning-rpc

Then you can pass these rpc commands over the raw socket

Think you can also set this up via trivial cli over http, or configure it via something like nginx

{
  server unix:/path/to/.lightning/lightning-rpc
}

server {
  listen 80;

  location / {
    proxy_pass http://myapp;
  }
}

Docker example on their readme has some info on how to do this via containers

Alternatively you can fire up something like lightning charge https://github.com/ElementsProject/lightning-charge

alecalve commented 5 years ago

Thanks for sharing!

This is definitly an interesting solution to expose the API via HTTP and less heavy than running a JAR file.