Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/conscott/get-lightning-paid

Simple Flask API for generating c-lightning invoices and detecting payment using pylightning
https://github.com/conscott/get-lightning-paid

Last synced: about 1 month ago
JSON representation

Simple Flask API for generating c-lightning invoices and detecting payment using pylightning

Awesome Lists containing this project

README

        

## Description

A simple Flask REST API to generate lightning invoices and wait for payment confirmation / check invoice status. This is experimential fun and not enterprise ready. *Use with caution!*

### Files
* API implementation in [app.py](./app.py)
* Sample usage in script [gen_invoice_and_pay.py](./gen_invoice_and_pay.py)

The app requires a locally running version of [c-lightning](https://github.com/ElementsProject/lightning)

### Install Environment
```
sudo apt-get install python3-dev
python3 -v venv venv
source venv/bin/activate
pip install -r requirements.txt
```

### Run Server

For development/test server
```
./run_dev.sh
```

For production server using uWSGI
```
./run_prod.sh
```
You can tweak uwsgi configuration in [uwsgi.ini](./uwsgi.ini)

## API

### Generate Invoice

#### POST /api/generate_invoice
```
{
"msatoshi": (required)
"description": (optional, defatul '')
"expiry": (optional, default 600)
}
```

#### Response
```
{
"payment_hash":
"expires_at":
"bolt11":
"label":
}
```

Note the `label` is needed to check invoice status later

### Check Invoice

#### GET /api/check_invoice/\
Check the status of the invoice with the given `label`

#### Response
```
{
"status": "paid|unpaid|expired"
"expires_at":
}
```

### Wait For Invoice Payment

#### GET /api/wait_invoice/\

Will wait until the invoice associated with the label has been paid

#### Response
```
{
"label":
"bolt11":
"payment_hash":
"msatoshi":
"status": "paid",
"pay_index":
"msatoshi_received":
"paid_at":
"description":
"expires_at":
}
```

### Try it out

Check out the script [gen_invoice_and_pay.py](./gen_invoice_and_pay.py) to see a sample backend flow