From f0d58a83657196cfd4fafe914603f83ca03531d2 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Thu, 26 Jan 2023 11:08:40 +0100 Subject: [PATCH] Wallets: add custom invoice expiry (#1396) * expiry for fakewallet * expiry for lnd * lnbits backend * fix: eclair descriptionHash fixed and expiry added * cln and sparko * test expiry * Eclair from AdminUI and bugfix for nonexistent payments * add to settings and .env and remove lntxbot * remove duplicate and format * add invoice expiry * add min max and step * UI works now * test should fail, sanity check, will revert * revert, ready for merge Co-authored-by: Tiago Vasconcelos --- .env.example | 3 + lnbits/core/services.py | 2 + lnbits/core/templates/admin/_tab_funding.html | 58 ++++++----- lnbits/core/templates/admin/index.html | 43 ++++---- lnbits/core/templates/core/_api_docs.html | 9 +- lnbits/core/views/api.py | 2 + lnbits/settings.py | 16 ++- lnbits/wallets/cliche.py | 1 + lnbits/wallets/cln.py | 2 + lnbits/wallets/eclair.py | 97 +++++++++++-------- lnbits/wallets/fake.py | 2 + lnbits/wallets/lnbits.py | 3 + lnbits/wallets/lndgrpc.py | 5 +- lnbits/wallets/lndrest.py | 2 + lnbits/wallets/spark.py | 1 + tests/core/views/test_api.py | 15 +++ 16 files changed, 166 insertions(+), 95 deletions(-) diff --git a/.env.example b/.env.example index a367bec6b..37e62ce3e 100644 --- a/.env.example +++ b/.env.example @@ -63,6 +63,9 @@ LNBITS_BACKEND_WALLET_CLASS=VoidWallet # VoidWallet is just a fallback that works without any actual Lightning capabilities, # just so you can see the UI before dealing with this file. +# Invoice expiry for LND, CLN, Eclair, LNbits funding sources +LIGHTNING_INVOICE_EXPIRY=600 + # Set one of these blocks depending on the wallet kind you chose above: # ClicheWallet diff --git a/lnbits/core/services.py b/lnbits/core/services.py index 446645138..ee7503024 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -64,6 +64,7 @@ async def create_invoice( memo: str, description_hash: Optional[bytes] = None, unhashed_description: Optional[bytes] = None, + expiry: Optional[int] = None, extra: Optional[Dict] = None, webhook: Optional[str] = None, internal: Optional[bool] = False, @@ -79,6 +80,7 @@ async def create_invoice( memo=invoice_memo, description_hash=description_hash, unhashed_description=unhashed_description, + expiry=expiry or settings.lightning_invoice_expiry, ) if not ok: raise InvoiceFailure(error_message or "unexpected backend error.") diff --git a/lnbits/core/templates/admin/_tab_funding.html b/lnbits/core/templates/admin/_tab_funding.html index 3887e151f..35349e383 100644 --- a/lnbits/core/templates/admin/_tab_funding.html +++ b/lnbits/core/templates/admin/_tab_funding.html @@ -16,7 +16,7 @@
-
+

Active Funding (Requires server restart)

@@ -30,28 +30,40 @@
-
-
-

Fee reserve

-
-
- - -
-
- +
+
+
+

Invoice Expiry

+ + +
+
+

Fee reserve

+
+
+ + +
+
+ +
diff --git a/lnbits/core/templates/admin/index.html b/lnbits/core/templates/admin/index.html index 3e688fd65..f4d5c6010 100644 --- a/lnbits/core/templates/admin/index.html +++ b/lnbits/core/templates/admin/index.html @@ -9,6 +9,7 @@ :disabled="!checkChanges" > Save your changes + + Restart the server for changes to take effect + + Add funds to a wallet. + +
+
@@ -70,16 +77,19 @@ label="Funding" @update="val => tab = val.name" > + + +
+ {% include "admin/_tab_funding.html" %} {% include @@ -98,10 +109,12 @@
+

TopUp a wallet

+
+
+
+
+ Cancel
- {% endblock %} {% block scripts %} {{ window_vars(user) }}