fix: publish events via websocket
This commit is contained in:
parent
f978d9e97f
commit
9931a08566
3 changed files with 6 additions and 38 deletions
|
|
@ -1,28 +1,18 @@
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
import httpx
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from websocket import WebSocketApp
|
from websocket import WebSocketApp
|
||||||
|
|
||||||
from lnbits.app import settings
|
from lnbits.app import settings
|
||||||
from lnbits.helpers import url_for
|
|
||||||
|
|
||||||
|
from .. import send_req_queue
|
||||||
from .event import NostrEvent
|
from .event import NostrEvent
|
||||||
|
|
||||||
|
|
||||||
async def publish_nostr_event(e: NostrEvent):
|
async def publish_nostr_event(e: NostrEvent):
|
||||||
url = url_for("/nostrclient/api/v1/publish", external=True)
|
print('### publish_nostr_event', e.dict())
|
||||||
data = dict(e)
|
await send_req_queue.put(["EVENT", e.dict()])
|
||||||
print("### published", dict(data))
|
|
||||||
async with httpx.AsyncClient() as client:
|
|
||||||
try:
|
|
||||||
await client.post(
|
|
||||||
url,
|
|
||||||
json=data,
|
|
||||||
)
|
|
||||||
except Exception as ex:
|
|
||||||
logger.warning(ex)
|
|
||||||
|
|
||||||
|
|
||||||
async def connect_to_nostrclient_ws(
|
async def connect_to_nostrclient_ws(
|
||||||
|
|
@ -44,23 +34,3 @@ async def connect_to_nostrclient_ws(
|
||||||
wst.start()
|
wst.start()
|
||||||
|
|
||||||
return ws
|
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)
|
|
||||||
|
|
|
||||||
|
|
@ -345,8 +345,9 @@ async function customerStall(path) {
|
||||||
let json = JSON.parse(text)
|
let json = JSON.parse(text)
|
||||||
if (json.id != this.activeOrder) return
|
if (json.id != this.activeOrder) return
|
||||||
if (json.payment_options) {
|
if (json.payment_options) {
|
||||||
let payment_request = json.payment_options.find(o => o.type == 'ln')
|
let payment_request = json.payment_options.find(
|
||||||
.link
|
o => o.type == 'ln'
|
||||||
|
).link
|
||||||
if (!payment_request) return
|
if (!payment_request) return
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.qrCodeDialog.data.payment_request = payment_request
|
this.qrCodeDialog.data.payment_request = payment_request
|
||||||
|
|
|
||||||
3
tasks.py
3
tasks.py
|
|
@ -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):
|
async def subscribe_to_nostr_client(recieve_event_queue: Queue, send_req_queue: Queue):
|
||||||
print("### subscribe_nostrclient_ws")
|
|
||||||
|
|
||||||
def on_open(_):
|
def on_open(_):
|
||||||
logger.info("Connected to 'nostrclient' websocket")
|
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):
|
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()
|
public_keys = await get_public_keys_for_merchants()
|
||||||
for p in public_keys:
|
for p in public_keys:
|
||||||
last_order_time = await get_last_order_time(p)
|
last_order_time = await get_last_order_time(p)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue