fix tracked budget
This commit is contained in:
parent
a366dbce33
commit
c1dab6a632
1 changed files with 13 additions and 16 deletions
29
crud.py
29
crud.py
|
|
@ -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
|
||||||
|
|
@ -181,7 +178,7 @@ async def tracked_spend_nwc(data: TrackedSpendNWC, action):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
return True, out
|
return True, out
|
||||||
|
|
||||||
return await enqueue(r)
|
return await enqueue(r)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue