Allow setting mint as peg-out only (#160)

* Allow setting mint as peg-out only

* Update cashu/mint/router.py

* Update cashu/mint/router.py

---------

Co-authored-by: calle <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
sihamon
2023-04-16 15:49:57 +02:00
committed by GitHub
parent d42092d62e
commit e7d7659767
2 changed files with 6 additions and 1 deletions

View File

@@ -53,6 +53,7 @@ class MintSettings(CashuSettings):
mint_listen_port: int = Field(default=3338)
mint_lightning_backend: str = Field(default="LNbitsWallet")
mint_database: str = Field(default="data/mint")
mint_peg_out_only: bool = Field(default=False)
mint_lnbits_endpoint: str = Field(default=None)
mint_lnbits_key: str = Field(default=None)

View File

@@ -90,13 +90,15 @@ async def keysets() -> KeysetsResponse:
@router.get("/mint", name="Request mint", summary="Request minting of new tokens")
async def request_mint(amount: int = 0) -> GetMintResponse:
async def request_mint(amount: int = 0) -> Union[GetMintResponse, CashuError]:
"""
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.
"""
if settings.mint_peg_out_only:
return CashuError(code=0, error="Mint does not allow minting new tokens.")
payment_request, payment_hash = await ledger.request_mint(amount)
print(f"Lightning invoice: {payment_request}")
resp = GetMintResponse(pr=payment_request, hash=payment_hash)
@@ -117,6 +119,8 @@ async def mint(
Call this endpoint after `GET /mint`.
"""
if settings.mint_peg_out_only:
return CashuError(code=0, error="Mint does not allow minting new tokens.")
try:
promises = await ledger.mint(payload.outputs, payment_hash=payment_hash)
blinded_signatures = PostMintResponse(promises=promises)