This commit is contained in:
callebtc
2022-10-11 00:48:05 +02:00
parent 6838b0be05
commit 74df219d6d
3 changed files with 37 additions and 14 deletions

View File

@@ -7,7 +7,7 @@ on:
branches: [main]
jobs:
poetry:
format:
runs-on: ubuntu-latest
strategy:
matrix:
@@ -29,3 +29,23 @@ jobs:
run: poetry run black --check .
- name: Check isort
run: poetry run isort --profile black --check-only .
mypy:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9"]
poetry-version: ["1.2.1"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Set up Poetry ${{ matrix.poetry-version }}
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install packages
run: poetry install --with dev
- name: Mypy
run: poetry run mypy cashu --ignore-missing

View File

@@ -79,9 +79,9 @@ class Wallet(ABC):
) -> Coroutine[None, None, PaymentStatus]:
pass
@abstractmethod
def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
pass
# @abstractmethod
# def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
# pass
class Unsupported(Exception):

View File

@@ -1,4 +1,4 @@
from typing import Union
from typing import Union, List, Dict
from fastapi import APIRouter
from secp256k1 import PublicKey
@@ -13,6 +13,7 @@ from cashu.core.base import (
MintRequest,
PostSplitResponse,
SplitRequest,
BlindedSignature,
)
from cashu.core.errors import CashuError
from cashu.mint import ledger
@@ -21,19 +22,19 @@ router: APIRouter = APIRouter()
@router.get("/keys")
def keys():
def keys() -> dict[int, str]:
"""Get the public keys of the mint"""
return ledger.get_keyset()
@router.get("/keysets")
def keysets():
def keysets() -> dict[str, list[str]]:
"""Get all active keysets of the mint"""
return {"keysets": ledger.keysets.get_ids()}
@router.get("/mint")
async def request_mint(amount: int = 0):
async def request_mint(amount: int = 0) -> GetMintResponse:
"""
Request minting of new tokens. The mint responds with a Lightning invoice.
This endpoint can be used for a Lightning invoice UX flow.
@@ -50,7 +51,7 @@ async def request_mint(amount: int = 0):
async def mint(
payloads: MintRequest,
payment_hash: Union[str, None] = None,
):
) -> Union[List[BlindedSignature], CashuError]:
"""
Requests the minting of tokens belonging to a paid payment request.
@@ -69,7 +70,7 @@ async def mint(
@router.post("/melt")
async def melt(payload: MeltRequest):
async def melt(payload: MeltRequest) -> GetMeltResponse:
"""
Requests tokens to be destroyed and sent out via Lightning.
"""
@@ -79,13 +80,13 @@ async def melt(payload: MeltRequest):
@router.post("/check")
async def check_spendable(payload: CheckRequest):
async def check_spendable(payload: CheckRequest) -> Dict[int, bool]:
"""Check whether a secret has been spent already or not."""
return await ledger.check_spendable(payload.proofs)
@router.post("/checkfees")
async def check_fees(payload: CheckFeesRequest):
async def check_fees(payload: CheckFeesRequest) -> CheckFeesResponse:
"""
Responds with the fees necessary to pay a Lightning invoice.
Used by wallets for figuring out the fees they need to supply.
@@ -96,7 +97,9 @@ async def check_fees(payload: CheckFeesRequest):
@router.post("/split")
async def split(payload: SplitRequest):
async def split(
payload: SplitRequest,
) -> Union[CashuError, PostSplitResponse]:
"""
Requetst a set of tokens with amount "total" to be split into two
newly minted sets with amount "split" and "total-split".
@@ -111,7 +114,7 @@ async def split(payload: SplitRequest):
except Exception as exc:
return CashuError(error=str(exc))
if not split_return:
return {"error": "there was a problem with the split."}
return CashuError(error="there was an error with the split")
frst_promises, scnd_promises = split_return
resp = PostSplitResponse(fst=frst_promises, snd=scnd_promises)
return resp