mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
* mint does not start yet * fix import * revert mint db migrations * handle zero fee case * cli: adjust fee message * wallet: replace requests with httpx * clean up * rename http client decorator * fix pending check in main, todo: TEST PROXIES WITH HTTPX * fix up * use httpx for nostr as well * update packages to same versions as https://github.com/lnbits/lnbits/pull/1609/files * fix proof deserialization * check for string * tests passing * adjust wallet api tests * lockfile * add correct responses to Lightning interface and delete melt_id for proofs for which the payent has failed * fix create_invoice checking_id response * migrations atomic * proofs are stored automatically when created * make format * use bolt11 lib * stricter type checking * add fee response to payments * assert fees in test_melt * test that mint_id and melt_id is stored correctly in proofs and proofs_used * remove traces * refactor: Lightning interface into own file and LedgerCrud with typing * fix tests * fix payment response * rename variable
90 lines
2.1 KiB
Python
90 lines
2.1 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import Coroutine, Optional
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class StatusResponse(BaseModel):
|
|
error_message: Optional[str]
|
|
balance_msat: int
|
|
|
|
|
|
class InvoiceResponse(BaseModel):
|
|
ok: bool # True: invoice created, False: failed
|
|
checking_id: Optional[str] = None
|
|
payment_request: Optional[str] = None
|
|
error_message: Optional[str] = None
|
|
|
|
|
|
class PaymentResponse(BaseModel):
|
|
ok: Optional[bool] = None # True: paid, False: failed, None: pending or unknown
|
|
checking_id: Optional[str] = None
|
|
fee_msat: Optional[int] = None
|
|
preimage: Optional[str] = None
|
|
error_message: Optional[str] = None
|
|
|
|
|
|
class PaymentStatus(BaseModel):
|
|
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
|