diff --git a/cashu/core/base.py b/cashu/core/base.py index d0a3eff3..c2694ec9 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -302,6 +302,13 @@ def from_row(cls, row: Row): # ------- API: INFO ------- +class MintMeltMethodSetting(BaseModel): + method: str + unit: str + min_amount: Optional[int] = None + max_amount: Optional[int] = None + + class GetInfoResponse(BaseModel): name: Optional[str] = None pubkey: Optional[str] = None diff --git a/cashu/mint/router.py b/cashu/mint/router.py index 58af4203..50c41c7f 100644 --- a/cashu/mint/router.py +++ b/cashu/mint/router.py @@ -9,6 +9,7 @@ KeysetsResponseKeyset, KeysResponse, KeysResponseKeyset, + MintMeltMethodSetting, PostCheckStateRequest, PostCheckStateResponse, PostMeltQuoteRequest, @@ -41,19 +42,31 @@ async def info() -> GetInfoResponse: logger.trace("> GET /v1/info") # determine all method-unit pairs - method_unit_pairs: List[List[str]] = [] - for method, unit_dict in ledger.backends.items(): - for unit in unit_dict.keys(): - method_unit_pairs.append([method.name, unit.name]) + method_settings: Dict[int, List[MintMeltMethodSetting]] = {} + for nut in [4, 5]: + method_settings[nut] = [] + for method, unit_dict in ledger.backends.items(): + for unit in unit_dict.keys(): + setting = MintMeltMethodSetting(method=method.name, unit=unit.name) + + if nut == 4 and settings.mint_max_peg_in: + setting.max_amount = settings.mint_max_peg_in + setting.min_amount = 0 + elif nut == 5 and settings.mint_max_peg_out: + setting.max_amount = settings.mint_max_peg_out + setting.min_amount = 0 + + method_settings[nut].append(setting) + supported_dict = dict(supported=True) mint_features: Dict[int, Dict[str, Any]] = { 4: dict( - methods=method_unit_pairs, - disabled=False, + methods=method_settings[4], + disabled=settings.mint_peg_out_only, ), 5: dict( - methods=method_unit_pairs, + methods=method_settings[5], disabled=False, ), 7: supported_dict, diff --git a/tests/test_mint_api.py b/tests/test_mint_api.py index b5e5b64b..fab370a6 100644 --- a/tests/test_mint_api.py +++ b/tests/test_mint_api.py @@ -4,6 +4,8 @@ import pytest_asyncio from cashu.core.base import ( + GetInfoResponse, + MintMeltMethodSetting, PostCheckStateRequest, PostCheckStateResponse, PostMintRequest, @@ -40,6 +42,12 @@ async def test_info(ledger: Ledger): assert response.status_code == 200, f"{response.url} {response.status_code}" assert ledger.pubkey assert response.json()["pubkey"] == ledger.pubkey.serialize().hex() + info = GetInfoResponse(**response.json()) + assert info.nuts + assert info.nuts[4]["disabled"] is False + setting = MintMeltMethodSetting.parse_obj(info.nuts[4]["methods"][0]) + assert setting.method == "bolt11" + assert setting.unit == "sat" @pytest.mark.asyncio