SatsPayServer works apart from updating charges
This commit is contained in:
@@ -9,17 +9,19 @@ from lnbits.helpers import urlsafe_short_hash
|
||||
from quart import jsonify
|
||||
import httpx
|
||||
from lnbits.core.services import create_invoice, check_invoice_status
|
||||
from ..watchonly.crud import get_watch_wallet, get_derive_address, get_mempool
|
||||
from ..watchonly.crud import get_watch_wallet, get_derive_address, get_mempool, update_watch_wallet
|
||||
|
||||
|
||||
###############CHARGES##########################
|
||||
|
||||
|
||||
async def create_charge(user: str, description: Optional[str] = None, onchainwallet: Optional[str] = None, lnbitswallet: Optional[str] = None, webhook: Optional[str] = None, time: Optional[int] = None, amount: Optional[int] = None) -> Charges:
|
||||
async def create_charge(user: str, description: str = None, onchainwallet: Optional[str] = None, lnbitswallet: Optional[str] = None, webhook: Optional[str] = None, completelink: Optional[str] = None, completelinktext: Optional[str] = None, time: Optional[int] = None, amount: Optional[int] = None) -> Charges:
|
||||
charge_id = urlsafe_short_hash()
|
||||
if onchainwallet:
|
||||
wallet = await get_watch_wallet(onchainwallet)
|
||||
onchainaddress = await get_derive_address(onchainwallet, wallet[4] + 1)
|
||||
onchainaddress = await get_derive_address(onchainwallet, int(wallet[4]) + 1)
|
||||
await update_watch_wallet(wallet_id=onchainwallet, address_no=int(wallet[4]) + 1)
|
||||
print(onchainaddress)
|
||||
else:
|
||||
onchainaddress = None
|
||||
if lnbitswallet:
|
||||
@@ -42,14 +44,16 @@ async def create_charge(user: str, description: Optional[str] = None, onchainwal
|
||||
payment_request,
|
||||
payment_hash,
|
||||
webhook,
|
||||
completelink,
|
||||
completelinktext,
|
||||
time,
|
||||
amount,
|
||||
balance
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(charge_id, user, description, onchainwallet, onchainaddress, lnbitswallet,
|
||||
payment_request, payment_hash, webhook, time, amount, 0),
|
||||
payment_request, payment_hash, webhook, completelink, completelinktext, time, amount, 0),
|
||||
)
|
||||
return await get_charge(charge_id)
|
||||
|
||||
@@ -77,7 +81,6 @@ async def delete_charge(charge_id: str) -> None:
|
||||
|
||||
async def check_address_balance(charge_id: str) -> List[Charges]:
|
||||
charge = await get_charge(charge_id)
|
||||
print(charge.balance)
|
||||
if not charge.paid:
|
||||
if charge.onchainaddress:
|
||||
mempool = await get_mempool(charge.user)
|
||||
@@ -85,16 +88,13 @@ async def check_address_balance(charge_id: str) -> List[Charges]:
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.get(mempool.endpoint + "/api/address/" + charge.onchainaddress)
|
||||
respAmount = r.json()['chain_stats']['funded_txo_sum']
|
||||
print(respAmount)
|
||||
if respAmount >= charge.balance:
|
||||
await update_charge(charge_id=charge_id, balance=respAmount)
|
||||
except Exception:
|
||||
pass
|
||||
if charge.lnbitswallet:
|
||||
invoice_status = await check_invoice_status(charge.lnbitswallet, charge.payment_hash)
|
||||
print(invoice_status)
|
||||
if invoice_status.paid:
|
||||
print("paid")
|
||||
return await update_charge(charge_id=charge_id, balance=charge.amount)
|
||||
row = await db.fetchone("SELECT * FROM charges WHERE id = ?", (charge_id,))
|
||||
return Charges.from_row(row) if row else None
|
||||
|
||||
Reference in New Issue
Block a user