diff --git a/cashu/core/base.py b/cashu/core/base.py index e7cb961c..e1edb51b 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -246,36 +246,61 @@ class KeysetsResponse_deprecated(BaseModel): keysets: list[str] -# ------- API: MINT ------- +# ------- API: MINT QUOTE ------- + +class PostMintQuoteRequest(BaseModel): + method: str # Payment method + symbol: str # Payment symbol + amount: int # Amount of payment -class GetMintResponse(BaseModel): + +class PostMintQuoteResponse(BaseModel): request: str # payment request method: str # payment method symbol: str # payment symbol amount: int # amount of payment - id: str # payment lookup id + id: str # quote id -class GetMintResponse_deprecated(BaseModel): - pr: str - hash: str +# ------- API: MINT ------- class PostMintRequest(BaseModel): - outputs: List[BlindedMessage] + id: str # quote id + outputs: List[BlindedMessage] # outputs to mint class PostMintResponse(BaseModel): promises: List[BlindedSignature] = [] +class GetMintResponse_deprecated(BaseModel): + pr: str + hash: str + + +# ------- API: MELT QUOTE ------- + + +class PostMeltQuoteRequest(BaseModel): + symbol: str + method: str + request: str + + +class PostMeltQuoteResponse(BaseModel): + symbol: str + amount: int + fee: int + fee_reserve: int + + # ------- API: MELT ------- class PostMeltRequest(BaseModel): proofs: List[Proof] - method: str request: str outputs: Union[List[BlindedMessage], None] @@ -303,7 +328,6 @@ class PostMeltResponse_deprecated(BaseModel): class PostSplitRequest(BaseModel): proofs: List[Proof] - amount: Optional[int] = None # deprecated since 0.13.0 outputs: List[BlindedMessage] @@ -312,6 +336,12 @@ class PostSplitResponse(BaseModel): # deprecated since 0.13.0 +class PostSplitRequest_Deprecated(BaseModel): + proofs: List[Proof] + amount: Optional[int] = None + outputs: List[BlindedMessage] + + class PostSplitResponse_Deprecated(BaseModel): fst: List[BlindedSignature] = [] snd: List[BlindedSignature] = [] diff --git a/cashu/mint/router.py b/cashu/mint/router.py index 60082d6f..35d751d3 100644 --- a/cashu/mint/router.py +++ b/cashu/mint/router.py @@ -1,4 +1,4 @@ -from typing import List, Optional, Union +from typing import List, Union from fastapi import APIRouter, Request from loguru import logger @@ -10,13 +10,15 @@ CheckSpendableRequest, CheckSpendableResponse, GetInfoResponse, - GetMintResponse, KeysetsResponse, KeysetsResponseKeyset, KeysResponse, KeysResponseKeyset, + PostMeltQuoteRequest, + PostMeltQuoteResponse, PostMeltRequest, PostMeltResponse, + PostMintQuoteRequest, PostMintRequest, PostMintResponse, PostRestoreResponse, @@ -140,7 +142,7 @@ async def keysets() -> KeysetsResponse: " after payment." ), ) -async def request_mint(amount: int) -> GetMintResponse: +async def request_mint(payload: PostMintQuoteRequest) -> GetMintResponse: """ Request minting of new tokens. The mint responds with a Lightning invoice. This endpoint can be used for a Lightning invoice UX flow. @@ -176,8 +178,6 @@ async def request_mint(amount: int) -> GetMintResponse: ) async def mint( payload: PostMintRequest, - id: Optional[str] = None, - hash: Optional[str] = None, ) -> PostMintResponse: """ Requests the minting of tokens belonging to a paid payment request. @@ -186,12 +186,28 @@ async def mint( """ logger.trace(f"> POST /mint: {payload}") - promises = await ledger.mint(outputs=payload.outputs, id=id or hash) + promises = await ledger.mint(outputs=payload.outputs, id=payload.id) blinded_signatures = PostMintResponse(promises=promises) logger.trace(f"< POST /mint: {blinded_signatures}") return blinded_signatures +@router.post( + "/v1/melt/quote", + summary="Request a quote for melting tokens", + response_model=PostMeltQuoteResponse, + response_description="Melt tokens for a payment on a supported payment method.", +) +async def melt_quote(payload: PostMeltQuoteRequest): + """ + Request a quote for melting tokens. + """ + logger.trace(f"> POST /melt/quote: {payload}") + quote = await ledger.melt_quote(payload.outputs) # TODO + logger.trace(f"< POST /melt/quote: {quote}") + return PostMeltQuoteResponse(quote=quote) + + @router.post( "/v1/melt", name="Melt tokens",