mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-24 06:48:02 +01:00
Trying to fix
This commit is contained in:
parent
54c0c9f3a8
commit
4c7c792390
3 changed files with 9 additions and 15 deletions
|
@ -2,7 +2,7 @@ from typing import List, Optional, Union
|
|||
|
||||
#from lnbits.db import open_ext_db
|
||||
from . import db
|
||||
from .models import Wallets, charges, Addresses, Mempool
|
||||
from .models import Wallets, Charges, Mempool
|
||||
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
|
||||
|
@ -67,9 +67,9 @@ async def delete_watch_wallet(wallet_id: str) -> None:
|
|||
await db.execute("DELETE FROM wallets WHERE id = ?", (wallet_id,))
|
||||
|
||||
|
||||
###############charges##########################
|
||||
###############CHARGES##########################
|
||||
|
||||
async def create_charge(*, walletid: str, user: str, title: str, time: str, amount: int) -> charges:
|
||||
async def create_charge(*, walletid: str, user: str, title: str, time: str, amount: int) -> Charges:
|
||||
|
||||
address = await get_fresh_address(walletid)
|
||||
charge_id = urlsafe_short_hash()
|
||||
|
@ -92,12 +92,12 @@ async def create_charge(*, walletid: str, user: str, title: str, time: str, amou
|
|||
return await get_charge(charge_id)
|
||||
|
||||
|
||||
async def get_charge(charge_id: str) -> charges:
|
||||
async def get_charge(charge_id: str) -> Charges:
|
||||
row = await db.fetchone("SELECT * FROM charges WHERE id = ?", (charge_id,))
|
||||
return charges.from_row(row) if row else None
|
||||
|
||||
|
||||
async def get_charges(user: str) -> List[charges]:
|
||||
async def get_charges(user: str) -> List[Charges]:
|
||||
rows = await db.fetchall("SELECT * FROM charges WHERE user = ?", (user,))
|
||||
for row in rows:
|
||||
await check_address_balance(row.address)
|
||||
|
@ -108,15 +108,12 @@ async def get_charges(user: str) -> List[charges]:
|
|||
async def delete_charge(charge_id: str) -> None:
|
||||
await db.execute("DELETE FROM charges WHERE id = ?", (charge_id,))
|
||||
|
||||
async def check_address_balance(address: str) -> List[Addresses]:
|
||||
async def check_address_balance(address: str) -> List[Charges]:
|
||||
address_data = await get_address(address)
|
||||
mempool = await get_mempool(address_data.user)
|
||||
r = requests.get(mempool.endpoint + "/api/address/" + address)
|
||||
amount_paid = r.json()['chain_stats']['funded_txo_sum'] - r.json()['chain_stats']['spent_txo_sum']
|
||||
print(amount_paid)
|
||||
await db.execute("UPDATE addresses SET amount_paid = ? WHERE address = ?", (amount_paid, address))
|
||||
row = await db.fetchone("SELECT * FROM addresses WHERE address = ?", (address,))
|
||||
return Addresses.from_row(row) if row else None
|
||||
|
||||
######################MEMPOOL#######################
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from http import HTTPStatus
|
|||
from lnbits.decorators import check_user_exists, validate_uuids
|
||||
|
||||
from . import watchonly_ext
|
||||
from .crud import get_payment
|
||||
from .crud import get_charge
|
||||
|
||||
|
||||
@watchonly_ext.route("/")
|
||||
|
@ -15,7 +15,7 @@ async def index():
|
|||
|
||||
|
||||
@watchonly_ext.route("/<charge_id>")
|
||||
async def display(payment_id):
|
||||
link = get_payment(payment_id) or abort(HTTPStatus.NOT_FOUND, "Pay link does not exist.")
|
||||
async def display(charge_id):
|
||||
link = get_payment(charge_id) or abort(HTTPStatus.NOT_FOUND, "Charge link does not exist.")
|
||||
|
||||
return await render_template("watchonly/display.html", link=link)
|
|
@ -21,9 +21,6 @@ from .crud import (
|
|||
create_mempool,
|
||||
update_mempool,
|
||||
get_mempool,
|
||||
get_addresses,
|
||||
get_fresh_address,
|
||||
get_address
|
||||
)
|
||||
|
||||
###################WALLETS#############################
|
||||
|
|
Loading…
Add table
Reference in a new issue