chore: use modern websockets instead of legacy (#3278)
This commit is contained in:
parent
114e7b8c3c
commit
65864cb216
6 changed files with 18 additions and 12 deletions
|
|
@ -7,8 +7,7 @@ from typing import Optional
|
||||||
import httpx
|
import httpx
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from websockets.legacy.client import connect
|
from websockets import Subprotocol, connect
|
||||||
from websockets.typing import Subprotocol
|
|
||||||
|
|
||||||
from lnbits import bolt11
|
from lnbits import bolt11
|
||||||
from lnbits.helpers import normalize_endpoint
|
from lnbits.helpers import normalize_endpoint
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from typing import Any, Optional
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from websockets.legacy.client import connect
|
from websockets import connect
|
||||||
|
|
||||||
from lnbits.helpers import normalize_endpoint
|
from lnbits.helpers import normalize_endpoint
|
||||||
from lnbits.settings import settings
|
from lnbits.settings import settings
|
||||||
|
|
@ -245,7 +245,9 @@ class EclairWallet(Wallet):
|
||||||
try:
|
try:
|
||||||
async with connect(
|
async with connect(
|
||||||
self.ws_url,
|
self.ws_url,
|
||||||
extra_headers=[("Authorization", self.headers["Authorization"])],
|
additional_headers=[
|
||||||
|
("Authorization", self.headers["Authorization"])
|
||||||
|
],
|
||||||
) as ws:
|
) as ws:
|
||||||
while settings.lnbits_running:
|
while settings.lnbits_running:
|
||||||
message = await ws.recv()
|
message = await ws.recv()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from typing import Optional
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from websockets.legacy.client import connect
|
from websockets import connect
|
||||||
|
|
||||||
from lnbits.helpers import normalize_endpoint
|
from lnbits.helpers import normalize_endpoint
|
||||||
from lnbits.settings import settings
|
from lnbits.settings import settings
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ from urllib.parse import parse_qs, unquote, urlparse
|
||||||
import secp256k1
|
import secp256k1
|
||||||
from bolt11 import decode as bolt11_decode
|
from bolt11 import decode as bolt11_decode
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from websockets.legacy.client import connect as ws_connect
|
from websockets import connect as ws_connect
|
||||||
|
|
||||||
from lnbits.settings import settings
|
from lnbits.settings import settings
|
||||||
from lnbits.utils.nostr import (
|
from lnbits.utils.nostr import (
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from typing import Any, Optional
|
||||||
import httpx
|
import httpx
|
||||||
from httpx import RequestError, TimeoutException
|
from httpx import RequestError, TimeoutException
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from websockets.legacy.client import connect
|
from websockets import connect
|
||||||
|
|
||||||
from lnbits.helpers import normalize_endpoint
|
from lnbits.helpers import normalize_endpoint
|
||||||
from lnbits.settings import settings
|
from lnbits.settings import settings
|
||||||
|
|
@ -300,7 +300,9 @@ class PhoenixdWallet(Wallet):
|
||||||
try:
|
try:
|
||||||
async with connect(
|
async with connect(
|
||||||
self.ws_url,
|
self.ws_url,
|
||||||
extra_headers=[("Authorization", self.headers["Authorization"])],
|
additional_headers=[
|
||||||
|
("Authorization", self.headers["Authorization"])
|
||||||
|
],
|
||||||
) as ws:
|
) as ws:
|
||||||
logger.info("connected to phoenixd invoices stream")
|
logger.info("connected to phoenixd invoices stream")
|
||||||
while settings.lnbits_running:
|
while settings.lnbits_running:
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ import secp256k1
|
||||||
from Cryptodome import Random
|
from Cryptodome import Random
|
||||||
from Cryptodome.Cipher import AES
|
from Cryptodome.Cipher import AES
|
||||||
from Cryptodome.Util.Padding import pad, unpad
|
from Cryptodome.Util.Padding import pad, unpad
|
||||||
from websockets.legacy.server import serve as ws_serve
|
from websockets import ServerConnection
|
||||||
|
from websockets import serve as ws_serve
|
||||||
|
|
||||||
from lnbits.wallets.nwc import NWCWallet
|
from lnbits.wallets.nwc import NWCWallet
|
||||||
from tests.wallets.helpers import (
|
from tests.wallets.helpers import (
|
||||||
|
|
@ -74,7 +75,9 @@ def sign_event(pub_key, priv_key, event):
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
|
||||||
async def handle(wallet, mock_settings, data, websocket, path): # noqa: C901
|
async def handle( # noqa: C901
|
||||||
|
wallet, mock_settings, data, websocket: ServerConnection
|
||||||
|
):
|
||||||
async for message in websocket:
|
async for message in websocket:
|
||||||
if not wallet:
|
if not wallet:
|
||||||
continue
|
continue
|
||||||
|
|
@ -162,8 +165,8 @@ async def run(data: WalletTest):
|
||||||
if mock_settings is None:
|
if mock_settings is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
async def handler(websocket, path):
|
def handler(websocket):
|
||||||
return await handle(wallet, mock_settings, data, websocket, path)
|
return handle(wallet, mock_settings, data, websocket)
|
||||||
|
|
||||||
if mock_settings is not None:
|
if mock_settings is not None:
|
||||||
async with ws_serve(handler, "localhost", mock_settings["port"]) as server:
|
async with ws_serve(handler, "localhost", mock_settings["port"]) as server:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue