mirror of
https://github.com/lnbits/lnbits.git
synced 2025-04-15 23:31:44 +02:00
fix expiry integer
This commit is contained in:
parent
befdeb040e
commit
441d5337a3
@ -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(
|
||||
|
@ -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.
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user