mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-10 20:42:32 +02:00
Merge remote-tracking branch 'lnbits/main' into fix/tpos_dismiss_btn
This commit is contained in:
@@ -10,7 +10,7 @@ You can choose between four package managers, `poetry`, `nix` and `venv`.
|
|||||||
|
|
||||||
By default, LNbits will use SQLite as its database. You can also use PostgreSQL which is recommended for applications with a high load (see guide below).
|
By default, LNbits will use SQLite as its database. You can also use PostgreSQL which is recommended for applications with a high load (see guide below).
|
||||||
|
|
||||||
## Option 1: poetry
|
## Option 1 (recommended): poetry
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://github.com/lnbits/lnbits-legend.git
|
git clone https://github.com/lnbits/lnbits-legend.git
|
||||||
|
@@ -327,6 +327,7 @@ async def delete_expired_invoices(
|
|||||||
AND amount > 0 AND time < {db.timestamp_now} - {db.interval_seconds(86400)}
|
AND amount > 0 AND time < {db.timestamp_now} - {db.interval_seconds(86400)}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
logger.debug(f"Checking expiry of {len(rows)} invoices")
|
||||||
for (payment_request,) in rows:
|
for (payment_request,) in rows:
|
||||||
try:
|
try:
|
||||||
invoice = bolt11.decode(payment_request)
|
invoice = bolt11.decode(payment_request)
|
||||||
@@ -336,7 +337,9 @@ async def delete_expired_invoices(
|
|||||||
expiration_date = datetime.datetime.fromtimestamp(invoice.date + invoice.expiry)
|
expiration_date = datetime.datetime.fromtimestamp(invoice.date + invoice.expiry)
|
||||||
if expiration_date > datetime.datetime.utcnow():
|
if expiration_date > datetime.datetime.utcnow():
|
||||||
continue
|
continue
|
||||||
logger.debug(f"Deleting expired invoice: {invoice.payment_hash}")
|
logger.debug(
|
||||||
|
f"Deleting expired invoice: {invoice.payment_hash} (expired: {expiration_date})"
|
||||||
|
)
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
"""
|
"""
|
||||||
DELETE FROM apipayments
|
DELETE FROM apipayments
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import secrets
|
import secrets
|
||||||
|
from datetime import date, datetime
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
@@ -6,7 +7,6 @@ from lnbits.helpers import urlsafe_short_hash
|
|||||||
from . import db
|
from . import db
|
||||||
from .models import Card, CreateCardData, Hit, Refund
|
from .models import Card, CreateCardData, Hit, Refund
|
||||||
|
|
||||||
from datetime import date, datetime
|
|
||||||
|
|
||||||
async def create_card(data: CreateCardData, wallet_id: str) -> Card:
|
async def create_card(data: CreateCardData, wallet_id: str) -> Card:
|
||||||
card_id = urlsafe_short_hash().upper()
|
card_id = urlsafe_short_hash().upper()
|
||||||
@@ -181,7 +181,8 @@ async def get_hits(cards_ids: Union[str, List[str]]) -> List[Hit]:
|
|||||||
|
|
||||||
async def get_hits_today(card_id: str) -> Optional[Hit]:
|
async def get_hits_today(card_id: str) -> Optional[Hit]:
|
||||||
rows = await db.fetchall(
|
rows = await db.fetchall(
|
||||||
f"SELECT * FROM boltcards.hits WHERE card_id = ?", (card_id,),
|
f"SELECT * FROM boltcards.hits WHERE card_id = ?",
|
||||||
|
(card_id,),
|
||||||
)
|
)
|
||||||
updatedrow = []
|
updatedrow = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
@@ -21,7 +21,6 @@ from starlette.requests import Request
|
|||||||
from starlette.responses import HTMLResponse
|
from starlette.responses import HTMLResponse
|
||||||
|
|
||||||
from lnbits import bolt11
|
from lnbits import bolt11
|
||||||
|
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
from lnbits.core.views.api import pay_invoice
|
from lnbits.core.views.api import pay_invoice
|
||||||
|
|
||||||
@@ -98,6 +97,7 @@ async def api_scan(p, c, request: Request, external_id: str = None):
|
|||||||
"defaultDescription": f"Boltcard (refund address lnurl://{lnurlpay})",
|
"defaultDescription": f"Boltcard (refund address lnurl://{lnurlpay})",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@boltcards_ext.get(
|
@boltcards_ext.get(
|
||||||
"/api/v1/lnurl/cb/{hitid}",
|
"/api/v1/lnurl/cb/{hitid}",
|
||||||
status_code=HTTPStatus.OK,
|
status_code=HTTPStatus.OK,
|
||||||
@@ -129,6 +129,7 @@ async def lnurl_callback(
|
|||||||
except:
|
except:
|
||||||
return {"status": "ERROR", "reason": f"Payment failed"}
|
return {"status": "ERROR", "reason": f"Payment failed"}
|
||||||
|
|
||||||
|
|
||||||
# /boltcards/api/v1/auth?a=00000000000000000000000000000000
|
# /boltcards/api/v1/auth?a=00000000000000000000000000000000
|
||||||
@boltcards_ext.get("/api/v1/auth")
|
@boltcards_ext.get("/api/v1/auth")
|
||||||
async def api_auth(a, request: Request):
|
async def api_auth(a, request: Request):
|
||||||
@@ -159,11 +160,12 @@ async def api_auth(a, request: Request):
|
|||||||
"k4": card.k2,
|
"k4": card.k2,
|
||||||
"lnurlw_base": "lnurlw://" + lnurlw_base,
|
"lnurlw_base": "lnurlw://" + lnurlw_base,
|
||||||
"protocol_name": "new_bolt_card_response",
|
"protocol_name": "new_bolt_card_response",
|
||||||
"protocol_version": 1
|
"protocol_version": 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
###############LNURLPAY REFUNDS#################
|
###############LNURLPAY REFUNDS#################
|
||||||
|
|
||||||
|
|
||||||
|
@@ -63,7 +63,7 @@ class ConnectionManager:
|
|||||||
manager = ConnectionManager()
|
manager = ConnectionManager()
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.websocket("/copilot/ws/{copilot_id}", name="copilot.websocket_by_id")
|
@copilot_ext.websocket("/ws/{copilot_id}", name="copilot.websocket_by_id")
|
||||||
async def websocket_endpoint(websocket: WebSocket, copilot_id: str):
|
async def websocket_endpoint(websocket: WebSocket, copilot_id: str):
|
||||||
await manager.connect(websocket, copilot_id)
|
await manager.connect(websocket, copilot_id)
|
||||||
try:
|
try:
|
||||||
|
@@ -132,8 +132,6 @@ async def lndhub_gettxs(
|
|||||||
):
|
):
|
||||||
await payment.check_status()
|
await payment.check_status()
|
||||||
|
|
||||||
await asyncio.sleep(0.1)
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"payment_preimage": payment.preimage,
|
"payment_preimage": payment.preimage,
|
||||||
@@ -180,7 +178,6 @@ async def lndhub_getuserinvoices(
|
|||||||
await invoice.set_pending(
|
await invoice.set_pending(
|
||||||
(await WALLET.get_invoice_status(invoice.checking_id)).pending
|
(await WALLET.get_invoice_status(invoice.checking_id)).pending
|
||||||
)
|
)
|
||||||
await asyncio.sleep(0.1)
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
@@ -19,7 +19,7 @@ class WalletAccount(BaseModel):
|
|||||||
title: str
|
title: str
|
||||||
address_no: int
|
address_no: int
|
||||||
balance: int
|
balance: int
|
||||||
type: str = ""
|
type: Optional[str] = ""
|
||||||
network: str = "Mainnet"
|
network: str = "Mainnet"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@@ -16,6 +16,8 @@ from lnbits.core.crud import (
|
|||||||
from lnbits.core.services import redeem_lnurl_withdraw
|
from lnbits.core.services import redeem_lnurl_withdraw
|
||||||
from lnbits.settings import WALLET
|
from lnbits.settings import WALLET
|
||||||
|
|
||||||
|
from .core import db
|
||||||
|
|
||||||
deferred_async: List[Callable] = []
|
deferred_async: List[Callable] = []
|
||||||
|
|
||||||
|
|
||||||
@@ -86,24 +88,34 @@ async def check_pending_payments():
|
|||||||
incoming = True
|
incoming = True
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
async with db.connect() as conn:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Task: checking all pending payments (incoming={incoming}, outgoing={outgoing}) of last 15 days"
|
f"Task: checking all pending payments (incoming={incoming}, outgoing={outgoing}) of last 15 days"
|
||||||
)
|
)
|
||||||
for payment in await get_payments(
|
start_time: float = time.time()
|
||||||
|
pending_payments = await get_payments(
|
||||||
since=(int(time.time()) - 60 * 60 * 24 * 15), # 15 days ago
|
since=(int(time.time()) - 60 * 60 * 24 * 15), # 15 days ago
|
||||||
complete=False,
|
complete=False,
|
||||||
pending=True,
|
pending=True,
|
||||||
outgoing=outgoing,
|
outgoing=outgoing,
|
||||||
incoming=incoming,
|
incoming=incoming,
|
||||||
exclude_uncheckable=True,
|
exclude_uncheckable=True,
|
||||||
):
|
conn=conn,
|
||||||
|
)
|
||||||
|
for payment in pending_payments:
|
||||||
await payment.check_status()
|
await payment.check_status()
|
||||||
logger.debug("Task: pending payments check finished")
|
|
||||||
|
logger.debug(
|
||||||
|
f"Task: pending check finished for {len(pending_payments)} payments (took {time.time() - start_time:0.3f} s)"
|
||||||
|
)
|
||||||
# we delete expired invoices once upon the first pending check
|
# we delete expired invoices once upon the first pending check
|
||||||
if incoming:
|
if incoming:
|
||||||
logger.debug("Task: deleting all expired invoices")
|
logger.debug("Task: deleting all expired invoices")
|
||||||
await delete_expired_invoices()
|
start_time: float = time.time()
|
||||||
logger.debug("Task: expired invoice deletion finished")
|
await delete_expired_invoices(conn=conn)
|
||||||
|
logger.debug(
|
||||||
|
f"Task: expired invoice deletion finished (took {time.time() - start_time:0.3f} s)"
|
||||||
|
)
|
||||||
|
|
||||||
# after the first check we will only check outgoing, not incoming
|
# after the first check we will only check outgoing, not incoming
|
||||||
# that will be handled by the global invoice listeners, hopefully
|
# that will be handled by the global invoice listeners, hopefully
|
||||||
|
Reference in New Issue
Block a user