diff --git a/cashu/core/base.py b/cashu/core/base.py index ac5b1ada..e7cb961c 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -249,12 +249,6 @@ class KeysetsResponse_deprecated(BaseModel): # ------- API: MINT ------- -class GetMintRequest(BaseModel): - amount: int - method: str - symbol: str - - class GetMintResponse(BaseModel): request: str # payment request method: str # payment method diff --git a/cashu/mint/crud.py b/cashu/mint/crud.py index 35b90c18..a6e7c2f9 100644 --- a/cashu/mint/crud.py +++ b/cashu/mint/crud.py @@ -34,7 +34,7 @@ async def get_secrets_used( self, db: Database, conn: Optional[Connection] = None, - ) -> List[str]: + ) -> Optional[List[str]]: ... async def invalidate_proof( @@ -169,11 +169,11 @@ async def get_secrets_used( *, db: Database, conn: Optional[Connection] = None, - ) -> List[str]: + ) -> Optional[List[str]]: rows = await (conn or db).fetchall(f""" SELECT secret from {table_with_schema(db, 'proofs_used')} """) - return [row[0] for row in rows] + return [row[0] for row in rows] if rows else None async def invalidate_proof( self, diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index ef72bfe1..3b7e8ea1 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -599,8 +599,9 @@ async def load_used_proofs(self) -> None: """Load all used proofs from database.""" logger.trace("crud: loading used proofs") secrets_used = await self.crud.get_secrets_used(db=self.db) - logger.trace(f"crud: loaded {len(secrets_used)} used proofs") - self.secrets_used = set(secrets_used) + if secrets_used: + logger.trace(f"crud: loaded {len(secrets_used)} used proofs") + self.secrets_used = set(secrets_used) def _check_spendable(self, proof: Proof) -> bool: """Checks whether the proof was already spent.""" diff --git a/cashu/mint/router.py b/cashu/mint/router.py index 01047d91..60082d6f 100644 --- a/cashu/mint/router.py +++ b/cashu/mint/router.py @@ -10,7 +10,6 @@ CheckSpendableRequest, CheckSpendableResponse, GetInfoResponse, - GetMintRequest, GetMintResponse, KeysetsResponse, KeysetsResponseKeyset, @@ -141,26 +140,26 @@ async def keysets() -> KeysetsResponse: " after payment." ), ) -async def request_mint(payload: GetMintRequest) -> GetMintResponse: +async def request_mint(amount: int) -> GetMintResponse: """ Request minting of new tokens. The mint responds with a Lightning invoice. This endpoint can be used for a Lightning invoice UX flow. Call `POST /mint` after paying the invoice. """ - logger.trace(f"> GET /mint: amount={payload.amount}") - if payload.amount > 21_000_000 * 100_000_000 or payload.amount <= 0: + logger.trace(f"> GET /mint: amount={amount}") + if amount > 21_000_000 * 100_000_000 or amount <= 0: raise CashuError(code=0, detail="Amount must be a valid amount of sat.") if settings.mint_peg_out_only: raise CashuError(code=0, detail="Mint does not allow minting new tokens.") - payment_request, id = await ledger.request_mint(payload.amount) + payment_request, id = await ledger.request_mint(amount) resp = GetMintResponse( request=payment_request, id=id, method="bolt11", symbol="sat", - amount=payload.amount, + amount=amount, ) logger.trace(f"< GET /mint: {resp}") return resp diff --git a/cashu/mint/startup.py b/cashu/mint/startup.py index 162c853f..d9a39f81 100644 --- a/cashu/mint/startup.py +++ b/cashu/mint/startup.py @@ -10,7 +10,7 @@ from ..core.migrations import migrate_databases from ..core.settings import settings from ..mint import migrations -from ..mint.crud import LedgerCrud +from ..mint.crud import LedgerCrudSqlite from ..mint.ledger import Ledger logger.debug("Enviroment Settings:") @@ -27,7 +27,7 @@ seed=settings.mint_private_key, derivation_path=settings.mint_derivation_path, lightning=lightning_backend, - crud=LedgerCrud(), + crud=LedgerCrudSqlite(), ) diff --git a/cashu/wallet/deprecated.py b/cashu/wallet/deprecated.py index c6e84cac..8830a542 100644 --- a/cashu/wallet/deprecated.py +++ b/cashu/wallet/deprecated.py @@ -190,7 +190,7 @@ async def request_mint_deprecated(self, amount) -> Invoice: self.raise_on_error(resp) return_dict = resp.json() mint_response = GetMintResponse_deprecated.parse_obj(return_dict) - return Invoice(amount=amount, pr=mint_response.pr, hash=mint_response.hash) + return Invoice(amount=amount, bolt11=mint_response.pr, id=mint_response.hash) @async_set_requests async def mint_deprecated( diff --git a/tests/conftest.py b/tests/conftest.py index 02751323..9eecb01e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,7 @@ from cashu.core.settings import settings from cashu.lightning.fake import FakeWallet from cashu.mint import migrations as migrations_mint -from cashu.mint.crud import LedgerCrud +from cashu.mint.crud import LedgerCrudSqlite from cashu.mint.ledger import Ledger SERVER_PORT = 3337 @@ -65,7 +65,7 @@ async def start_mint_init(ledger: Ledger): seed=settings.mint_private_key, derivation_path=settings.mint_derivation_path, lightning=FakeWallet(), - crud=LedgerCrud(), + crud=LedgerCrudSqlite(), ) await start_mint_init(ledger) yield ledger