From 75051f1c5603bfd7f985b847113e0e7852c1ced2 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 1 Oct 2024 03:53:24 +0200 Subject: [PATCH] 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 --- .gitignore | 3 ++ docker-compose.yml | 4 ++- docker/lnbits/Dockerfile | 5 ++++ docker/lnbits/data/.super_user | 1 + docker/lnbits/data/database.sqlite3 | Bin 0 -> 98304 bytes wallets/lnbits/ATTACH.md | 45 +++++++++++++--------------- wallets/lnbits/server.js | 7 ++++- 7 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 docker/lnbits/Dockerfile create mode 100644 docker/lnbits/data/.super_user create mode 100644 docker/lnbits/data/database.sqlite3 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 0000000000000000000000000000000000000000..a8463c7f0d0b51fa623c01e4c3b2fbf93de63506 GIT binary patch literal 98304 zcmeI5TXP%7mB#^#B6W#HJFx<9xwJcmoFZAp3qTSVD!bk#Dew{zB*lv?$#!OYW*R`7 zgPGA>0D>w%&`Nfn^9}ZGAGWq?Kf->6JSLU*{RXM6%FA}o4Kn~p#jdE9#r$E(!1OtN zy3en>Pd7Lmox`U)%%xJpwA;j$mNFk?vf0c(Nm3@0xyS#0%>PEOPx*(j=z_mz6Q3{o zcrP>mu%%Dw|CZVzrOwXt$&~R zkBPIJf4uphW52!eaO__$GWlngfA?%+BKOHB*;$cs(%@Wzx(HpCvufa_E&N+lc-{OPD^$?#Zhf$ zxy&@2?x@0_rcjJj8Q?+<%`%z6heyo3Xc*H7-af7P2nGNyu+TD{OIvVRn>sFOTZvf` z^(CGz(~fI5gy!_r&zz}QY05CWQ!_K^z9!a=G#xoND+Mmh#A7(K{Ws&euPfOMGc)+Z{%`3ekz7QYU&3N95Ud?F%U?lU5Jo zo*dS8YU@W~M3|KhkL%N3HtT(nXk< z!3T{;IZftEfEtdNmvV7b>HRm^`xCiRDf{c6`BQq7&Zx4FQWJWV#=v}jYYgpBTlDj? z`5rIr3ud#^GHqAZXuKGMwI4GSA)TpV8|mrEdD)J%z1v@E@$@dFHHqr74vhnBI5m3!HG&! z1M-&P;LQ!OyF*>> zVAF}-KTP=^m8N``B*(L;EsNb^sDF|~HRfBEwe2=Y5Hn1!7y5W6A?7`#FZ1Vdu4JwSD$(t1GPoflRg6f^4@vl-b8L{D*NVc zihwVSob)f=AL+j@`ir>F=R}98mz?Il7oX5tg3;EG#&e%M%o2Y;Q+jfXI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ck)1V8`;KmY_l00dG5aQ{Dr0~a6w0w4eaAOHd&00JNY0w4ea zAaE@S;Qs%$99B350w4eaAOHd&00JNY0w4eaAOHd>0=WO5!hs7A009sH0T2KI5C8!X z009sH0T8&B1aSZVS`I6m0s#;J0T2KI5C8!X009sH0T2LzAp(O51Z3AHhC@`BnTAMs zFpy24OBKs=S~AZnz*7-$d46r{`O+8PoR&&kr;iI;owen;HCH#EpO9_)+W^cW$IHp67I{OXJc(!dh#d>F{_NscQuD;sbc(#2kavy}L z4dOO!)(IP(6R)+}=Ju|%f3W>*^{6I2slD(^zcT9En_H{R+G>5RzPZ+WwRu=yUg6i9 z>+9j?Zf$FAv(P2o?X}gXPn!#+%GUN?d2O**JY4bCYhM|UjgxPTmoBT6DjNr_gMDXt zQ9ag%; z;h4{aHCwL1jHb+tj>%LS%W{3xREVZ~@@E>TH{^8Ieuw8@jPxC?#@ z^RZ5{@u-kHs@grvr6R>lj8l_sUOx$8P!#$;SR9!hVJs3|+M;dpG%|9FuQ(ApUE2%t zuxRpddzaz6oSg65Wz~I!i)~Oqj!idc?(p@!OgG<@j!9Yg!VU+f88oACLhvo>>i0v`@0zgQ@Y z7JCNsS96fcD4`SOFyeaxH}GX5WsstqyeFDGEHO-%HJC~+I0T$9U3a?7Ra@NRzyYBz z;~SJq?G6!np~@nqQnZ~15iRhlO-^Nn=)_PdSG!0{BTVnfLYKGN(rnVbM497vWQDq2 z$`d^KrC8xy3uidnG)ZPpAk3;-tY%a1n2&-;;z$ zW=(@fi~yeD4|^N|{Uw#unH^93=ZnYzH*q)DB4nsc=|AL_hiG%r)q_!(2^2!{sR z95jqTv6Z!2bc)N6K3O literal 0 HcmV?d00001 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,