mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-23 03:34:19 +01:00
NUTs: info endpoint method settings (#487)
* adjust info endpoint settings * respect MINT_MAX_PEG_IN MINT_MAX_PEG_OUT settings
This commit is contained in:
@@ -302,6 +302,13 @@ class MintQuote(BaseModel):
|
||||
# ------- 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
|
||||
|
||||
@@ -9,6 +9,7 @@ from ..core.base import (
|
||||
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,
|
||||
|
||||
@@ -4,6 +4,8 @@ import pytest
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user