mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-10 09:19:42 +01:00
[REFACTOR] grpcio and protofbuf for lndgrpc is not optional (#1886)
also removed dead code def get_ssl_context black
This commit is contained in:
parent
576e20d0cd
commit
8f0c1f6a80
1 changed files with 6 additions and 53 deletions
|
@ -4,8 +4,13 @@ import hashlib
|
|||
from os import environ
|
||||
from typing import AsyncGenerator, Dict, Optional
|
||||
|
||||
import grpc
|
||||
from loguru import logger
|
||||
|
||||
import lnbits.wallets.lnd_grpc_files.lightning_pb2 as ln
|
||||
import lnbits.wallets.lnd_grpc_files.lightning_pb2_grpc as lnrpc
|
||||
import lnbits.wallets.lnd_grpc_files.router_pb2 as router
|
||||
import lnbits.wallets.lnd_grpc_files.router_pb2_grpc as routerrpc
|
||||
from lnbits.settings import settings
|
||||
|
||||
from .base import (
|
||||
|
@ -17,52 +22,6 @@ from .base import (
|
|||
)
|
||||
from .macaroon import AESCipher, load_macaroon
|
||||
|
||||
imports_ok = True
|
||||
try:
|
||||
import grpc
|
||||
from grpc import RpcError
|
||||
except ImportError: # pragma: nocover
|
||||
imports_ok = False
|
||||
|
||||
if imports_ok:
|
||||
import lnbits.wallets.lnd_grpc_files.lightning_pb2 as ln
|
||||
import lnbits.wallets.lnd_grpc_files.lightning_pb2_grpc as lnrpc
|
||||
import lnbits.wallets.lnd_grpc_files.router_pb2 as router
|
||||
import lnbits.wallets.lnd_grpc_files.router_pb2_grpc as routerrpc
|
||||
|
||||
|
||||
def get_ssl_context(cert_path: str):
|
||||
import ssl
|
||||
|
||||
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
||||
context.options |= ssl.OP_NO_SSLv2
|
||||
context.options |= ssl.OP_NO_SSLv3
|
||||
context.options |= ssl.OP_NO_TLSv1
|
||||
context.options |= ssl.OP_NO_TLSv1_1
|
||||
context.options |= ssl.OP_NO_COMPRESSION
|
||||
context.set_ciphers(
|
||||
":".join(
|
||||
[
|
||||
"ECDHE+AESGCM",
|
||||
"ECDHE+CHACHA20",
|
||||
"DHE+AESGCM",
|
||||
"DHE+CHACHA20",
|
||||
"ECDH+AESGCM",
|
||||
"DH+AESGCM",
|
||||
"ECDH+AES",
|
||||
"DH+AES",
|
||||
"RSA+AESGCM",
|
||||
"RSA+AES",
|
||||
"!aNULL",
|
||||
"!eNULL",
|
||||
"!MD5",
|
||||
"!DSS",
|
||||
]
|
||||
)
|
||||
)
|
||||
context.load_verify_locations(capath=cert_path)
|
||||
return context
|
||||
|
||||
|
||||
def b64_to_bytes(checking_id: str) -> bytes:
|
||||
return base64.b64decode(checking_id.replace("_", "/"))
|
||||
|
@ -98,12 +57,6 @@ environ["GRPC_SSL_CIPHER_SUITES"] = "HIGH+ECDSA"
|
|||
|
||||
class LndWallet(Wallet):
|
||||
def __init__(self):
|
||||
if not imports_ok: # pragma: nocover
|
||||
raise ImportError(
|
||||
"The `grpcio` and `protobuf` library must be installed to use `GRPC"
|
||||
" LndWallet`. Alternatively try using the LndRESTWallet."
|
||||
)
|
||||
|
||||
endpoint = settings.lnd_grpc_endpoint
|
||||
|
||||
macaroon = (
|
||||
|
@ -242,7 +195,7 @@ class LndWallet(Wallet):
|
|||
return PaymentStatus(None)
|
||||
try:
|
||||
resp = await self.rpc.LookupInvoice(ln.PaymentHash(r_hash=r_hash))
|
||||
except RpcError:
|
||||
except grpc.RpcError:
|
||||
return PaymentStatus(None)
|
||||
if resp.settled:
|
||||
return PaymentStatus(True)
|
||||
|
|
Loading…
Add table
Reference in a new issue