mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2024-11-19 18:11:30 +01:00
migrate from aiohttp to httpx following master.
This commit is contained in:
parent
2c92205703
commit
bbe8d05af4
@ -1,4 +1,4 @@
|
||||
import aiohttp
|
||||
import httpx
|
||||
|
||||
from lnbits.core.models import Payment
|
||||
|
||||
@ -13,9 +13,9 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||
# no pay_link or this webhook has already been sent
|
||||
return
|
||||
if pay_link.webhook_url:
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
r = await session.post(
|
||||
r = await client.post(
|
||||
pay_link.webhook_url,
|
||||
json={
|
||||
"payment_hash": payment.payment_hash,
|
||||
@ -23,8 +23,8 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||
"amount": payment.amount,
|
||||
"lnurlp": pay_link.id,
|
||||
},
|
||||
timeout=60,
|
||||
timeout=40,
|
||||
)
|
||||
mark_webhook_sent(payment.payment_hash, r.status)
|
||||
except aiohttp.client_exceptions.ClientError:
|
||||
mark_webhook_sent(payment.payment_hash, r.status_code)
|
||||
except httpx.RequestError:
|
||||
mark_webhook_sent(payment.payment_hash, -1)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import json
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import httpx
|
||||
from os import getenv
|
||||
from http import HTTPStatus
|
||||
from typing import Optional, Dict, AsyncGenerator
|
||||
@ -93,12 +93,12 @@ class LNPayWallet(Wallet):
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
|
||||
lntx_id = data["data"]["wtx"]["lnTx"]["id"]
|
||||
async with aiohttp.ClientSession() as session:
|
||||
resp = await session.get(
|
||||
async with httpx.AsyncClient() as client:
|
||||
r = await client.get(
|
||||
f"{self.endpoint}/user/lntx/{lntx_id}?fields=settled",
|
||||
headers=self.auth_api,
|
||||
)
|
||||
data = await resp.json()
|
||||
data = r.json()
|
||||
if data["settled"]:
|
||||
self.queue.put_nowait(lntx_id)
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import random
|
||||
import requests
|
||||
import json
|
||||
from aiohttp_sse_client import client as sse_client
|
||||
import httpx
|
||||
from os import getenv
|
||||
from typing import Optional, AsyncGenerator
|
||||
|
||||
@ -30,9 +29,7 @@ class SparkWallet(Wallet):
|
||||
elif kwargs:
|
||||
params = kwargs
|
||||
|
||||
r = requests.post(
|
||||
self.url + "/rpc", headers={"X-Access": self.token}, json={"method": key, "params": params}
|
||||
)
|
||||
r = httpx.post(self.url + "/rpc", headers={"X-Access": self.token}, json={"method": key, "params": params})
|
||||
try:
|
||||
data = r.json()
|
||||
except:
|
||||
@ -98,12 +95,11 @@ class SparkWallet(Wallet):
|
||||
|
||||
async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
|
||||
url = self.url + "/stream?access-key=" + self.token
|
||||
conn = sse_client.EventSource(url)
|
||||
async with conn as es:
|
||||
async for event in es:
|
||||
try:
|
||||
if event.type == "inv-paid":
|
||||
data = json.loads(event.data)
|
||||
yield data["label"]
|
||||
except ConnectionError:
|
||||
pass
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
async with client.stream("GET", url) as r:
|
||||
async for line in r.aiter_lines():
|
||||
if line.startswith("data:"):
|
||||
data = json.loads(line[5:])
|
||||
if "pay_index" in data and data.get("status") == "paid":
|
||||
yield data["label"]
|
||||
|
Loading…
Reference in New Issue
Block a user