npubpayments/docs/lightningd.md

91 lines
3.5 KiB
Markdown
Raw Normal View History

# lightning payments
Simple payments app for core-lightning node (lightningd).
## Usage
* Start lightningd with the new rest api `--clnrest-port=3010` or configure it in `.lightning/config`
* Note that the clnrest plugin is bundled within lightningd, but its dependencies are not. You might need to `pip install -r requirements.txt` before it'll work.
* When the plugin is working, the lightningd log will show a message like `plugin-clnrest.py: REST server running at https://127.0.0.1:3010`
* Create a run with `lightning-cli commando-rune`
```shell
lightning-cli commando-rune restrictions='[["method^list", "method^get", "method=summary", "method~invoice", "method~offers"],["method/listdatastore"]]'
export RUNE=<node-rune>
curl -X GET 'http://localhost:3010/v1/list-methods' -H "Rune: ${RUNE}"
curl -k -X POST 'http://localhost:3010/v1/getinfo' -H "Rune: ${RUNE}"
curl -X POST 'http://localhost:3010/v1/listoffers' -H "Rune: ${RUNE}"
curl -X POST 'http://localhost:3010/v1/listinvoices' -H "Rune: ${RUNE}"
deno run --allow-net --unsafely-ignore-certificate-errors test.ts
```
* TODO: env var
## Resources
Swagger for lightningd will be on `https://192.168.0.42:3010`
* c-lightning-REST [API Docs](https://squirtle.satstack.net:4446/api-docs/)
* CLNRest [API Reference](https://docs.corelightning.org/reference/get_list_methods_resource)
* [CLNRest](https://docs.corelightning.org/docs/rest) has examples
## Copypasta
To run node.js in repl:
```sh
npm init -y
npm install fs socket.io-client
node
```
Paste code.
To run code in Deno:
```shell
deno repl --allow-net --unsafely-ignore-certificate-errors
```
## Decisions
### SQLite
Pros
* postgres typically wants a lot more memory, which motivates running it on a separate server
* some of our custom strfry-policies read from the same database, and strfry needs to reload the policies to import updates to the pubkey lists
* avoids introducing more failure methods, such as failing to connect to an external postgresql database
* reduces barrier to entry for other relay ops who might attempt to run the code themselves
Cons
* downsides to this choice includes increasing overhead memory requirements for the server, but the whole purpose of this code is to fund a better server anyway
* another downside is that the Deno sqlite integrations don't seem to be very mature
## Discovery Notes
Relevant methods
* Command: waitanyinvoice [lastpay_index] [timeout]
* Description: Wait for the next invoice to be paid, after {lastpay_index} (if supplied). If {timeout} seconds is reached while waiting, fail with an error.
* Command: waitinvoice label
* Description: Wait for an incoming payment matching the invoice with {label}, or if the invoice expires
* Command: listinvoices [label] [invstring] [payment_hash] [offer_id] [index] [start] [limit]
* Description: Show invoice matching {label}, {invstring}, {payment_hash} or {offerid} (or all, if no query parameter specified)
* Command: invoice amount_msat label description [expiry] [fallbacks] [preimage] [exposeprivatechannels] [cltv] [deschashonly] [dev-routes]
* Description: Create an invoice for {msatoshi} with {label} and {description} with optional {expiry} seconds (default 1 week), optional {fallbacks} address list(default empty list) and optional {preimage} (default autogenerated)
### Invoices
Generate one
```shell
lightning-cli invoice amount_msat=$((2 *1000)) label=$(openssl rand -hex 4) description="test 2" expiry=3600
curl -X POST 'http://localhost:3010/v1/listinvoices' -H "Rune: ${RUNE}"
```