fix: publish events via websocket

This commit is contained in:
Vlad Stan 2023-03-14 16:00:01 +02:00
parent f978d9e97f
commit 9931a08566
3 changed files with 6 additions and 38 deletions

View file

@ -1,28 +1,18 @@
from threading import Thread
from typing import Callable
import httpx
from loguru import logger
from websocket import WebSocketApp
from lnbits.app import settings
from lnbits.helpers import url_for
from .. import send_req_queue
from .event import NostrEvent
async def publish_nostr_event(e: NostrEvent):
url = url_for("/nostrclient/api/v1/publish", external=True)
data = dict(e)
print("### published", dict(data))
async with httpx.AsyncClient() as client:
try:
await client.post(
url,
json=data,
)
except Exception as ex:
logger.warning(ex)
print('### publish_nostr_event', e.dict())
await send_req_queue.put(["EVENT", e.dict()])
async def connect_to_nostrclient_ws(
@ -44,23 +34,3 @@ async def connect_to_nostrclient_ws(
wst.start()
return ws
# async def handle_event(event, pubkeys):
# tags = [t[1] for t in event["tags"] if t[0] == "p"]
# to_merchant = None
# if tags and len(tags) > 0:
# to_merchant = tags[0]
# if event["pubkey"] in pubkeys or to_merchant in pubkeys:
# logger.debug(f"Event sent to {to_merchant}")
# pubkey = to_merchant if to_merchant in pubkeys else event["pubkey"]
# # Send event to market extension
# await send_event_to_market(event=event, pubkey=pubkey)
# async def send_event_to_market(event: dict, pubkey: str):
# # Sends event to market extension, for decrypt and handling
# market_url = url_for(f"/market/api/v1/nip04/{pubkey}", external=True)
# async with httpx.AsyncClient() as client:
# await client.post(url=market_url, json=event)

View file

@ -345,8 +345,9 @@ async function customerStall(path) {
let json = JSON.parse(text)
if (json.id != this.activeOrder) return
if (json.payment_options) {
let payment_request = json.payment_options.find(o => o.type == 'ln')
.link
let payment_request = json.payment_options.find(
o => o.type == 'ln'
).link
if (!payment_request) return
this.loading = false
this.qrCodeDialog.data.payment_request = payment_request

View file

@ -40,8 +40,6 @@ async def on_invoice_paid(payment: Payment) -> None:
async def subscribe_to_nostr_client(recieve_event_queue: Queue, send_req_queue: Queue):
print("### subscribe_nostrclient_ws")
def on_open(_):
logger.info("Connected to 'nostrclient' websocket")
@ -68,7 +66,6 @@ async def subscribe_to_nostr_client(recieve_event_queue: Queue, send_req_queue:
async def wait_for_nostr_events(recieve_event_queue: Queue, send_req_queue: Queue):
print("### wait_for_nostr_events")
public_keys = await get_public_keys_for_merchants()
for p in public_keys:
last_order_time = await get_last_order_time(p)