From c1dab6a63254554cd4144d8e21ca44e4730933a4 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Tue, 18 Feb 2025 13:49:34 +0000 Subject: [PATCH] fix tracked budget --- crud.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/crud.py b/crud.py index 89a37ab..e8be965 100644 --- a/crud.py +++ b/crud.py @@ -147,21 +147,18 @@ async def tracked_spend_nwc(data: TrackedSpendNWC, action): for budget in budgets: last_cycle, next_cycle = budget.get_timestamp_range() tot_spent_in_range_msats = ( - ( - await db.fetchone( - """ - SELECT SUM(amount_msats) FROM nwcprovider.spent - WHERE pubkey = :pubkey AND created_at >= - :last_cycle AND created_at < :next_cycle - """, - { - "pubkey": data.pubkey, - "last_cycle": last_cycle, - "next_cycle": next_cycle, - }, - ) - )[0] - or 0 + next(iter((await db.fetchone( + """ + SELECT SUM(amount_msats) FROM nwcprovider.spent + WHERE pubkey = :pubkey AND created_at >= + :last_cycle AND created_at < :next_cycle + """, + { + "pubkey": data.pubkey, + "last_cycle": last_cycle, + "next_cycle": next_cycle, + }, + )).values())) or 0 ) if tot_spent_in_range_msats + data.amount_msats > budget.budget_msats: in_budget = False @@ -181,7 +178,7 @@ async def tracked_spend_nwc(data: TrackedSpendNWC, action): }, ) return True, out - + return await enqueue(r)