mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-26 07:31:22 +01:00
Merge branch 'main' into diagon-alley
This commit is contained in:
commit
807eb59192
5 changed files with 42 additions and 47 deletions
|
@ -9,6 +9,7 @@ from lnurl import encode as lnurl_encode # type: ignore
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from lnbits.db import Connection
|
||||||
from lnbits.helpers import url_for
|
from lnbits.helpers import url_for
|
||||||
from lnbits.settings import WALLET
|
from lnbits.settings import WALLET
|
||||||
from lnbits.wallets.base import PaymentStatus
|
from lnbits.wallets.base import PaymentStatus
|
||||||
|
@ -131,7 +132,11 @@ class Payment(BaseModel):
|
||||||
def is_uncheckable(self) -> bool:
|
def is_uncheckable(self) -> bool:
|
||||||
return self.checking_id.startswith("internal_")
|
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
|
from .crud import update_payment_details
|
||||||
|
|
||||||
await update_payment_details(
|
await update_payment_details(
|
||||||
|
@ -139,6 +144,7 @@ class Payment(BaseModel):
|
||||||
pending=status.pending,
|
pending=status.pending,
|
||||||
fee=status.fee_msat,
|
fee=status.fee_msat,
|
||||||
preimage=status.preimage,
|
preimage=status.preimage,
|
||||||
|
conn=conn,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def set_pending(self, pending: bool) -> None:
|
async def set_pending(self, pending: bool) -> None:
|
||||||
|
@ -146,7 +152,10 @@ class Payment(BaseModel):
|
||||||
|
|
||||||
await update_payment_status(self.checking_id, pending)
|
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:
|
if self.is_uncheckable:
|
||||||
return PaymentStatus(None)
|
return PaymentStatus(None)
|
||||||
|
|
||||||
|
@ -170,7 +179,7 @@ class Payment(BaseModel):
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Marking '{'in' if self.is_in else 'out'}' {self.checking_id} as not pending anymore: {status}"
|
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
|
return status
|
||||||
|
|
||||||
async def delete(self) -> None:
|
async def delete(self) -> None:
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
outline
|
outline
|
||||||
color="grey"
|
color="grey"
|
||||||
type="a"
|
type="a"
|
||||||
href="https://github.com/lnbits/lnbits"
|
href="https://github.com/lnbits/lnbits-legend"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener"
|
rel="noopener"
|
||||||
>View project in GitHub</q-btn
|
>View project in GitHub</q-btn
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
outline
|
outline
|
||||||
color="grey"
|
color="grey"
|
||||||
type="a"
|
type="a"
|
||||||
href="https://lnbits.com/paywall/GAqKguK5S8f6w5VNjS9DfK"
|
href="https://legend.lnbits.com/paywall/GAqKguK5S8f6w5VNjS9DfK"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener"
|
rel="noopener"
|
||||||
>Donate</q-btn
|
>Donate</q-btn
|
||||||
|
|
|
@ -402,10 +402,6 @@ async def subscribe(request: Request, wallet: Wallet):
|
||||||
async def api_payments_sse(
|
async def api_payments_sse(
|
||||||
request: Request, wallet: WalletTypeInfo = Depends(get_key_type)
|
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(
|
return EventSourceResponse(
|
||||||
subscribe(request, wallet.wallet), ping=20, media_type="text/event-stream"
|
subscribe(request, wallet.wallet), ping=20, media_type="text/event-stream"
|
||||||
)
|
)
|
||||||
|
|
|
@ -138,13 +138,20 @@ async def get_key_type(
|
||||||
detail="Invoice (or Admin) key required.",
|
detail="Invoice (or Admin) key required.",
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
for typenr, WalletChecker in zip(
|
||||||
admin_checker = WalletAdminKeyChecker(api_key=token)
|
[0, 1], [WalletAdminKeyChecker, WalletInvoiceKeyChecker]
|
||||||
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
|
|
||||||
):
|
):
|
||||||
|
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(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized."
|
status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized."
|
||||||
)
|
)
|
||||||
|
@ -156,26 +163,9 @@ async def get_key_type(
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
raise
|
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(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized."
|
status_code=HTTPStatus.NOT_FOUND, detail="Wallet does not exist."
|
||||||
)
|
)
|
||||||
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(
|
async def require_admin_key(
|
||||||
|
|
|
@ -103,7 +103,7 @@ async def check_pending_payments():
|
||||||
conn=conn,
|
conn=conn,
|
||||||
)
|
)
|
||||||
for payment in pending_payments:
|
for payment in pending_payments:
|
||||||
await payment.check_status()
|
await payment.check_status(conn=conn)
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Task: pending check finished for {len(pending_payments)} payments (took {time.time() - start_time:0.3f} s)"
|
f"Task: pending check finished for {len(pending_payments)} payments (took {time.time() - start_time:0.3f} s)"
|
||||||
|
|
Loading…
Add table
Reference in a new issue