LNbits updates for local dev

* persistent lnbits db with lnbits superuser
* map localhost:5001 -> lnbits:5000 in local dev for LNbits receives
* updated ATTACH.md
This commit is contained in:
ekzyis 2024-10-01 03:53:24 +02:00
parent 1d3ab23ec4
commit 75051f1c56
7 changed files with 39 additions and 26 deletions

3
.gitignore vendored
View File

@ -56,3 +56,6 @@ docker-compose.*.yml
# nostr wallet connect # nostr wallet connect
scripts/nwc-keys.json scripts/nwc-keys.json
# lnbits
docker/lnbits/data

View File

@ -586,7 +586,8 @@ services:
- 'keys-file.json' - 'keys-file.json'
cpu_shares: "${CPU_SHARES_LOW}" cpu_shares: "${CPU_SHARES_LOW}"
lnbits: lnbits:
image: lnbits/lnbits:0.12.5 build:
context: ./docker/lnbits
container_name: lnbits container_name: lnbits
profiles: profiles:
- wallets - wallets
@ -596,6 +597,7 @@ services:
depends_on: depends_on:
- stacker_lnd - stacker_lnd
environment: environment:
- LNBITS_ADMIN_UI=true
- LNBITS_BACKEND_WALLET_CLASS=LndWallet - LNBITS_BACKEND_WALLET_CLASS=LndWallet
- LND_GRPC_ENDPOINT=stacker_lnd - LND_GRPC_ENDPOINT=stacker_lnd
- LND_GRPC_PORT=10009 - LND_GRPC_PORT=10009

5
docker/lnbits/Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM lnbits/lnbits:0.12.5
COPY ["./data/database.sqlite3", "/app/data/database.sqlite3"]
COPY ["./data/.super_user", "/app/data/.super_user"]

View File

@ -0,0 +1 @@
e46288268b67457399a5fca81809573e

Binary file not shown.

View File

@ -1,27 +1,24 @@
For testing LNbits, you need to create a LNbits account first via the web interface. LNbits' database is seeded with a superuser (see https://docs.lnbits.org/guide/admin_ui.html).
By default, you can access it at `localhost:5001` (see `LNBITS_WEB_PORT` in .env.development). The following credentials were used:
After you created a wallet, you should find the invoice and admin key under `Node URL, API keys and API docs`. - username: `stackernews`
- password: `stackernews`
> [!IMPORTANT] To get access to the superuser, you need to visit the admin UI:
>
> Since your browser is running on your host machine but the server is running inside a docker container, the server will not be able to reach LNbits with `localhost:5001` to create invoices. This makes it hard to test send+receive at the same time. http://localhost:5001/wallet?usr=e46288268b67457399a5fca81809573e
>
> For now, you need to patch the `_createInvoice` function in wallets/lnbits/server.js to always use `lnbits:5000` as the URL: After that, the cookies will be set to access this wallet:
>
> ```diff http://localhost:5001/wallet?&wal=15ffe06c74cc4082a91f528d016d9028
> diff --git a/wallets/lnbits/server.js b/wallets/lnbits/server.js
> index 39949775..e3605c45 100644 Or simply copy the keys from here:
> --- a/wallets/lnbits/server.js
> +++ b/wallets/lnbits/server.js * admin key: `640cc7b031eb427c891eeaa4d9c34180`
> @@ -11,6 +11,7 @@ async function _createInvoice ({ url, invoiceKey, amount, expiry }, { me }) {
> const memo = me.hideInvoiceDesc ? undefined : 'autowithdraw to LNbits from SN' * invoice key: `5deed7cd634e4306bb5e696f4a03cdac`
> const body = JSON.stringify({ amount, unit: 'sat', expiry, memo, out: false })
> ( These keys can be found under `Node URL, API keys and API docs`. )
> + url = 'http://lnbits:5000'
> const res = await fetch(url + path, { method: 'POST', headers, body }) To use the same URL to connect to LNbits in the browser and server during local development, `localhost:<port>` is mapped to `lnbits:5000` on the server.
> if (!res.ok) {
> const errBody = await res.json()
> ```
>

View File

@ -28,9 +28,14 @@ export async function createInvoice (
out: false out: false
}) })
const hostname = url.replace(/^https?:\/\//, '') let hostname = url.replace(/^https?:\/\//, '')
const agent = getAgent({ hostname }) const agent = getAgent({ hostname })
if (process.env.NODE_ENV !== 'production' && hostname.startsWith('localhost:')) {
// to make it possible to attach LNbits for receives during local dev
hostname = 'lnbits:5000'
}
const res = await fetch(`${agent.protocol}//${hostname}${path}`, { const res = await fetch(`${agent.protocol}//${hostname}${path}`, {
method: 'POST', method: 'POST',
headers, headers,