This commit is contained in:
callebtc
2022-09-13 21:36:18 +03:00
parent 075fb57093
commit f2228e6a38
16 changed files with 251 additions and 131 deletions

View File

@@ -1,5 +1,7 @@
import secrets
from typing import Optional
from core.base import Invoice
from core.db import Connection, Database
@@ -62,3 +64,52 @@ async def invalidate_proof(
str(proof["secret"]),
),
)
async def store_lightning_invoice(
invoice: Invoice,
db: Database,
conn: Optional[Connection] = None,
):
await (conn or db).execute(
"""
INSERT INTO invoices
(amount, pr, hash, issued)
VALUES (?, ?, ?, ?)
""",
(
invoice.amount,
invoice.pr,
invoice.hash,
invoice.issued,
),
)
async def get_lightning_invoice(
hash: str,
db: Database,
conn: Optional[Connection] = None,
):
row = await (conn or db).fetchone(
"""
SELECT * from invoices
WHERE hash = ?
""",
hash,
)
return Invoice.from_row(row)
async def update_lightning_invoice(
hash: str,
issued: bool,
db: Database,
conn: Optional[Connection] = None,
):
await (conn or db).execute(
"UPDATE invoices SET issued = ? WHERE hash = ?",
(issued, hash),
)