fix: wallets not loading when protobuf is missing

This commit is contained in:
Stefan Stammberger 2021-11-09 18:15:07 +01:00
parent a50c7b6e3a
commit 8ea2d20389
No known key found for this signature in database
GPG Key ID: 645FA807E935D9D5
2 changed files with 10 additions and 6 deletions

View File

@ -29,7 +29,7 @@ Using this wallet requires the installation of the `pylightning` Python package.
### LND (gRPC)
Using this wallet requires the installation of the `grpcio` Python packages.
Using this wallet requires the installation of the `grpcio` and `protobuf` Python packages.
- `LNBITS_BACKEND_WALLET_CLASS`: **LndWallet**
- `LND_GRPC_ENDPOINT`: ip_address

View File

@ -1,7 +1,10 @@
imports_ok = True
try:
from google import protobuf
import grpc
except ImportError: # pragma: nocover
grpc = None
imports_ok = False
import binascii
import base64
@ -9,8 +12,9 @@ import hashlib
from os import environ, error, getenv
from typing import Optional, Dict, AsyncGenerator
import lnbits.wallets.lnd_grpc_files.lightning_pb2 as ln
import lnbits.wallets.lnd_grpc_files.lightning_pb2_grpc as lnrpc
if imports_ok:
import lnbits.wallets.lnd_grpc_files.lightning_pb2 as ln
import lnbits.wallets.lnd_grpc_files.lightning_pb2_grpc as lnrpc
from .base import (
StatusResponse,
@ -76,9 +80,9 @@ environ["GRPC_SSL_CIPHER_SUITES"] = "HIGH+ECDSA"
class LndWallet(Wallet):
def __init__(self):
if grpc is None: # pragma: nocover
if not imports_ok: # pragma: nocover
raise ImportError(
"The `grpcio` library must be installed to use `GRPC LndWallet`. Alternatively try using the LndRESTWallet."
"The `grpcio` and `protobuf` library must be installed to use `GRPC LndWallet`. Alternatively try using the LndRESTWallet."
)
endpoint = getenv("LND_GRPC_ENDPOINT")