2020-01-10 21:26:42 +01:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from typing import NamedTuple, Optional
|
|
|
|
|
|
|
|
|
|
|
|
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-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):
|
|
|
|
@abstractmethod
|
|
|
|
def create_invoice(self, amount: int, memo: str = "") -> InvoiceResponse:
|
|
|
|
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
|