2020-01-10 21:26:42 +01:00
|
|
|
from abc import ABC, abstractmethod
|
2022-07-16 14:23:03 +02:00
|
|
|
from typing import AsyncGenerator, Coroutine, NamedTuple, Optional
|
2020-01-10 21:26:42 +01:00
|
|
|
|
|
|
|
|
2020-10-12 22:25:55 -03:00
|
|
|
class StatusResponse(NamedTuple):
|
|
|
|
error_message: Optional[str]
|
|
|
|
balance_msat: int
|
|
|
|
|
|
|
|
|
2020-01-10 21:26:42 +01:00
|
|
|
class InvoiceResponse(NamedTuple):
|
2020-03-31 19:05:25 +02:00
|
|
|
ok: bool
|
|
|
|
checking_id: Optional[str] = None # payment_hash, rpc_id
|
2020-01-10 21:26:42 +01:00
|
|
|
payment_request: Optional[str] = None
|
2020-03-31 19:05:25 +02:00
|
|
|
error_message: Optional[str] = None
|
2020-01-10 21:26:42 +01:00
|
|
|
|
|
|
|
|
2020-01-16 13:58:27 +01:00
|
|
|
class PaymentResponse(NamedTuple):
|
2021-03-24 01:51:15 -03:00
|
|
|
# when ok is None it means we don't know if this succeeded
|
|
|
|
ok: Optional[bool] = None
|
2020-03-31 19:05:25 +02:00
|
|
|
checking_id: Optional[str] = None # payment_hash, rcp_id
|
2020-01-16 13:58:27 +01:00
|
|
|
fee_msat: int = 0
|
2020-10-12 23:18:37 -03:00
|
|
|
preimage: Optional[str] = None
|
2020-03-07 22:27:00 +01:00
|
|
|
error_message: Optional[str] = None
|
2020-01-16 13:58:27 +01:00
|
|
|
|
|
|
|
|
2020-03-07 22:27:00 +01:00
|
|
|
class PaymentStatus(NamedTuple):
|
|
|
|
paid: Optional[bool] = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def pending(self) -> bool:
|
|
|
|
return self.paid is not True
|
2020-01-10 21:26:42 +01:00
|
|
|
|
2021-03-28 00:11:41 -03:00
|
|
|
@property
|
|
|
|
def failed(self) -> bool:
|
|
|
|
return self.paid == False
|
|
|
|
|
|
|
|
def __str__(self) -> str:
|
|
|
|
if self.paid == True:
|
|
|
|
return "settled"
|
|
|
|
elif self.paid == False:
|
|
|
|
return "failed"
|
|
|
|
elif self.paid == None:
|
|
|
|
return "still pending"
|
|
|
|
else:
|
|
|
|
return "unknown (should never happen)"
|
|
|
|
|
2020-01-10 21:26:42 +01:00
|
|
|
|
|
|
|
class Wallet(ABC):
|
2020-10-12 22:25:55 -03:00
|
|
|
@abstractmethod
|
2021-03-24 01:01:09 -03:00
|
|
|
def status(self) -> Coroutine[None, None, StatusResponse]:
|
2020-10-12 22:25:55 -03:00
|
|
|
pass
|
|
|
|
|
2020-01-10 21:26:42 +01:00
|
|
|
@abstractmethod
|
2020-08-30 23:48:46 -03:00
|
|
|
def create_invoice(
|
2021-03-24 00:40:32 -03:00
|
|
|
self,
|
|
|
|
amount: int,
|
|
|
|
memo: Optional[str] = None,
|
|
|
|
description_hash: Optional[bytes] = None,
|
2021-03-24 01:01:09 -03:00
|
|
|
) -> Coroutine[None, None, InvoiceResponse]:
|
2020-01-10 21:26:42 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2022-03-16 07:20:15 +01:00
|
|
|
def pay_invoice(
|
|
|
|
self, bolt11: str, fee_limit_msat: int
|
|
|
|
) -> Coroutine[None, None, PaymentResponse]:
|
2020-01-10 21:26:42 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2021-03-24 01:01:09 -03:00
|
|
|
def get_invoice_status(
|
|
|
|
self, checking_id: str
|
|
|
|
) -> Coroutine[None, None, PaymentStatus]:
|
2020-01-10 21:26:42 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2021-03-24 01:01:09 -03:00
|
|
|
def get_payment_status(
|
|
|
|
self, checking_id: str
|
|
|
|
) -> Coroutine[None, None, PaymentStatus]:
|
2020-01-10 21:26:42 +01:00
|
|
|
pass
|
2020-06-07 19:46:16 -03:00
|
|
|
|
2020-10-02 17:13:33 -03:00
|
|
|
@abstractmethod
|
|
|
|
def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
|
|
|
pass
|
|
|
|
|
2020-06-07 19:46:16 -03:00
|
|
|
|
|
|
|
class Unsupported(Exception):
|
|
|
|
pass
|