fix expiry integer
This commit is contained in:
parent
befdeb040e
commit
441d5337a3
3 changed files with 25 additions and 26 deletions
|
|
@ -377,6 +377,7 @@ async def create_payment(
|
||||||
invoice = bolt11.decode(payment_request)
|
invoice = bolt11.decode(payment_request)
|
||||||
expiration_date = datetime.datetime.fromtimestamp(invoice.date + invoice.expiry)
|
expiration_date = datetime.datetime.fromtimestamp(invoice.date + invoice.expiry)
|
||||||
except:
|
except:
|
||||||
|
# assume maximum bolt11 expiry of 31 days to be on the safe side
|
||||||
expiration_date = datetime.datetime.now() + datetime.timedelta(days=31)
|
expiration_date = datetime.datetime.now() + datetime.timedelta(days=31)
|
||||||
|
|
||||||
await (conn or db).execute(
|
await (conn or db).execute(
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
from loguru import logger
|
||||||
from sqlalchemy.exc import OperationalError # type: ignore
|
from sqlalchemy.exc import OperationalError # type: ignore
|
||||||
|
|
||||||
from lnbits import bolt11
|
from lnbits import bolt11
|
||||||
|
|
@ -216,25 +216,21 @@ async def m006_add_invoice_expiry_to_apipayments(db):
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
).fetchall()
|
).fetchall()
|
||||||
# then we delete all expired invoices, checking one by one
|
logger.info(f"Checking expiry of {len(rows)} invoices")
|
||||||
print(f"Checking expiry of {len(rows)} invoices")
|
|
||||||
for i, (
|
for i, (
|
||||||
payment_request,
|
payment_request,
|
||||||
payment_hash,
|
checking_id,
|
||||||
) in enumerate(rows):
|
) in enumerate(rows):
|
||||||
print(f"Checking invoice {i}/{len(rows)}")
|
logger.info(f"Checking invoice {i}/{len(rows)}")
|
||||||
try:
|
try:
|
||||||
invoice = bolt11.decode(payment_request)
|
invoice = bolt11.decode(payment_request)
|
||||||
except:
|
if invoice.expiry is None:
|
||||||
continue
|
|
||||||
if payment_hash != invoice.payment_hash:
|
|
||||||
print("Error: {payment_hash} != {invoice.payment_hash}")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
expiration_date = datetime.datetime.fromtimestamp(
|
expiration_date = datetime.datetime.fromtimestamp(
|
||||||
invoice.date + invoice.expiry
|
invoice.date + invoice.expiry
|
||||||
)
|
)
|
||||||
print(
|
logger.info(
|
||||||
f"Setting expiry of invoice {invoice.payment_hash} to {expiration_date}"
|
f"Setting expiry of invoice {invoice.payment_hash} to {expiration_date}"
|
||||||
)
|
)
|
||||||
await db.execute(
|
await db.execute(
|
||||||
|
|
@ -244,9 +240,11 @@ async def m006_add_invoice_expiry_to_apipayments(db):
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
db.datetime_to_timestamp(expiration_date),
|
db.datetime_to_timestamp(expiration_date),
|
||||||
invoice.payment_hash,
|
checking_id,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
# this is necessary now because it may be the case that this migration will
|
# this is necessary now because it may be the case that this migration will
|
||||||
# run twice in some environments.
|
# run twice in some environments.
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ class Payment(BaseModel):
|
||||||
bolt11: str
|
bolt11: str
|
||||||
preimage: str
|
preimage: str
|
||||||
payment_hash: str
|
payment_hash: str
|
||||||
expiry: int
|
expiry: float
|
||||||
extra: Optional[Dict] = {}
|
extra: Optional[Dict] = {}
|
||||||
wallet_id: str
|
wallet_id: str
|
||||||
webhook: Optional[str]
|
webhook: Optional[str]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue