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-13 03:25:55 +02: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 05:51:15 +01: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
|
2022-08-30 13:28:58 +02:00
|
|
|
fee_msat: Optional[int] = None
|
2020-10-13 04:18:37 +02: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
|
2022-08-30 13:28:58 +02:00
|
|
|
fee_msat: Optional[int] = None
|
|
|
|
preimage: Optional[str] = None
|
2020-03-07 22:27:00 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def pending(self) -> bool:
|
|
|
|
return self.paid is not True
|
2020-01-10 21:26:42 +01:00
|
|
|
|
2021-03-28 05:11:41 +02: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-13 03:25:55 +02:00
|
|
|
@abstractmethod
|
2021-03-24 05:01:09 +01:00
|
|
|
def status(self) -> Coroutine[None, None, StatusResponse]:
|
2020-10-13 03:25:55 +02:00
|
|
|
pass
|
|
|
|
|
2020-01-10 21:26:42 +01:00
|
|
|
@abstractmethod
|
2020-08-31 04:48:46 +02:00
|
|
|
def create_invoice(
|
2021-03-24 04:40:32 +01:00
|
|
|
self,
|
|
|
|
amount: int,
|
|
|
|
memo: Optional[str] = None,
|
|
|
|
description_hash: Optional[bytes] = None,
|
2021-03-24 05:01:09 +01: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 05:01:09 +01: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 05:01:09 +01:00
|
|
|
def get_payment_status(
|
|
|
|
self, checking_id: str
|
|
|
|
) -> Coroutine[None, None, PaymentStatus]:
|
2020-01-10 21:26:42 +01:00
|
|
|
pass
|
2020-06-08 00:46:16 +02:00
|
|
|
|
2020-10-02 22:13:33 +02:00
|
|
|
@abstractmethod
|
|
|
|
def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
|
|
|
pass
|
|
|
|
|
2020-06-08 00:46:16 +02:00
|
|
|
|
|
|
|
class Unsupported(Exception):
|
|
|
|
pass
|