fix expiry integer

This commit is contained in:
callebtc 2022-12-06 10:48:16 +01:00
parent befdeb040e
commit 441d5337a3
3 changed files with 25 additions and 26 deletions

View File

@ -377,6 +377,7 @@ async def create_payment(
invoice = bolt11.decode(payment_request)
expiration_date = datetime.datetime.fromtimestamp(invoice.date + invoice.expiry)
except:
# assume maximum bolt11 expiry of 31 days to be on the safe side
expiration_date = datetime.datetime.now() + datetime.timedelta(days=31)
await (conn or db).execute(

View File

@ -1,5 +1,5 @@
import datetime
from loguru import logger
from sqlalchemy.exc import OperationalError # type: ignore
from lnbits import bolt11
@ -216,37 +216,35 @@ async def m006_add_invoice_expiry_to_apipayments(db):
"""
)
).fetchall()
# then we delete all expired invoices, checking one by one
print(f"Checking expiry of {len(rows)} invoices")
logger.info(f"Checking expiry of {len(rows)} invoices")
for i, (
payment_request,
payment_hash,
checking_id,
) in enumerate(rows):
print(f"Checking invoice {i}/{len(rows)}")
logger.info(f"Checking invoice {i}/{len(rows)}")
try:
invoice = bolt11.decode(payment_request)
if invoice.expiry is None:
continue
expiration_date = datetime.datetime.fromtimestamp(
invoice.date + invoice.expiry
)
logger.info(
f"Setting expiry of invoice {invoice.payment_hash} to {expiration_date}"
)
await db.execute(
"""
UPDATE apipayments SET expiry = ?
WHERE checking_id = ? AND amount > 0
""",
(
db.datetime_to_timestamp(expiration_date),
checking_id,
),
)
except:
continue
if payment_hash != invoice.payment_hash:
print("Error: {payment_hash} != {invoice.payment_hash}")
continue
expiration_date = datetime.datetime.fromtimestamp(
invoice.date + invoice.expiry
)
print(
f"Setting expiry of invoice {invoice.payment_hash} to {expiration_date}"
)
await db.execute(
"""
UPDATE apipayments SET expiry = ?
WHERE checking_id = ? AND amount > 0
""",
(
db.datetime_to_timestamp(expiration_date),
invoice.payment_hash,
),
)
except OperationalError:
# this is necessary now because it may be the case that this migration will
# run twice in some environments.

View File

@ -85,7 +85,7 @@ class Payment(BaseModel):
bolt11: str
preimage: str
payment_hash: str
expiry: int
expiry: float
extra: Optional[Dict] = {}
wallet_id: str
webhook: Optional[str]