refactor: make some wallet dependencies optional

This commit is contained in:
Eneko Illarramendi
2020-05-02 19:16:10 +02:00
parent 5553ed82f0
commit 2c5e539795
5 changed files with 56 additions and 169 deletions
+13 -3
View File
@@ -1,11 +1,21 @@
from os import getenv
from .base import InvoiceResponse, PaymentResponse, PaymentStatus, Wallet
from lightning import LightningRpc # type: ignore
try:
from lightning import LightningRpc # type: ignore
except ImportError: # pragma: nocover
LightningRpc = None
import random
from os import getenv
from .base import InvoiceResponse, PaymentResponse, PaymentStatus, Wallet
class CLightningWallet(Wallet):
def __init__(self):
if LightningRpc is None: # pragma: nocover
raise ImportError("The `pylightning` library must be installed to use `CLightningWallet`.")
self.l1 = LightningRpc(getenv("CLIGHTNING_RPC"))
def create_invoice(self, amount: int, memo: str = "") -> InvoiceResponse:
+8 -5
View File
@@ -1,5 +1,9 @@
try:
import lnd_grpc # type: ignore
except ImportError: # pragma: nocover
lnd_grpc = None
import base64
import lnd_grpc # type: ignore
from os import getenv
@@ -8,6 +12,9 @@ from .base import InvoiceResponse, PaymentResponse, PaymentStatus, Wallet
class LndWallet(Wallet):
def __init__(self):
if lnd_grpc is None: # pragma: nocover
raise ImportError("The `lnd-grpc` library must be installed to use `LndWallet`.")
endpoint = getenv("LND_GRPC_ENDPOINT")
self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
self.port = getenv("LND_GRPC_PORT")
@@ -16,10 +23,6 @@ class LndWallet(Wallet):
self.auth_read = getenv("LND_READ_MACAROON")
self.auth_cert = getenv("LND_CERT")
lnd_rpc = lnd_grpc.Client(
lnd_dir=None, tls_cert_path=self.auth_cert, network="mainnet", grpc_host=self.endpoint, grpc_port=self.port
)
def create_invoice(self, amount: int, memo: str = "") -> InvoiceResponse:
lnd_rpc = lnd_grpc.Client(
lnd_dir=None,