fix tracked budget

This commit is contained in:
Riccardo Balbo 2025-02-18 13:49:34 +00:00
commit c1dab6a632

27
crud.py
View file

@ -147,21 +147,18 @@ async def tracked_spend_nwc(data: TrackedSpendNWC, action):
for budget in budgets: for budget in budgets:
last_cycle, next_cycle = budget.get_timestamp_range() last_cycle, next_cycle = budget.get_timestamp_range()
tot_spent_in_range_msats = ( tot_spent_in_range_msats = (
( next(iter((await db.fetchone(
await db.fetchone( """
""" SELECT SUM(amount_msats) FROM nwcprovider.spent
SELECT SUM(amount_msats) FROM nwcprovider.spent WHERE pubkey = :pubkey AND created_at >=
WHERE pubkey = :pubkey AND created_at >= :last_cycle AND created_at < :next_cycle
:last_cycle AND created_at < :next_cycle """,
""", {
{ "pubkey": data.pubkey,
"pubkey": data.pubkey, "last_cycle": last_cycle,
"last_cycle": last_cycle, "next_cycle": next_cycle,
"next_cycle": next_cycle, },
}, )).values())) or 0
)
)[0]
or 0
) )
if tot_spent_in_range_msats + data.amount_msats > budget.budget_msats: if tot_spent_in_range_msats + data.amount_msats > budget.budget_msats:
in_budget = False in_budget = False