improve checking routine.

check pending invoices only once on startup,
then check outgoing payments every 30 minutes,
and delete outgoing payments that return False (meaning they have failed).

also fix a bug on sparko.
This commit is contained in:
fiatjaf
2021-03-28 00:11:45 -03:00
parent b2efd71d3c
commit e112258c39
4 changed files with 37 additions and 9 deletions
+11 -4
View File
@@ -58,7 +58,7 @@ class Wallet(NamedTuple):
pending: bool = False,
outgoing: bool = True,
incoming: bool = True,
exclude_uncheckable: bool = False
exclude_uncheckable: bool = False,
) -> List["Payment"]:
from .crud import get_payments
@@ -141,11 +141,18 @@ class Payment(NamedTuple):
return
if self.is_out:
pending = await WALLET.get_payment_status(self.checking_id)
status = await WALLET.get_payment_status(self.checking_id)
else:
pending = await WALLET.get_invoice_status(self.checking_id)
status = await WALLET.get_invoice_status(self.checking_id)
await self.set_pending(pending.pending)
print(
f" - checking '{'in' if self.is_in else 'out'}' {self.checking_id}: {status.paid}"
)
if self.is_out and status.failed:
await self.delete()
elif not status.pending:
await self.set_pending(status.pending)
async def delete(self) -> None:
from .crud import delete_payment