mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
* init flake8 * exclude nostr client, and add ds_store to gitignore * fix flake8 F811 issue, redefinition of unused variables * add flake8 to workflow * F401 unused imports * F541 f-string is missing placeholders * E501 line too long > 150 characters * E722 no bare except * E402 module level import not at top of file * F405 no star imports * E712 comparison to False should be 'if cond is False:' * F841 local variable is assigned to but never used * E266 too many leading '#' for block comment * E265, E261 * E713 test for membership should be 'not in' * E711, E741 E741 ambiguous variable name 'l' E711 comparison to None should be 'if cond is None:' * flake config * isort * refactor makefile flake8 usage * reflaking the rebase * black * fix tests? * black * fix line lenght it test_cli * sort out makefile * fix strings * reintroduce black-check * reflake and mypy * isort * Update cashu/wallet/wallet.py Co-authored-by: Angus Pearson <angus@toaster.cc> * Update cashu/mint/ledger.py Co-authored-by: Angus Pearson <angus@toaster.cc> --------- Co-authored-by: Angus Pearson <angus@toaster.cc>
89 lines
2.1 KiB
Python
89 lines
2.1 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import Coroutine, NamedTuple, Optional
|
|
|
|
|
|
class StatusResponse(NamedTuple):
|
|
error_message: Optional[str]
|
|
balance_msat: int
|
|
|
|
|
|
class InvoiceResponse(NamedTuple):
|
|
ok: bool
|
|
checking_id: Optional[str] = None # payment_hash, rpc_id
|
|
payment_request: Optional[str] = None
|
|
error_message: Optional[str] = None
|
|
|
|
|
|
class PaymentResponse(NamedTuple):
|
|
# when ok is None it means we don't know if this succeeded
|
|
ok: Optional[bool] = None
|
|
checking_id: Optional[str] = None # payment_hash, rcp_id
|
|
fee_msat: Optional[int] = None
|
|
preimage: Optional[str] = None
|
|
error_message: Optional[str] = None
|
|
|
|
|
|
class PaymentStatus(NamedTuple):
|
|
paid: Optional[bool] = None
|
|
fee_msat: Optional[int] = None
|
|
preimage: Optional[str] = None
|
|
|
|
@property
|
|
def pending(self) -> bool:
|
|
return self.paid is not True
|
|
|
|
@property
|
|
def failed(self) -> bool:
|
|
return self.paid is False
|
|
|
|
def __str__(self) -> str:
|
|
if self.paid is True:
|
|
return "settled"
|
|
elif self.paid is False:
|
|
return "failed"
|
|
elif self.paid is None:
|
|
return "still pending"
|
|
else:
|
|
return "unknown (should never happen)"
|
|
|
|
|
|
class Wallet(ABC):
|
|
@abstractmethod
|
|
def status(self) -> Coroutine[None, None, StatusResponse]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def create_invoice(
|
|
self,
|
|
amount: int,
|
|
memo: Optional[str] = None,
|
|
description_hash: Optional[bytes] = None,
|
|
) -> Coroutine[None, None, InvoiceResponse]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def pay_invoice(
|
|
self, bolt11: str, fee_limit_msat: int
|
|
) -> Coroutine[None, None, PaymentResponse]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_invoice_status(
|
|
self, checking_id: str
|
|
) -> Coroutine[None, None, PaymentStatus]:
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_payment_status(
|
|
self, checking_id: str
|
|
) -> Coroutine[None, None, PaymentStatus]:
|
|
pass
|
|
|
|
# @abstractmethod
|
|
# def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
|
# pass
|
|
|
|
|
|
class Unsupported(Exception):
|
|
pass
|