Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUTs: info endpoint method settings #487

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 20 additions & 7 deletions cashu/mint/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
KeysetsResponseKeyset,
KeysResponse,
KeysResponseKeyset,
MintMeltMethodSetting,
PostCheckStateRequest,
PostCheckStateResponse,
PostMeltQuoteRequest,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_mint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pytest_asyncio

from cashu.core.base import (
GetInfoResponse,
MintMeltMethodSetting,
PostCheckStateRequest,
PostCheckStateResponse,
PostMintRequest,
Expand Down Expand Up @@ -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
Expand Down
Loading