Skip to content

Commit

Permalink
tests passing?
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Oct 21, 2023
1 parent b0b365d commit 4bfe2f4
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 22 deletions.
6 changes: 0 additions & 6 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cashu/mint/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
11 changes: 5 additions & 6 deletions cashu/mint/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
CheckSpendableRequest,
CheckSpendableResponse,
GetInfoResponse,
GetMintRequest,
GetMintResponse,
KeysetsResponse,
KeysetsResponseKeyset,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cashu/mint/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand All @@ -27,7 +27,7 @@
seed=settings.mint_private_key,
derivation_path=settings.mint_derivation_path,
lightning=lightning_backend,
crud=LedgerCrud(),
crud=LedgerCrudSqlite(),
)


Expand Down
2 changes: 1 addition & 1 deletion cashu/wallet/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4bfe2f4

Please sign in to comment.