From e5644ec4f6fb740e84d711f81adfb6c7ca9b0dd8 Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Mon, 5 Sep 2022 11:47:27 +0100 Subject: [PATCH 01/21] show a dismissable notification after payment succeed --- .../extensions/tpos/templates/tpos/tpos.html | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index 98334e55..40da0068 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -253,7 +253,7 @@ name="check" transition-show="fade" class="text-light-green" - style="font-size: 40em" + style="font-size: min(90vw, 40em)" > @@ -413,9 +413,19 @@ dialog.show = false self.complete.show = true - setTimeout(function () { - self.complete.show = false - }, 5000) + self.$q.notify({ + type: 'positive', + message: 'Sats received, thanks!', + icon: 'thumb_up', + timeout: 0, + actions: [ + { + label: 'Dismiss', + color: 'white', + handler: () => (self.complete.show = false) + } + ] + }) } }) }, 3000) From ddc3ec7e2f52a75bd674f7aa1635b2bb8795674e Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Mon, 5 Sep 2022 11:55:24 +0100 Subject: [PATCH 02/21] add a tooltip and label for adding tip options --- lnbits/extensions/tpos/templates/tpos/index.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lnbits/extensions/tpos/templates/tpos/index.html b/lnbits/extensions/tpos/templates/tpos/index.html index edbb2aa8..3c4fa24f 100644 --- a/lnbits/extensions/tpos/templates/tpos/index.html +++ b/lnbits/extensions/tpos/templates/tpos/index.html @@ -138,8 +138,9 @@ hide-dropdown-icon input-debounce="0" new-value-mode="add-unique" - label="Tip % Options" - > + label="Tip % Options (hit enter to add values)" + >Hit enter to add values
Date: Mon, 5 Sep 2022 12:54:37 +0100 Subject: [PATCH 03/21] update event data on ticket sold --- lnbits/extensions/events/crud.py | 45 ++++++++++---------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/lnbits/extensions/events/crud.py b/lnbits/extensions/events/crud.py index 4cc86ac4..12cc7327 100644 --- a/lnbits/extensions/events/crud.py +++ b/lnbits/extensions/events/crud.py @@ -19,42 +19,25 @@ async def create_ticket( (payment_hash, wallet, event, name, email, False, True), ) + # UPDATE EVENT DATA ON SOLD TICKET + eventdata = await get_event(event) + assert eventdata, "Couldn't get event from ticket being paid" + sold = eventdata.sold + 1 + amount_tickets = eventdata.amount_tickets - 1 + await db.execute( + """ + UPDATE events.events + SET sold = ?, amount_tickets = ? + WHERE id = ? + """, + (sold, amount_tickets, event), + ) + ticket = await get_ticket(payment_hash) assert ticket, "Newly created ticket couldn't be retrieved" return ticket -async def set_ticket_paid(payment_hash: str) -> Tickets: - row = await db.fetchone("SELECT * FROM events.ticket WHERE id = ?", (payment_hash,)) - if row[6] != True: - await db.execute( - """ - UPDATE events.ticket - SET paid = true - WHERE id = ? - """, - (payment_hash,), - ) - - eventdata = await get_event(row[2]) - assert eventdata, "Couldn't get event from ticket being paid" - - sold = eventdata.sold + 1 - amount_tickets = eventdata.amount_tickets - 1 - await db.execute( - """ - UPDATE events.events - SET sold = ?, amount_tickets = ? - WHERE id = ? - """, - (sold, amount_tickets, row[2]), - ) - - ticket = await get_ticket(payment_hash) - assert ticket, "Newly updated ticket couldn't be retrieved" - return ticket - - async def get_ticket(payment_hash: str) -> Optional[Tickets]: row = await db.fetchone("SELECT * FROM events.ticket WHERE id = ?", (payment_hash,)) return Tickets(**row) if row else None From dc6098e1ca77aaf2150d1a96fd0f370893441eaa Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Mon, 5 Sep 2022 12:56:40 +0100 Subject: [PATCH 04/21] remove call to set ticket paid --- lnbits/extensions/events/views_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lnbits/extensions/events/views_api.py b/lnbits/extensions/events/views_api.py index 56e6b06c..9cb18f04 100644 --- a/lnbits/extensions/events/views_api.py +++ b/lnbits/extensions/events/views_api.py @@ -24,7 +24,6 @@ from .crud import ( get_ticket, get_tickets, reg_ticket, - set_ticket_paid, update_event, ) From 01773160753abcdfdb1b6771f93a4326dd8f4672 Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Wed, 7 Sep 2022 16:39:08 +0100 Subject: [PATCH 05/21] display NFC button on supported and fix null tip options --- lnbits/extensions/tpos/templates/tpos/tpos.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index 40da0068..bcd312e3 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -175,6 +175,7 @@ {% endraw %} From d1eb0b0c4d1552b62089fbb1941934c4a717ae94 Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Wed, 7 Sep 2022 16:43:47 +0100 Subject: [PATCH 06/21] rollback on removing NFC button --- lnbits/extensions/tpos/templates/tpos/tpos.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index bcd312e3..f88a8f7a 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -175,7 +175,6 @@ {% endraw %} From fad040edf19513a1453f25ebe9bc752fe5f90e83 Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Mon, 12 Sep 2022 08:49:12 +0100 Subject: [PATCH 07/21] remove toast - click checkmark to dismiss --- lnbits/extensions/tpos/templates/tpos/tpos.html | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html index f88a8f7a..ad04b3be 100644 --- a/lnbits/extensions/tpos/templates/tpos/tpos.html +++ b/lnbits/extensions/tpos/templates/tpos/tpos.html @@ -414,19 +414,6 @@ dialog.show = false self.complete.show = true - self.$q.notify({ - type: 'positive', - message: 'Sats received, thanks!', - icon: 'thumb_up', - timeout: 0, - actions: [ - { - label: 'Dismiss', - color: 'white', - handler: () => (self.complete.show = false) - } - ] - }) } }) }, 3000) From 8c75ea600fd0a6c14e07207690c515d64cdb18ca Mon Sep 17 00:00:00 2001 From: Gene Takavic <80261724+iWarpBTC@users.noreply.github.com> Date: Mon, 12 Sep 2022 10:17:45 +0200 Subject: [PATCH 08/21] fix for uppercase QR --- lnbits/core/static/js/wallet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lnbits/core/static/js/wallet.js b/lnbits/core/static/js/wallet.js index 1c417eaf..e62c1a6d 100644 --- a/lnbits/core/static/js/wallet.js +++ b/lnbits/core/static/js/wallet.js @@ -369,9 +369,9 @@ new Vue({ decodeRequest: function () { this.parse.show = true let req = this.parse.data.request.toLowerCase() - if (this.parse.data.request.startsWith('lightning:')) { + if (this.parse.data.request.toLowerCase().startsWith('lightning:')) { this.parse.data.request = this.parse.data.request.slice(10) - } else if (this.parse.data.request.startsWith('lnurl:')) { + } else if (this.parse.data.request.toLowerCase().startsWith('lnurl:')) { this.parse.data.request = this.parse.data.request.slice(6) } else if (req.indexOf('lightning=lnurl1') !== -1) { this.parse.data.request = this.parse.data.request From b8531f9e0e707dd604fb61e093371abad68ba736 Mon Sep 17 00:00:00 2001 From: Aaron Dewes Date: Mon, 12 Sep 2022 12:32:03 +0200 Subject: [PATCH 09/21] Change message about login functionality According to the README, Lnbits is already at 0.9. Claiming a feature will be added in 0.2 doesn't make sense. --- lnbits/core/templates/core/wallet.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/core/templates/core/wallet.html b/lnbits/core/templates/core/wallet.html index bd2668d1..bccdc2b4 100644 --- a/lnbits/core/templates/core/wallet.html +++ b/lnbits/core/templates/core/wallet.html @@ -711,7 +711,7 @@
Warning

- Login functionality to be released in v0.2, for now, + Login functionality to be released in a future update, for now, make sure you bookmark this page for future access to your wallet Date: Mon, 12 Sep 2022 18:39:53 +0300 Subject: [PATCH 10/21] API key check: assert that wallet exists (#961) * check if wallet exists * check wallet existence in key check --- lnbits/core/views/api.py | 4 --- lnbits/decorators.py | 64 +++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 830cc16a..af453f03 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -402,10 +402,6 @@ async def subscribe(request: Request, wallet: Wallet): async def api_payments_sse( request: Request, wallet: WalletTypeInfo = Depends(get_key_type) ): - if wallet is None or wallet.wallet is None: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist." - ) return EventSourceResponse( subscribe(request, wallet.wallet), ping=20, media_type="text/event-stream" ) diff --git a/lnbits/decorators.py b/lnbits/decorators.py index 69b26fe7..8b8ebd55 100644 --- a/lnbits/decorators.py +++ b/lnbits/decorators.py @@ -138,44 +138,34 @@ async def get_key_type( detail="Invoice (or Admin) key required.", ) - try: - admin_checker = WalletAdminKeyChecker(api_key=token) - await admin_checker.__call__(r) - wallet = WalletTypeInfo(0, admin_checker.wallet) # type: ignore - if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and ( - LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS - ): - raise HTTPException( - status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." - ) - return wallet - except HTTPException as e: - if e.status_code == HTTPStatus.BAD_REQUEST: + for typenr, WalletChecker in zip( + [0, 1], [WalletAdminKeyChecker, WalletInvoiceKeyChecker] + ): + try: + checker = WalletChecker(api_key=token) + await checker.__call__(r) + wallet = WalletTypeInfo(typenr, checker.wallet) # type: ignore + if wallet is None or wallet.wallet is None: + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist." + ) + if ( + LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS + ) and (LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS): + raise HTTPException( + status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." + ) + return wallet + except HTTPException as e: + if e.status_code == HTTPStatus.BAD_REQUEST: + raise + if e.status_code == HTTPStatus.UNAUTHORIZED: + pass + except: raise - if e.status_code == HTTPStatus.UNAUTHORIZED: - pass - except: - raise - - try: - invoice_checker = WalletInvoiceKeyChecker(api_key=token) - await invoice_checker.__call__(r) - wallet = WalletTypeInfo(1, invoice_checker.wallet) # type: ignore - if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and ( - LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS - ): - raise HTTPException( - status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." - ) - return wallet - except HTTPException as e: - if e.status_code == HTTPStatus.BAD_REQUEST: - raise - if e.status_code == HTTPStatus.UNAUTHORIZED: - return WalletTypeInfo(2, None) # type: ignore - except: - raise - return wallet + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist." + ) async def require_admin_key( From 57fffa0c7f569ea05a814d47ef3d66aace3297d3 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Mon, 12 Sep 2022 18:41:27 +0300 Subject: [PATCH 11/21] Revert "API key check: assert that wallet exists (#961)" (#962) This reverts commit 0930fca7ec03382c19d63b8e6da4fd02791fcf8e. --- lnbits/core/views/api.py | 4 +++ lnbits/decorators.py | 64 +++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index af453f03..830cc16a 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -402,6 +402,10 @@ async def subscribe(request: Request, wallet: Wallet): async def api_payments_sse( request: Request, wallet: WalletTypeInfo = Depends(get_key_type) ): + if wallet is None or wallet.wallet is None: + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist." + ) return EventSourceResponse( subscribe(request, wallet.wallet), ping=20, media_type="text/event-stream" ) diff --git a/lnbits/decorators.py b/lnbits/decorators.py index 8b8ebd55..69b26fe7 100644 --- a/lnbits/decorators.py +++ b/lnbits/decorators.py @@ -138,34 +138,44 @@ async def get_key_type( detail="Invoice (or Admin) key required.", ) - for typenr, WalletChecker in zip( - [0, 1], [WalletAdminKeyChecker, WalletInvoiceKeyChecker] - ): - try: - checker = WalletChecker(api_key=token) - await checker.__call__(r) - wallet = WalletTypeInfo(typenr, checker.wallet) # type: ignore - if wallet is None or wallet.wallet is None: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist." - ) - if ( - LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS - ) and (LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS): - raise HTTPException( - status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." - ) - return wallet - except HTTPException as e: - if e.status_code == HTTPStatus.BAD_REQUEST: - raise - if e.status_code == HTTPStatus.UNAUTHORIZED: - pass - except: + try: + admin_checker = WalletAdminKeyChecker(api_key=token) + await admin_checker.__call__(r) + wallet = WalletTypeInfo(0, admin_checker.wallet) # type: ignore + if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and ( + LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS + ): + raise HTTPException( + status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." + ) + return wallet + except HTTPException as e: + if e.status_code == HTTPStatus.BAD_REQUEST: raise - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist." - ) + if e.status_code == HTTPStatus.UNAUTHORIZED: + pass + except: + raise + + try: + invoice_checker = WalletInvoiceKeyChecker(api_key=token) + await invoice_checker.__call__(r) + wallet = WalletTypeInfo(1, invoice_checker.wallet) # type: ignore + if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and ( + LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS + ): + raise HTTPException( + status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." + ) + return wallet + except HTTPException as e: + if e.status_code == HTTPStatus.BAD_REQUEST: + raise + if e.status_code == HTTPStatus.UNAUTHORIZED: + return WalletTypeInfo(2, None) # type: ignore + except: + raise + return wallet async def require_admin_key( From 1660b9dcf1f3c17af1b7d7a894f6ce06359ca578 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Mon, 12 Sep 2022 18:49:57 +0300 Subject: [PATCH 12/21] Revert "Revert "API key check: assert that wallet exists (#961)" (#962)" (#963) This reverts commit 57fffa0c7f569ea05a814d47ef3d66aace3297d3. --- lnbits/core/views/api.py | 4 --- lnbits/decorators.py | 64 +++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/lnbits/core/views/api.py b/lnbits/core/views/api.py index 830cc16a..af453f03 100644 --- a/lnbits/core/views/api.py +++ b/lnbits/core/views/api.py @@ -402,10 +402,6 @@ async def subscribe(request: Request, wallet: Wallet): async def api_payments_sse( request: Request, wallet: WalletTypeInfo = Depends(get_key_type) ): - if wallet is None or wallet.wallet is None: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist." - ) return EventSourceResponse( subscribe(request, wallet.wallet), ping=20, media_type="text/event-stream" ) diff --git a/lnbits/decorators.py b/lnbits/decorators.py index 69b26fe7..8b8ebd55 100644 --- a/lnbits/decorators.py +++ b/lnbits/decorators.py @@ -138,44 +138,34 @@ async def get_key_type( detail="Invoice (or Admin) key required.", ) - try: - admin_checker = WalletAdminKeyChecker(api_key=token) - await admin_checker.__call__(r) - wallet = WalletTypeInfo(0, admin_checker.wallet) # type: ignore - if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and ( - LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS - ): - raise HTTPException( - status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." - ) - return wallet - except HTTPException as e: - if e.status_code == HTTPStatus.BAD_REQUEST: + for typenr, WalletChecker in zip( + [0, 1], [WalletAdminKeyChecker, WalletInvoiceKeyChecker] + ): + try: + checker = WalletChecker(api_key=token) + await checker.__call__(r) + wallet = WalletTypeInfo(typenr, checker.wallet) # type: ignore + if wallet is None or wallet.wallet is None: + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist." + ) + if ( + LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS + ) and (LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS): + raise HTTPException( + status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." + ) + return wallet + except HTTPException as e: + if e.status_code == HTTPStatus.BAD_REQUEST: + raise + if e.status_code == HTTPStatus.UNAUTHORIZED: + pass + except: raise - if e.status_code == HTTPStatus.UNAUTHORIZED: - pass - except: - raise - - try: - invoice_checker = WalletInvoiceKeyChecker(api_key=token) - await invoice_checker.__call__(r) - wallet = WalletTypeInfo(1, invoice_checker.wallet) # type: ignore - if (LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS) and ( - LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS - ): - raise HTTPException( - status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." - ) - return wallet - except HTTPException as e: - if e.status_code == HTTPStatus.BAD_REQUEST: - raise - if e.status_code == HTTPStatus.UNAUTHORIZED: - return WalletTypeInfo(2, None) # type: ignore - except: - raise - return wallet + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist." + ) async def require_admin_key( From d0ca0b18da5a62a9bd10a466a798f6a4b1c61cc2 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Mon, 12 Sep 2022 20:57:23 +0300 Subject: [PATCH 13/21] Fix/db reuse connection mark pending (#964) * check if wallet exists * check wallet existence in key check * reuse connection for stataus update * make format --- lnbits/core/models.py | 15 ++++++++++++--- lnbits/tasks.py | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lnbits/core/models.py b/lnbits/core/models.py index 4dc15bbc..219380c8 100644 --- a/lnbits/core/models.py +++ b/lnbits/core/models.py @@ -9,6 +9,7 @@ from lnurl import encode as lnurl_encode # type: ignore from loguru import logger from pydantic import BaseModel +from lnbits.db import Connection from lnbits.helpers import url_for from lnbits.settings import WALLET from lnbits.wallets.base import PaymentStatus @@ -131,7 +132,11 @@ class Payment(BaseModel): def is_uncheckable(self) -> bool: return self.checking_id.startswith("internal_") - async def update_status(self, status: PaymentStatus) -> None: + async def update_status( + self, + status: PaymentStatus, + conn: Optional[Connection] = None, + ) -> None: from .crud import update_payment_details await update_payment_details( @@ -139,6 +144,7 @@ class Payment(BaseModel): pending=status.pending, fee=status.fee_msat, preimage=status.preimage, + conn=conn, ) async def set_pending(self, pending: bool) -> None: @@ -146,7 +152,10 @@ class Payment(BaseModel): await update_payment_status(self.checking_id, pending) - async def check_status(self) -> PaymentStatus: + async def check_status( + self, + conn: Optional[Connection] = None, + ) -> PaymentStatus: if self.is_uncheckable: return PaymentStatus(None) @@ -170,7 +179,7 @@ class Payment(BaseModel): logger.info( f"Marking '{'in' if self.is_in else 'out'}' {self.checking_id} as not pending anymore: {status}" ) - await self.update_status(status) + await self.update_status(status, conn=conn) return status async def delete(self) -> None: diff --git a/lnbits/tasks.py b/lnbits/tasks.py index 078edca1..41287ff2 100644 --- a/lnbits/tasks.py +++ b/lnbits/tasks.py @@ -103,7 +103,7 @@ async def check_pending_payments(): conn=conn, ) for payment in pending_payments: - await payment.check_status() + await payment.check_status(conn=conn) logger.debug( f"Task: pending check finished for {len(pending_payments)} payments (took {time.time() - start_time:0.3f} s)" From 7ee6d09585849054f19512b90ca76f842ddb6546 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Tue, 13 Sep 2022 16:24:30 +0300 Subject: [PATCH 14/21] feat: add link for `hardware-wallet` browser flash --- .../templates/watchonly/_api_docs.html | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/watchonly/templates/watchonly/_api_docs.html b/lnbits/extensions/watchonly/templates/watchonly/_api_docs.html index db0811f5..ba52c4fa 100644 --- a/lnbits/extensions/watchonly/templates/watchonly/_api_docs.html +++ b/lnbits/extensions/watchonly/templates/watchonly/_api_docs.html @@ -3,23 +3,36 @@

Onchain Wallet (watch-only) extension uses mempool.space
For use with "account Extended Public Key" - https://iancoleman.io/bip39/ + https://iancoleman.io/bip39/ +
+ Flash binaries + directly from browser
Created by, - Ben Arc (using, Embit
)

- Swagger REST API Documentation

From 232d50baaa03c29da712c4158f7635853ad3f1bb Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Thu, 15 Sep 2022 14:48:59 +0300 Subject: [PATCH 15/21] Fix: tasks.py reuse db connection for invoice deletion (#971) * check if wallet exists * check wallet existence in key check * reuse db connection for payment deletion --- lnbits/core/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lnbits/core/models.py b/lnbits/core/models.py index 219380c8..216acafd 100644 --- a/lnbits/core/models.py +++ b/lnbits/core/models.py @@ -174,7 +174,7 @@ class Payment(BaseModel): logger.warning( f"Deleting outgoing failed payment {self.checking_id}: {status}" ) - await self.delete() + await self.delete(conn) elif not status.pending: logger.info( f"Marking '{'in' if self.is_in else 'out'}' {self.checking_id} as not pending anymore: {status}" @@ -182,10 +182,10 @@ class Payment(BaseModel): await self.update_status(status, conn=conn) return status - async def delete(self) -> None: + async def delete(self, conn: Optional[Connection] = None) -> None: from .crud import delete_payment - await delete_payment(self.checking_id) + await delete_payment(self.checking_id, conn=conn) class BalanceCheck(BaseModel): From e7a6e86e7add238dce56f438aab491893e329a7e Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Sun, 18 Sep 2022 16:27:03 +0300 Subject: [PATCH 16/21] Fix/duplicate payments (#973) * check if wallet exists * check wallet existence in key check * fix duplicate removal --- lnbits/core/crud.py | 9 +++++++++ lnbits/core/services.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index 4122f902..ecc27a9c 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -452,6 +452,15 @@ async def delete_payment(checking_id: str, conn: Optional[Connection] = None) -> ) +async def delete_wallet_payment( + checking_id: str, wallet_id: str, conn: Optional[Connection] = None +) -> None: + await (conn or db).execute( + "DELETE FROM apipayments WHERE checking_id = ? AND wallet = ?", + (checking_id, wallet_id), + ) + + async def check_internal( payment_hash: str, conn: Optional[Connection] = None ) -> Optional[str]: diff --git a/lnbits/core/services.py b/lnbits/core/services.py index a6e0b43a..10693f4b 100644 --- a/lnbits/core/services.py +++ b/lnbits/core/services.py @@ -28,7 +28,7 @@ from . import db from .crud import ( check_internal, create_payment, - delete_payment, + delete_wallet_payment, get_wallet, get_wallet_payment, update_payment_details, @@ -221,7 +221,7 @@ async def pay_invoice( logger.warning(f"backend sent payment failure") async with db.connect() as conn: logger.debug(f"deleting temporary payment {temp_id}") - await delete_payment(temp_id, conn=conn) + await delete_wallet_payment(temp_id, wallet_id, conn=conn) raise PaymentFailure( f"payment failed: {payment.error_message}" or "payment failed, but backend didn't give us an error message" From dd443925c242a8b268faba6320536c457d5db9f2 Mon Sep 17 00:00:00 2001 From: dasrecord <50388266+dasrecord@users.noreply.github.com> Date: Mon, 19 Sep 2022 15:56:32 -0700 Subject: [PATCH 17/21] Update wordlists.py spelling correction --- lnbits/extensions/offlineshop/wordlists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/extensions/offlineshop/wordlists.py b/lnbits/extensions/offlineshop/wordlists.py index ee3663e3..f690dca9 100644 --- a/lnbits/extensions/offlineshop/wordlists.py +++ b/lnbits/extensions/offlineshop/wordlists.py @@ -11,7 +11,7 @@ animals = [ "jaguar", "koala", "llama", - "macaroni penguim", + "macaroni penguin", "numbat", "octopus", "platypus", From c341a6419096da78c6ccbaeb957c578393028da9 Mon Sep 17 00:00:00 2001 From: dasrecord <50388266+dasrecord@users.noreply.github.com> Date: Mon, 19 Sep 2022 15:58:33 -0700 Subject: [PATCH 18/21] Update wordlists.py another spelling correction --- lnbits/extensions/offlineshop/wordlists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/extensions/offlineshop/wordlists.py b/lnbits/extensions/offlineshop/wordlists.py index ee3663e3..085e25bb 100644 --- a/lnbits/extensions/offlineshop/wordlists.py +++ b/lnbits/extensions/offlineshop/wordlists.py @@ -5,7 +5,7 @@ animals = [ "duck", "eagle", "flamingo", - "gorila", + "gorilla", "hamster", "iguana", "jaguar", From 9041c75eb6df1dc725c7eaf1b1aa0d7b17b83004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Tue, 20 Sep 2022 12:22:17 +0200 Subject: [PATCH 19/21] fix docker deploy --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c4fcb959..fed097d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM python:3.9-slim +RUN apt-get clean RUN apt-get update -RUN apt-get install -y curl +RUN apt-get install -y curl pkg-config build-essential RUN curl -sSL https://install.python-poetry.org | python3 - ENV PATH="/root/.local/bin:$PATH" WORKDIR /app From a9084a09f71fe601a824abd0da9578549580e1ff Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Tue, 20 Sep 2022 15:08:45 +0300 Subject: [PATCH 20/21] Docs/install docs (#983) * check if wallet exists * check wallet existence in key check * update install docs --- docs/guide/installation.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/guide/installation.md b/docs/guide/installation.md index 6f9d0d4f..2b058754 100644 --- a/docs/guide/installation.md +++ b/docs/guide/installation.md @@ -12,6 +12,8 @@ By default, LNbits will use SQLite as its database. You can also use PostgreSQL ## Option 1 (recommended): poetry +If you have problems installing LNbits using these instructions, please have a look at the [Troubleshooting](#troubleshooting) section. + ```sh git clone https://github.com/lnbits/lnbits-legend.git cd lnbits-legend/ @@ -26,12 +28,11 @@ curl -sSL https://install.python-poetry.org | python3 - export PATH="/home/ubuntu/.local/bin:$PATH" # or whatever is suggested in the poetry install notes printed to terminal poetry env use python3.9 poetry install --no-dev +poetry run python build.py mkdir data cp .env.example .env -sudo nano .env # set funding source - - +nano .env # set funding source ``` #### Running the server @@ -176,13 +177,15 @@ Problems installing? These commands have helped us install LNbits. ```sh sudo apt install pkg-config libffi-dev libpq-dev +# build essentials for debian/ubuntu +sudo apt install python3.9-dev gcc build-essential + # if the secp256k1 build fails: -# if you used venv -./venv/bin/pip install setuptools wheel # if you used poetry poetry add setuptools wheel -# build essentials for debian/ubuntu -sudo apt install python3-dev gcc build-essential + +# if you used venv +./venv/bin/pip install setuptools wheel ``` ### Optional: PostgreSQL database From c5cc65a736606a6906a2e17adcfbceb33ddfedb6 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Tue, 20 Sep 2022 15:34:03 +0300 Subject: [PATCH 21/21] Fix/admin extension exception (#984) * check if wallet exists * check wallet existence in key check * return FORBIDDEN for LNBITS_ADMIN_USERS --- lnbits/decorators.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lnbits/decorators.py b/lnbits/decorators.py index 8b8ebd55..d4aa63ae 100644 --- a/lnbits/decorators.py +++ b/lnbits/decorators.py @@ -153,14 +153,18 @@ async def get_key_type( LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS ) and (LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS): raise HTTPException( - status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." + status_code=HTTPStatus.FORBIDDEN, + detail="User not authorized for this extension.", ) return wallet except HTTPException as e: if e.status_code == HTTPStatus.BAD_REQUEST: raise - if e.status_code == HTTPStatus.UNAUTHORIZED: + elif e.status_code == HTTPStatus.UNAUTHORIZED: + # we pass this in case it is not an invoice key, nor an admin key, and then return NOT_FOUND at the end of this block pass + else: + raise except: raise raise HTTPException(