Merge remote-tracking branch 'origin/master' into watchonly

This commit is contained in:
Ben Arc 2021-04-04 13:35:42 +01:00
commit 96082978d1
2 changed files with 30 additions and 4 deletions

View File

@ -135,3 +135,29 @@ async def m003_add_invoice_webhook(db):
await db.execute("ALTER TABLE apipayments ADD COLUMN webhook TEXT")
await db.execute("ALTER TABLE apipayments ADD COLUMN webhook_status TEXT")
async def m004_ensure_fees_are_always_negative(db):
"""
Use abs() so wallet backends don't have to care about the sign of the fees.
"""
await db.execute("DROP VIEW balances")
await db.execute(
"""
CREATE VIEW IF NOT EXISTS balances AS
SELECT wallet, COALESCE(SUM(s), 0) AS balance FROM (
SELECT wallet, SUM(amount) AS s -- incoming
FROM apipayments
WHERE amount > 0 AND pending = 0 -- don't sum pending
GROUP BY wallet
UNION ALL
SELECT wallet, SUM(amount - abs(fee)) AS s -- outgoing, sum fees
FROM apipayments
WHERE amount < 0 -- do sum pending
GROUP BY wallet
)
GROUP BY wallet;
"""
)

View File

@ -145,13 +145,13 @@ class Payment(NamedTuple):
else:
status = await WALLET.get_invoice_status(self.checking_id)
print(
f" - checking '{'in' if self.is_in else 'out'}' {self.checking_id}: {status}"
)
if self.is_out and status.failed:
print(f" - deleting outgoing failed payment {self.checking_id}: {status}")
await self.delete()
elif not status.pending:
print(
f" - marking '{'in' if self.is_in else 'out'}' {self.checking_id} as not pending anymore: {status}"
)
await self.set_pending(status.pending)
async def delete(self) -> None: