add expiry to Payment model
This commit is contained in:
parent
2134b63cea
commit
7a6450f032
2 changed files with 16 additions and 1 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
from sqlite3 import Row
|
from sqlite3 import Row
|
||||||
from typing import Dict, List, NamedTuple, Optional
|
from typing import Dict, List, NamedTuple, Optional
|
||||||
|
|
||||||
|
|
@ -83,6 +85,7 @@ class Payment(BaseModel):
|
||||||
bolt11: str
|
bolt11: str
|
||||||
preimage: str
|
preimage: str
|
||||||
payment_hash: str
|
payment_hash: str
|
||||||
|
expiry: int
|
||||||
extra: Optional[Dict] = {}
|
extra: Optional[Dict] = {}
|
||||||
wallet_id: str
|
wallet_id: str
|
||||||
webhook: Optional[str]
|
webhook: Optional[str]
|
||||||
|
|
@ -101,6 +104,7 @@ class Payment(BaseModel):
|
||||||
fee=row["fee"],
|
fee=row["fee"],
|
||||||
memo=row["memo"],
|
memo=row["memo"],
|
||||||
time=row["time"],
|
time=row["time"],
|
||||||
|
expiry=row["expiry"],
|
||||||
wallet_id=row["wallet"],
|
wallet_id=row["wallet"],
|
||||||
webhook=row["webhook"],
|
webhook=row["webhook"],
|
||||||
webhook_status=row["webhook_status"],
|
webhook_status=row["webhook_status"],
|
||||||
|
|
@ -128,6 +132,10 @@ class Payment(BaseModel):
|
||||||
def is_out(self) -> bool:
|
def is_out(self) -> bool:
|
||||||
return self.amount < 0
|
return self.amount < 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_expired(self) -> bool:
|
||||||
|
return self.expiry < time.time()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_uncheckable(self) -> bool:
|
def is_uncheckable(self) -> bool:
|
||||||
return self.checking_id.startswith("internal_")
|
return self.checking_id.startswith("internal_")
|
||||||
|
|
@ -170,6 +178,13 @@ class Payment(BaseModel):
|
||||||
|
|
||||||
logger.debug(f"Status: {status}")
|
logger.debug(f"Status: {status}")
|
||||||
|
|
||||||
|
if self.is_in and self.is_expired:
|
||||||
|
expiration_date = datetime.datetime.fromtimestamp(self.expiry)
|
||||||
|
logger.debug(
|
||||||
|
f"Deleting expired incoming payment {self.checking_id}: expired {expiration_date}"
|
||||||
|
)
|
||||||
|
await self.delete(conn)
|
||||||
|
|
||||||
if self.is_out and status.failed:
|
if self.is_out and status.failed:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Deleting outgoing failed payment {self.checking_id}: {status}"
|
f"Deleting outgoing failed payment {self.checking_id}: {status}"
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ from lnbits.core.crud import (
|
||||||
get_standalone_payment,
|
get_standalone_payment,
|
||||||
)
|
)
|
||||||
from lnbits.core.services import redeem_lnurl_withdraw
|
from lnbits.core.services import redeem_lnurl_withdraw
|
||||||
|
from lnbits.settings import WALLET
|
||||||
from .core import db
|
from .core import db
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue