From ad81bb322a1cb8637ebbe275113f0f4266212c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Wed, 5 Oct 2022 13:01:41 +0200 Subject: [PATCH] change settings in wallets --- lnbits/wallets/cliche.py | 3 +-- lnbits/wallets/cln.py | 4 ++-- lnbits/wallets/eclair.py | 5 ++--- lnbits/wallets/lnbits.py | 9 ++++----- lnbits/wallets/lndgrpc.py | 22 ++++++++++++---------- lnbits/wallets/lndrest.py | 18 +++++++++--------- lnbits/wallets/lnpay.py | 9 +++++---- lnbits/wallets/lntxbot.py | 11 ++++++----- lnbits/wallets/opennode.py | 10 +++++----- lnbits/wallets/spark.py | 7 ++++--- 10 files changed, 50 insertions(+), 48 deletions(-) diff --git a/lnbits/wallets/cliche.py b/lnbits/wallets/cliche.py index 9b8627945..c0969cbbb 100644 --- a/lnbits/wallets/cliche.py +++ b/lnbits/wallets/cliche.py @@ -1,7 +1,6 @@ import asyncio import hashlib import json -from os import getenv from typing import AsyncGenerator, Dict, Optional import httpx @@ -21,7 +20,7 @@ class ClicheWallet(Wallet): """https://github.com/fiatjaf/cliche""" def __init__(self): - self.endpoint = getenv("CLICHE_ENDPOINT") + self.endpoint = settings.cliche_endpoint async def status(self) -> StatusResponse: try: diff --git a/lnbits/wallets/cln.py b/lnbits/wallets/cln.py index 48b96128d..4cb72f975 100644 --- a/lnbits/wallets/cln.py +++ b/lnbits/wallets/cln.py @@ -8,12 +8,12 @@ import hashlib import random import time from functools import partial, wraps -from os import getenv from typing import AsyncGenerator, Optional from loguru import logger from lnbits import bolt11 as lnbits_bolt11 +from lnbits.settings import settings from .base import ( InvoiceResponse, @@ -51,7 +51,7 @@ class CoreLightningWallet(Wallet): "The `pyln-client` library must be installed to use `CoreLightningWallet`." ) - self.rpc = getenv("CORELIGHTNING_RPC") or getenv("CLIGHTNING_RPC") + self.rpc = settings.corelightning_rpc or settings.clightning_rpc self.ln = LightningRpc(self.rpc) # check if description_hash is supported (from CLN>=v0.11.0) diff --git a/lnbits/wallets/eclair.py b/lnbits/wallets/eclair.py index c03e3f530..76fadbdb0 100644 --- a/lnbits/wallets/eclair.py +++ b/lnbits/wallets/eclair.py @@ -3,7 +3,6 @@ import base64 import hashlib import json import urllib.parse -from os import getenv from typing import AsyncGenerator, Dict, Optional import httpx @@ -37,12 +36,12 @@ class UnknownError(Exception): class EclairWallet(Wallet): def __init__(self): - url = getenv("ECLAIR_URL") + url = settings.eclair_url self.url = url[:-1] if url.endswith("/") else url self.ws_url = f"ws://{urllib.parse.urlsplit(self.url).netloc}/ws" - passw = getenv("ECLAIR_PASS") + passw = settings.eclair_pass encodedAuth = base64.b64encode(f":{passw}".encode("utf-8")) auth = str(encodedAuth, "utf-8") self.auth = {"Authorization": f"Basic {auth}"} diff --git a/lnbits/wallets/lnbits.py b/lnbits/wallets/lnbits.py index ddd80e770..749bb5300 100644 --- a/lnbits/wallets/lnbits.py +++ b/lnbits/wallets/lnbits.py @@ -1,7 +1,6 @@ import asyncio import hashlib import json -from os import getenv from typing import AsyncGenerator, Dict, Optional import httpx @@ -20,12 +19,12 @@ class LNbitsWallet(Wallet): """https://github.com/lnbits/lnbits""" def __init__(self): - self.endpoint = getenv("LNBITS_ENDPOINT") + self.endpoint = settings.lnbits_endpoint key = ( - getenv("LNBITS_KEY") - or getenv("LNBITS_ADMIN_KEY") - or getenv("LNBITS_INVOICE_KEY") + settings.lnbits_key + or settings.lnbits_admin_key + or settings.lnbits_invoice_key ) self.key = {"X-Api-Key": key} diff --git a/lnbits/wallets/lndgrpc.py b/lnbits/wallets/lndgrpc.py index 7f6135ad9..914337ba6 100644 --- a/lnbits/wallets/lndgrpc.py +++ b/lnbits/wallets/lndgrpc.py @@ -10,7 +10,7 @@ import asyncio import base64 import binascii import hashlib -from os import environ, error, getenv +from os import environ, error from typing import AsyncGenerator, Dict, Optional from loguru import logger @@ -23,6 +23,8 @@ if imports_ok: 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 ( InvoiceResponse, PaymentResponse, @@ -104,20 +106,20 @@ class LndWallet(Wallet): "The `grpcio` and `protobuf` library must be installed to use `GRPC LndWallet`. Alternatively try using the LndRESTWallet." ) - endpoint = getenv("LND_GRPC_ENDPOINT") + endpoint = settings.lnd_grpc_endpoint self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint - self.port = int(getenv("LND_GRPC_PORT")) - self.cert_path = getenv("LND_GRPC_CERT") or getenv("LND_CERT") + self.port = int(settings.lnd_grpc_port) + self.cert_path = settings.lnd_grpc_cert or settings.lnd_cert macaroon = ( - getenv("LND_GRPC_MACAROON") - or getenv("LND_GRPC_ADMIN_MACAROON") - or getenv("LND_ADMIN_MACAROON") - or getenv("LND_GRPC_INVOICE_MACAROON") - or getenv("LND_INVOICE_MACAROON") + settings.lnd_grpc_macaroon + or settings.lnd_grpc_admin_macaroon + or settings.lnd_admin_macaroon + or settings.lnd_grpc_invoice_macaroon + or settings.lnd_invoice_macaroon ) - encrypted_macaroon = getenv("LND_GRPC_MACAROON_ENCRYPTED") + encrypted_macaroon = settings.lnd_grpc_macaroon_encrypted if encrypted_macaroon: macaroon = AESCipher(description="macaroon decryption").decrypt( encrypted_macaroon diff --git a/lnbits/wallets/lndrest.py b/lnbits/wallets/lndrest.py index 1083e48a9..81157d33d 100644 --- a/lnbits/wallets/lndrest.py +++ b/lnbits/wallets/lndrest.py @@ -2,7 +2,6 @@ import asyncio import base64 import hashlib import json -from os import getenv from pydoc import describe from typing import AsyncGenerator, Dict, Optional @@ -10,6 +9,7 @@ import httpx from loguru import logger from lnbits import bolt11 as lnbits_bolt11 +from lnbits.settings import settings from .base import ( InvoiceResponse, @@ -25,7 +25,7 @@ class LndRestWallet(Wallet): """https://api.lightning.community/rest/index.html#lnd-rest-api-reference""" def __init__(self): - endpoint = getenv("LND_REST_ENDPOINT") + endpoint = settings.lnd_rest_endpoint endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint endpoint = ( "https://" + endpoint if not endpoint.startswith("http") else endpoint @@ -33,14 +33,14 @@ class LndRestWallet(Wallet): self.endpoint = endpoint macaroon = ( - getenv("LND_REST_MACAROON") - or getenv("LND_ADMIN_MACAROON") - or getenv("LND_REST_ADMIN_MACAROON") - or getenv("LND_INVOICE_MACAROON") - or getenv("LND_REST_INVOICE_MACAROON") + settings.lnd_rest_macaroon + or settings.lnd_admin_macaroon + or settings.lnd_rest_admin_macaroon + or settings.lnd_invoice_macaroon + or settings.lnd_rest_invoice_macaroon ) - encrypted_macaroon = getenv("LND_REST_MACAROON_ENCRYPTED") + encrypted_macaroon = settings.lnd_rest_macaroon_encrypted if encrypted_macaroon: macaroon = AESCipher(description="macaroon decryption").decrypt( encrypted_macaroon @@ -48,7 +48,7 @@ class LndRestWallet(Wallet): self.macaroon = load_macaroon(macaroon) self.auth = {"Grpc-Metadata-macaroon": self.macaroon} - self.cert = getenv("LND_REST_CERT", True) + self.cert = settings.lnd_rest_cert async def status(self) -> StatusResponse: try: diff --git a/lnbits/wallets/lnpay.py b/lnbits/wallets/lnpay.py index 5db68e1f2..ccc5254c9 100644 --- a/lnbits/wallets/lnpay.py +++ b/lnbits/wallets/lnpay.py @@ -2,13 +2,14 @@ import asyncio import hashlib import json from http import HTTPStatus -from os import getenv from typing import AsyncGenerator, Dict, Optional import httpx from fastapi.exceptions import HTTPException from loguru import logger +from lnbits.settings import settings + from .base import ( InvoiceResponse, PaymentResponse, @@ -22,10 +23,10 @@ class LNPayWallet(Wallet): """https://docs.lnpay.co/""" def __init__(self): - endpoint = getenv("LNPAY_API_ENDPOINT", "https://lnpay.co/v1") + endpoint = settings.lnpay_api_endpoint self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint - self.wallet_key = getenv("LNPAY_WALLET_KEY") or getenv("LNPAY_ADMIN_KEY") - self.auth = {"X-Api-Key": getenv("LNPAY_API_KEY")} + self.wallet_key = settings.lnpay_wallet_key or settings.lnpay_admin_key + self.auth = {"X-Api-Key": settings.lnpay_api_key} async def status(self) -> StatusResponse: url = f"{self.endpoint}/wallet/{self.wallet_key}" diff --git a/lnbits/wallets/lntxbot.py b/lnbits/wallets/lntxbot.py index 13046d261..ce315e75d 100644 --- a/lnbits/wallets/lntxbot.py +++ b/lnbits/wallets/lntxbot.py @@ -1,12 +1,13 @@ import asyncio import hashlib import json -from os import getenv from typing import AsyncGenerator, Dict, Optional import httpx from loguru import logger +from lnbits.settings import settings + from .base import ( InvoiceResponse, PaymentResponse, @@ -20,13 +21,13 @@ class LntxbotWallet(Wallet): """https://github.com/fiatjaf/lntxbot/blob/master/api.go""" def __init__(self): - endpoint = getenv("LNTXBOT_API_ENDPOINT") + endpoint = settings.lntxbot_api_endpoint self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint key = ( - getenv("LNTXBOT_KEY") - or getenv("LNTXBOT_ADMIN_KEY") - or getenv("LNTXBOT_INVOICE_KEY") + settings.lntxbot_key + or settings.lntxbot_admin_key + or settings.lntxbot_invoice_key ) self.auth = {"Authorization": f"Basic {key}"} diff --git a/lnbits/wallets/opennode.py b/lnbits/wallets/opennode.py index f7dcba404..ff71ef079 100644 --- a/lnbits/wallets/opennode.py +++ b/lnbits/wallets/opennode.py @@ -1,7 +1,6 @@ import asyncio import hmac from http import HTTPStatus -from os import getenv from typing import AsyncGenerator, Optional import httpx @@ -9,6 +8,7 @@ from fastapi.exceptions import HTTPException from loguru import logger from lnbits.helpers import url_for +from lnbits.settings import settings from .base import ( InvoiceResponse, @@ -24,13 +24,13 @@ class OpenNodeWallet(Wallet): """https://developers.opennode.com/""" def __init__(self): - endpoint = getenv("OPENNODE_API_ENDPOINT") + endpoint = settings.opennode_api_endpoint self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint key = ( - getenv("OPENNODE_KEY") - or getenv("OPENNODE_ADMIN_KEY") - or getenv("OPENNODE_INVOICE_KEY") + settings.opennode_key + or settings.opennode_admin_key + or settings.opennode_invoice_key ) self.auth = {"Authorization": key} diff --git a/lnbits/wallets/spark.py b/lnbits/wallets/spark.py index 414d4e470..982271756 100644 --- a/lnbits/wallets/spark.py +++ b/lnbits/wallets/spark.py @@ -2,12 +2,13 @@ import asyncio import hashlib import json import random -from os import getenv from typing import AsyncGenerator, Optional import httpx from loguru import logger +from lnbits.settings import settings + from .base import ( InvoiceResponse, PaymentResponse, @@ -27,8 +28,8 @@ class UnknownError(Exception): class SparkWallet(Wallet): def __init__(self): - self.url = getenv("SPARK_URL").replace("/rpc", "") - self.token = getenv("SPARK_TOKEN") + self.url = settings.spark_url.replace("/rpc", "") + self.token = settings.spark_token def __getattr__(self, key): async def call(*args, **kwargs):