allow for internal and external migrations
This commit is contained in:
@@ -11,6 +11,7 @@ from loguru import logger
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
|
||||
from . import db
|
||||
|
||||
from .core.base import Invoice
|
||||
from .models import Cashu, Pegs, Promises, Proof
|
||||
|
||||
@@ -18,44 +19,44 @@ from cashu.core.base import MintKeyset
|
||||
from lnbits.db import Database, Connection
|
||||
|
||||
|
||||
class LedgerCrud:
|
||||
"""
|
||||
Database interface for Cashu mint.
|
||||
# class LedgerCrud:
|
||||
# """
|
||||
# Database interface for Cashu mint.
|
||||
|
||||
This class needs to be overloaded by any app that imports the Cashu mint.
|
||||
"""
|
||||
# This class needs to be overloaded by any app that imports the Cashu mint.
|
||||
# """
|
||||
|
||||
async def get_keyset(*args, **kwags):
|
||||
# async def get_keyset(*args, **kwags):
|
||||
|
||||
return await get_keyset(*args, **kwags)
|
||||
# return await get_keyset(*args, **kwags)
|
||||
|
||||
async def get_lightning_invoice(*args, **kwags):
|
||||
# async def get_lightning_invoice(*args, **kwags):
|
||||
|
||||
return await get_lightning_invoice(*args, **kwags)
|
||||
# return await get_lightning_invoice(*args, **kwags)
|
||||
|
||||
async def get_proofs_used(*args, **kwags):
|
||||
# async def get_proofs_used(*args, **kwags):
|
||||
|
||||
return await get_proofs_used(*args, **kwags)
|
||||
# return await get_proofs_used(*args, **kwags)
|
||||
|
||||
async def invalidate_proof(*args, **kwags):
|
||||
# async def invalidate_proof(*args, **kwags):
|
||||
|
||||
return await invalidate_proof(*args, **kwags)
|
||||
# return await invalidate_proof(*args, **kwags)
|
||||
|
||||
async def store_keyset(*args, **kwags):
|
||||
# async def store_keyset(*args, **kwags):
|
||||
|
||||
return await store_keyset(*args, **kwags)
|
||||
# return await store_keyset(*args, **kwags)
|
||||
|
||||
async def store_lightning_invoice(*args, **kwags):
|
||||
# async def store_lightning_invoice(*args, **kwags):
|
||||
|
||||
return await store_lightning_invoice(*args, **kwags)
|
||||
# return await store_lightning_invoice(*args, **kwags)
|
||||
|
||||
async def store_promise(*args, **kwags):
|
||||
# async def store_promise(*args, **kwags):
|
||||
|
||||
return await store_promise(*args, **kwags)
|
||||
# return await store_promise(*args, **kwags)
|
||||
|
||||
async def update_lightning_invoice(*args, **kwags):
|
||||
# async def update_lightning_invoice(*args, **kwags):
|
||||
|
||||
return await update_lightning_invoice(*args, **kwags)
|
||||
# return await update_lightning_invoice(*args, **kwags)
|
||||
|
||||
|
||||
async def create_cashu(wallet_id: str, data: Cashu) -> Cashu:
|
||||
@@ -132,9 +133,9 @@ async def delete_cashu(cashu_id) -> None:
|
||||
await db.execute("DELETE FROM cashu.cashu WHERE id = ?", (cashu_id,))
|
||||
|
||||
|
||||
##########################################
|
||||
###############MINT STUFF#################
|
||||
##########################################
|
||||
# ##########################################
|
||||
# ###############MINT STUFF#################
|
||||
# ##########################################
|
||||
|
||||
|
||||
async def store_promises(
|
||||
@@ -241,55 +242,55 @@ async def update_lightning_invoice(cashu_id: str, hash: str, issued: bool):
|
||||
##############################
|
||||
|
||||
|
||||
async def store_keyset(
|
||||
keyset: MintKeyset,
|
||||
db: Database = None,
|
||||
conn: Optional[Connection] = None,
|
||||
):
|
||||
# async def store_keyset(
|
||||
# keyset: MintKeyset,
|
||||
# db: Database = None,
|
||||
# conn: Optional[Connection] = None,
|
||||
# ):
|
||||
|
||||
await (conn or db).execute( # type: ignore
|
||||
"""
|
||||
INSERT INTO cashu.keysets
|
||||
(id, derivation_path, valid_from, valid_to, first_seen, active, version)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
keyset.id,
|
||||
keyset.derivation_path,
|
||||
keyset.valid_from or db.timestamp_now,
|
||||
keyset.valid_to or db.timestamp_now,
|
||||
keyset.first_seen or db.timestamp_now,
|
||||
True,
|
||||
keyset.version,
|
||||
),
|
||||
)
|
||||
# await (conn or db).execute( # type: ignore
|
||||
# """
|
||||
# INSERT INTO cashu.keysets
|
||||
# (id, derivation_path, valid_from, valid_to, first_seen, active, version)
|
||||
# VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
# """,
|
||||
# (
|
||||
# keyset.id,
|
||||
# keyset.derivation_path,
|
||||
# keyset.valid_from or db.timestamp_now,
|
||||
# keyset.valid_to or db.timestamp_now,
|
||||
# keyset.first_seen or db.timestamp_now,
|
||||
# True,
|
||||
# keyset.version,
|
||||
# ),
|
||||
# )
|
||||
|
||||
|
||||
async def get_keyset(
|
||||
id: str = None,
|
||||
derivation_path: str = "",
|
||||
db: Database = None,
|
||||
conn: Optional[Connection] = None,
|
||||
):
|
||||
clauses = []
|
||||
values: List[Any] = []
|
||||
clauses.append("active = ?")
|
||||
values.append(True)
|
||||
if id:
|
||||
clauses.append("id = ?")
|
||||
values.append(id)
|
||||
if derivation_path:
|
||||
clauses.append("derivation_path = ?")
|
||||
values.append(derivation_path)
|
||||
where = ""
|
||||
if clauses:
|
||||
where = f"WHERE {' AND '.join(clauses)}"
|
||||
# async def get_keyset(
|
||||
# id: str = None,
|
||||
# derivation_path: str = "",
|
||||
# db: Database = None,
|
||||
# conn: Optional[Connection] = None,
|
||||
# ):
|
||||
# clauses = []
|
||||
# values: List[Any] = []
|
||||
# clauses.append("active = ?")
|
||||
# values.append(True)
|
||||
# if id:
|
||||
# clauses.append("id = ?")
|
||||
# values.append(id)
|
||||
# if derivation_path:
|
||||
# clauses.append("derivation_path = ?")
|
||||
# values.append(derivation_path)
|
||||
# where = ""
|
||||
# if clauses:
|
||||
# where = f"WHERE {' AND '.join(clauses)}"
|
||||
|
||||
rows = await (conn or db).fetchall( # type: ignore
|
||||
f"""
|
||||
SELECT * from cashu.keysets
|
||||
{where}
|
||||
""",
|
||||
tuple(values),
|
||||
)
|
||||
return [MintKeyset.from_row(row) for row in rows]
|
||||
# rows = await (conn or db).fetchall( # type: ignore
|
||||
# f"""
|
||||
# SELECT * from cashu.keysets
|
||||
# {where}
|
||||
# """,
|
||||
# tuple(values),
|
||||
# )
|
||||
# return [MintKeyset.from_row(row) for row in rows]
|
||||
|
||||
Reference in New Issue
Block a user