Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Nov 2, 2023
1 parent d379192 commit 78c604a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 deletions.
48 changes: 39 additions & 9 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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]


Expand All @@ -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] = []
Expand Down
28 changes: 22 additions & 6 deletions cashu/mint/router.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Union
from typing import List, Union

from fastapi import APIRouter, Request
from loguru import logger
Expand All @@ -10,13 +10,15 @@
CheckSpendableRequest,
CheckSpendableResponse,
GetInfoResponse,
GetMintResponse,
KeysetsResponse,
KeysetsResponseKeyset,
KeysResponse,
KeysResponseKeyset,
PostMeltQuoteRequest,
PostMeltQuoteResponse,
PostMeltRequest,
PostMeltResponse,
PostMintQuoteRequest,
PostMintRequest,
PostMintResponse,
PostRestoreResponse,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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",
Expand Down

0 comments on commit 78c604a

Please sign in to comment.