Allow to set maximum peg in/out for mint (#209)

* Allow to set maximum peg in/out for mint

* Make format

* remove duplicate error

* move business logic to ledger

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
sihamon
2023-05-13 20:41:24 +02:00
committed by GitHub
parent aa9b5bd55c
commit e7df2028fa
4 changed files with 25 additions and 7 deletions

View File

@@ -45,6 +45,11 @@ async def info():
contact=settings.mint_info_contact,
nuts=settings.mint_info_nuts,
motd=settings.mint_info_motd,
parameter={
"max_peg_in": settings.mint_max_peg_in,
"max_peg_out": settings.mint_max_peg_out,
"peg_out_only": settings.mint_peg_out_only,
},
)
@@ -99,10 +104,13 @@ async def request_mint(amount: int = 0) -> Union[GetMintResponse, CashuError]:
"""
if settings.mint_peg_out_only:
return CashuError(code=0, error="Mint does not allow minting new tokens.")
payment_request, hash = await ledger.request_mint(amount)
print(f"Lightning invoice: {payment_request}")
resp = GetMintResponse(pr=payment_request, hash=hash)
return resp
try:
payment_request, hash = await ledger.request_mint(amount)
print(f"Lightning invoice: {payment_request}")
resp = GetMintResponse(pr=payment_request, hash=hash)
return resp
except Exception as exc:
return CashuError(code=0, error=str(exc))
@router.post(
@@ -120,14 +128,11 @@ 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:
# BEGIN: backwards compatibility < 0.12 where we used to lookup payments with payment_hash
# We use the payment_hash to lookup the hash from the database and pass that one along.
hash = payment_hash or hash
# END: backwards compatibility < 0.12
promises = await ledger.mint(payload.outputs, hash=hash)
blinded_signatures = PostMintResponse(promises=promises)
return blinded_signatures