diff --git a/.gitignore b/.gitignore index b0e257af..ceb04b51 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ docker-compose.*.yml # nostr wallet connect scripts/nwc-keys.json + +# lnbits +docker/lnbits/data \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b3f3a9b5..baae9a40 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -586,7 +586,8 @@ services: - 'keys-file.json' cpu_shares: "${CPU_SHARES_LOW}" lnbits: - image: lnbits/lnbits:0.12.5 + build: + context: ./docker/lnbits container_name: lnbits profiles: - wallets @@ -596,6 +597,7 @@ services: depends_on: - stacker_lnd environment: + - LNBITS_ADMIN_UI=true - LNBITS_BACKEND_WALLET_CLASS=LndWallet - LND_GRPC_ENDPOINT=stacker_lnd - LND_GRPC_PORT=10009 diff --git a/docker/lnbits/Dockerfile b/docker/lnbits/Dockerfile new file mode 100644 index 00000000..099d7b82 --- /dev/null +++ b/docker/lnbits/Dockerfile @@ -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"] \ No newline at end of file diff --git a/docker/lnbits/data/.super_user b/docker/lnbits/data/.super_user new file mode 100644 index 00000000..1d7c4f33 --- /dev/null +++ b/docker/lnbits/data/.super_user @@ -0,0 +1 @@ +e46288268b67457399a5fca81809573e \ No newline at end of file diff --git a/docker/lnbits/data/database.sqlite3 b/docker/lnbits/data/database.sqlite3 new file mode 100644 index 00000000..a8463c7f Binary files /dev/null and b/docker/lnbits/data/database.sqlite3 differ diff --git a/wallets/lnbits/ATTACH.md b/wallets/lnbits/ATTACH.md index b34a213b..baafa1bf 100644 --- a/wallets/lnbits/ATTACH.md +++ b/wallets/lnbits/ATTACH.md @@ -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] -> -> 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. -> -> For now, you need to patch the `_createInvoice` function in wallets/lnbits/server.js to always use `lnbits:5000` as the URL: -> -> ```diff -> diff --git a/wallets/lnbits/server.js b/wallets/lnbits/server.js -> index 39949775..e3605c45 100644 -> --- a/wallets/lnbits/server.js -> +++ b/wallets/lnbits/server.js -> @@ -11,6 +11,7 @@ async function _createInvoice ({ url, invoiceKey, amount, expiry }, { me }) { -> const memo = me.hideInvoiceDesc ? undefined : 'autowithdraw to LNbits from SN' -> const body = JSON.stringify({ amount, unit: 'sat', expiry, memo, out: false }) -> -> + url = 'http://lnbits:5000' -> const res = await fetch(url + path, { method: 'POST', headers, body }) -> if (!res.ok) { -> const errBody = await res.json() -> ``` -> +To get access to the superuser, you need to visit the admin UI: + +http://localhost:5001/wallet?usr=e46288268b67457399a5fca81809573e + +After that, the cookies will be set to access this wallet: + +http://localhost:5001/wallet?&wal=15ffe06c74cc4082a91f528d016d9028 + +Or simply copy the keys from here: + +* admin key: `640cc7b031eb427c891eeaa4d9c34180` + +* invoice key: `5deed7cd634e4306bb5e696f4a03cdac` + +( These keys can be found under `Node URL, API keys and API docs`. ) + +To use the same URL to connect to LNbits in the browser and server during local development, `localhost:` is mapped to `lnbits:5000` on the server. diff --git a/wallets/lnbits/server.js b/wallets/lnbits/server.js index 23c8ba88..768990db 100644 --- a/wallets/lnbits/server.js +++ b/wallets/lnbits/server.js @@ -28,9 +28,14 @@ export async function createInvoice ( out: false }) - const hostname = url.replace(/^https?:\/\//, '') + let hostname = url.replace(/^https?:\/\//, '') 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}`, { method: 'POST', headers,