Trying to fix

This commit is contained in:
benarc 2020-12-04 10:07:59 +00:00
parent 54c0c9f3a8
commit 4c7c792390
3 changed files with 9 additions and 15 deletions

View file

@ -2,7 +2,7 @@ from typing import List, Optional, Union
#from lnbits.db import open_ext_db #from lnbits.db import open_ext_db
from . import db from . import db
from .models import Wallets, charges, Addresses, Mempool from .models import Wallets, Charges, Mempool
from lnbits.helpers import urlsafe_short_hash 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,)) 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) address = await get_fresh_address(walletid)
charge_id = urlsafe_short_hash() 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) 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,)) row = await db.fetchone("SELECT * FROM charges WHERE id = ?", (charge_id,))
return charges.from_row(row) if row else None 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,)) rows = await db.fetchall("SELECT * FROM charges WHERE user = ?", (user,))
for row in rows: for row in rows:
await check_address_balance(row.address) 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: async def delete_charge(charge_id: str) -> None:
await db.execute("DELETE FROM charges WHERE id = ?", (charge_id,)) 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) address_data = await get_address(address)
mempool = await get_mempool(address_data.user) mempool = await get_mempool(address_data.user)
r = requests.get(mempool.endpoint + "/api/address/" + address) r = requests.get(mempool.endpoint + "/api/address/" + address)
amount_paid = r.json()['chain_stats']['funded_txo_sum'] - r.json()['chain_stats']['spent_txo_sum'] amount_paid = r.json()['chain_stats']['funded_txo_sum'] - r.json()['chain_stats']['spent_txo_sum']
print(amount_paid) 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####################### ######################MEMPOOL#######################

View file

@ -4,7 +4,7 @@ from http import HTTPStatus
from lnbits.decorators import check_user_exists, validate_uuids from lnbits.decorators import check_user_exists, validate_uuids
from . import watchonly_ext from . import watchonly_ext
from .crud import get_payment from .crud import get_charge
@watchonly_ext.route("/") @watchonly_ext.route("/")
@ -15,7 +15,7 @@ async def index():
@watchonly_ext.route("/<charge_id>") @watchonly_ext.route("/<charge_id>")
async def display(payment_id): async def display(charge_id):
link = get_payment(payment_id) or abort(HTTPStatus.NOT_FOUND, "Pay link does not exist.") link = get_payment(charge_id) or abort(HTTPStatus.NOT_FOUND, "Charge link does not exist.")
return await render_template("watchonly/display.html", link=link) return await render_template("watchonly/display.html", link=link)

View file

@ -21,9 +21,6 @@ from .crud import (
create_mempool, create_mempool,
update_mempool, update_mempool,
get_mempool, get_mempool,
get_addresses,
get_fresh_address,
get_address
) )
###################WALLETS############################# ###################WALLETS#############################