change settings in wallets

This commit is contained in:
dni ⚡ 2022-10-05 13:01:41 +02:00
parent 017fd6bb09
commit 807317df64
10 changed files with 50 additions and 48 deletions

View file

@ -1,7 +1,6 @@
import asyncio import asyncio
import hashlib import hashlib
import json import json
from os import getenv
from typing import AsyncGenerator, Dict, Optional from typing import AsyncGenerator, Dict, Optional
import httpx import httpx
@ -21,7 +20,7 @@ class ClicheWallet(Wallet):
"""https://github.com/fiatjaf/cliche""" """https://github.com/fiatjaf/cliche"""
def __init__(self): def __init__(self):
self.endpoint = getenv("CLICHE_ENDPOINT") self.endpoint = settings.cliche_endpoint
async def status(self) -> StatusResponse: async def status(self) -> StatusResponse:
try: try:

View file

@ -8,12 +8,12 @@ import hashlib
import random import random
import time import time
from functools import partial, wraps from functools import partial, wraps
from os import getenv
from typing import AsyncGenerator, Optional from typing import AsyncGenerator, Optional
from loguru import logger from loguru import logger
from lnbits import bolt11 as lnbits_bolt11 from lnbits import bolt11 as lnbits_bolt11
from lnbits.settings import settings
from .base import ( from .base import (
InvoiceResponse, InvoiceResponse,
@ -51,7 +51,7 @@ class CoreLightningWallet(Wallet):
"The `pyln-client` library must be installed to use `CoreLightningWallet`." "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) self.ln = LightningRpc(self.rpc)
# check if description_hash is supported (from CLN>=v0.11.0) # check if description_hash is supported (from CLN>=v0.11.0)

View file

@ -3,7 +3,6 @@ import base64
import hashlib import hashlib
import json import json
import urllib.parse import urllib.parse
from os import getenv
from typing import AsyncGenerator, Dict, Optional from typing import AsyncGenerator, Dict, Optional
import httpx import httpx
@ -37,12 +36,12 @@ class UnknownError(Exception):
class EclairWallet(Wallet): class EclairWallet(Wallet):
def __init__(self): def __init__(self):
url = getenv("ECLAIR_URL") url = settings.eclair_url
self.url = url[:-1] if url.endswith("/") else url self.url = url[:-1] if url.endswith("/") else url
self.ws_url = f"ws://{urllib.parse.urlsplit(self.url).netloc}/ws" 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")) encodedAuth = base64.b64encode(f":{passw}".encode("utf-8"))
auth = str(encodedAuth, "utf-8") auth = str(encodedAuth, "utf-8")
self.auth = {"Authorization": f"Basic {auth}"} self.auth = {"Authorization": f"Basic {auth}"}

View file

@ -1,7 +1,6 @@
import asyncio import asyncio
import hashlib import hashlib
import json import json
from os import getenv
from typing import AsyncGenerator, Dict, Optional from typing import AsyncGenerator, Dict, Optional
import httpx import httpx
@ -20,12 +19,12 @@ class LNbitsWallet(Wallet):
"""https://github.com/lnbits/lnbits""" """https://github.com/lnbits/lnbits"""
def __init__(self): def __init__(self):
self.endpoint = getenv("LNBITS_ENDPOINT") self.endpoint = settings.lnbits_endpoint
key = ( key = (
getenv("LNBITS_KEY") settings.lnbits_key
or getenv("LNBITS_ADMIN_KEY") or settings.lnbits_admin_key
or getenv("LNBITS_INVOICE_KEY") or settings.lnbits_invoice_key
) )
self.key = {"X-Api-Key": key} self.key = {"X-Api-Key": key}

View file

@ -10,7 +10,7 @@ import asyncio
import base64 import base64
import binascii import binascii
import hashlib import hashlib
from os import environ, error, getenv from os import environ, error
from typing import AsyncGenerator, Dict, Optional from typing import AsyncGenerator, Dict, Optional
from loguru import logger 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 as router
import lnbits.wallets.lnd_grpc_files.router_pb2_grpc as routerrpc import lnbits.wallets.lnd_grpc_files.router_pb2_grpc as routerrpc
from lnbits.settings import settings
from .base import ( from .base import (
InvoiceResponse, InvoiceResponse,
PaymentResponse, 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." "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.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
self.port = int(getenv("LND_GRPC_PORT")) self.port = int(settings.lnd_grpc_port)
self.cert_path = getenv("LND_GRPC_CERT") or getenv("LND_CERT") self.cert_path = settings.lnd_grpc_cert or settings.lnd_cert
macaroon = ( macaroon = (
getenv("LND_GRPC_MACAROON") settings.lnd_grpc_macaroon
or getenv("LND_GRPC_ADMIN_MACAROON") or settings.lnd_grpc_admin_macaroon
or getenv("LND_ADMIN_MACAROON") or settings.lnd_admin_macaroon
or getenv("LND_GRPC_INVOICE_MACAROON") or settings.lnd_grpc_invoice_macaroon
or getenv("LND_INVOICE_MACAROON") or settings.lnd_invoice_macaroon
) )
encrypted_macaroon = getenv("LND_GRPC_MACAROON_ENCRYPTED") encrypted_macaroon = settings.lnd_grpc_macaroon_encrypted
if encrypted_macaroon: if encrypted_macaroon:
macaroon = AESCipher(description="macaroon decryption").decrypt( macaroon = AESCipher(description="macaroon decryption").decrypt(
encrypted_macaroon encrypted_macaroon

View file

@ -2,7 +2,6 @@ import asyncio
import base64 import base64
import hashlib import hashlib
import json import json
from os import getenv
from pydoc import describe from pydoc import describe
from typing import AsyncGenerator, Dict, Optional from typing import AsyncGenerator, Dict, Optional
@ -10,6 +9,7 @@ import httpx
from loguru import logger from loguru import logger
from lnbits import bolt11 as lnbits_bolt11 from lnbits import bolt11 as lnbits_bolt11
from lnbits.settings import settings
from .base import ( from .base import (
InvoiceResponse, InvoiceResponse,
@ -25,7 +25,7 @@ class LndRestWallet(Wallet):
"""https://api.lightning.community/rest/index.html#lnd-rest-api-reference""" """https://api.lightning.community/rest/index.html#lnd-rest-api-reference"""
def __init__(self): def __init__(self):
endpoint = getenv("LND_REST_ENDPOINT") endpoint = settings.lnd_rest_endpoint
endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
endpoint = ( endpoint = (
"https://" + endpoint if not endpoint.startswith("http") else endpoint "https://" + endpoint if not endpoint.startswith("http") else endpoint
@ -33,14 +33,14 @@ class LndRestWallet(Wallet):
self.endpoint = endpoint self.endpoint = endpoint
macaroon = ( macaroon = (
getenv("LND_REST_MACAROON") settings.lnd_rest_macaroon
or getenv("LND_ADMIN_MACAROON") or settings.lnd_admin_macaroon
or getenv("LND_REST_ADMIN_MACAROON") or settings.lnd_rest_admin_macaroon
or getenv("LND_INVOICE_MACAROON") or settings.lnd_invoice_macaroon
or getenv("LND_REST_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: if encrypted_macaroon:
macaroon = AESCipher(description="macaroon decryption").decrypt( macaroon = AESCipher(description="macaroon decryption").decrypt(
encrypted_macaroon encrypted_macaroon
@ -48,7 +48,7 @@ class LndRestWallet(Wallet):
self.macaroon = load_macaroon(macaroon) self.macaroon = load_macaroon(macaroon)
self.auth = {"Grpc-Metadata-macaroon": self.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: async def status(self) -> StatusResponse:
try: try:

View file

@ -2,13 +2,14 @@ import asyncio
import hashlib import hashlib
import json import json
from http import HTTPStatus from http import HTTPStatus
from os import getenv
from typing import AsyncGenerator, Dict, Optional from typing import AsyncGenerator, Dict, Optional
import httpx import httpx
from fastapi.exceptions import HTTPException from fastapi.exceptions import HTTPException
from loguru import logger from loguru import logger
from lnbits.settings import settings
from .base import ( from .base import (
InvoiceResponse, InvoiceResponse,
PaymentResponse, PaymentResponse,
@ -22,10 +23,10 @@ class LNPayWallet(Wallet):
"""https://docs.lnpay.co/""" """https://docs.lnpay.co/"""
def __init__(self): 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.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
self.wallet_key = getenv("LNPAY_WALLET_KEY") or getenv("LNPAY_ADMIN_KEY") self.wallet_key = settings.lnpay_wallet_key or settings.lnpay_admin_key
self.auth = {"X-Api-Key": getenv("LNPAY_API_KEY")} self.auth = {"X-Api-Key": settings.lnpay_api_key}
async def status(self) -> StatusResponse: async def status(self) -> StatusResponse:
url = f"{self.endpoint}/wallet/{self.wallet_key}" url = f"{self.endpoint}/wallet/{self.wallet_key}"

View file

@ -1,12 +1,13 @@
import asyncio import asyncio
import hashlib import hashlib
import json import json
from os import getenv
from typing import AsyncGenerator, Dict, Optional from typing import AsyncGenerator, Dict, Optional
import httpx import httpx
from loguru import logger from loguru import logger
from lnbits.settings import settings
from .base import ( from .base import (
InvoiceResponse, InvoiceResponse,
PaymentResponse, PaymentResponse,
@ -20,13 +21,13 @@ class LntxbotWallet(Wallet):
"""https://github.com/fiatjaf/lntxbot/blob/master/api.go""" """https://github.com/fiatjaf/lntxbot/blob/master/api.go"""
def __init__(self): def __init__(self):
endpoint = getenv("LNTXBOT_API_ENDPOINT") endpoint = settings.lntxbot_api_endpoint
self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
key = ( key = (
getenv("LNTXBOT_KEY") settings.lntxbot_key
or getenv("LNTXBOT_ADMIN_KEY") or settings.lntxbot_admin_key
or getenv("LNTXBOT_INVOICE_KEY") or settings.lntxbot_invoice_key
) )
self.auth = {"Authorization": f"Basic {key}"} self.auth = {"Authorization": f"Basic {key}"}

View file

@ -1,7 +1,6 @@
import asyncio import asyncio
import hmac import hmac
from http import HTTPStatus from http import HTTPStatus
from os import getenv
from typing import AsyncGenerator, Optional from typing import AsyncGenerator, Optional
import httpx import httpx
@ -9,6 +8,7 @@ from fastapi.exceptions import HTTPException
from loguru import logger from loguru import logger
from lnbits.helpers import url_for from lnbits.helpers import url_for
from lnbits.settings import settings
from .base import ( from .base import (
InvoiceResponse, InvoiceResponse,
@ -24,13 +24,13 @@ class OpenNodeWallet(Wallet):
"""https://developers.opennode.com/""" """https://developers.opennode.com/"""
def __init__(self): def __init__(self):
endpoint = getenv("OPENNODE_API_ENDPOINT") endpoint = settings.opennode_api_endpoint
self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint self.endpoint = endpoint[:-1] if endpoint.endswith("/") else endpoint
key = ( key = (
getenv("OPENNODE_KEY") settings.opennode_key
or getenv("OPENNODE_ADMIN_KEY") or settings.opennode_admin_key
or getenv("OPENNODE_INVOICE_KEY") or settings.opennode_invoice_key
) )
self.auth = {"Authorization": key} self.auth = {"Authorization": key}

View file

@ -2,12 +2,13 @@ import asyncio
import hashlib import hashlib
import json import json
import random import random
from os import getenv
from typing import AsyncGenerator, Optional from typing import AsyncGenerator, Optional
import httpx import httpx
from loguru import logger from loguru import logger
from lnbits.settings import settings
from .base import ( from .base import (
InvoiceResponse, InvoiceResponse,
PaymentResponse, PaymentResponse,
@ -27,8 +28,8 @@ class UnknownError(Exception):
class SparkWallet(Wallet): class SparkWallet(Wallet):
def __init__(self): def __init__(self):
self.url = getenv("SPARK_URL").replace("/rpc", "") self.url = settings.spark_url.replace("/rpc", "")
self.token = getenv("SPARK_TOKEN") self.token = settings.spark_token
def __getattr__(self, key): def __getattr__(self, key):
async def call(*args, **kwargs): async def call(*args, **kwargs):