2020-01-10 21:26:42 +01:00
|
|
|
from abc import ABC, abstractmethod
|
2020-10-02 22:13:33 +02:00
|
|
|
from typing import NamedTuple, Optional, AsyncGenerator
|
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):
|
2020-03-31 19:05:25 +02:00
|
|
|
ok: bool
|
|
|
|
checking_id: Optional[str] = None # payment_hash, rcp_id
|
2020-01-16 13:58:27 +01:00
|
|
|
fee_msat: int = 0
|
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
|
|
|
|
|
|
|
|
@property
|
|
|
|
def pending(self) -> bool:
|
|
|
|
return self.paid is not True
|
2020-01-10 21:26:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Wallet(ABC):
|
2020-10-13 03:25:55 +02:00
|
|
|
@abstractmethod
|
2020-10-13 19:46:23 +02:00
|
|
|
def status(self) -> 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,
|
2020-08-31 04:48:46 +02:00
|
|
|
) -> InvoiceResponse:
|
2020-01-10 21:26:42 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2020-03-07 22:27:00 +01:00
|
|
|
def pay_invoice(self, bolt11: str) -> PaymentResponse:
|
2020-01-10 21:26:42 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2020-03-31 19:05:25 +02:00
|
|
|
def get_invoice_status(self, checking_id: str) -> PaymentStatus:
|
2020-01-10 21:26:42 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2020-03-31 19:05:25 +02:00
|
|
|
def get_payment_status(self, checking_id: str) -> 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
|