diff --git a/api/nostr.py b/api/nostr.py index 9e31d27a..6d14b24c 100644 --- a/api/nostr.py +++ b/api/nostr.py @@ -1,6 +1,5 @@ -import time import pygeohash -from nostr_sdk import Keys, Client, EventBuilder, NostrSigner, Filter +from nostr_sdk import Keys, Client, EventBuilder, NostrSigner from api.models import Order from decouple import config @@ -18,10 +17,9 @@ class Nostr: # Add relays and connect await client.add_relays(["ws://localhost:888"]) await client.connect() - - event = EventBuilder(38383, "", generate_tags(order)).to_event(keys) - output = await client.send_event(event) + event = EventBuilder(38383, "", self.generate_tags(order)).to_event(keys) + output = await client.send_event(event) print(f"Nostr event sent: {output}") def generate_tags(self, order): @@ -35,13 +33,15 @@ class Nostr: ["fa", order.amount], ["pm", order.payment_method.split(" ")], ["premium", order.premium_percentile], - ["source", f"{config("HOST_NAME")}/{config("COORDINATOR_ALIAS")}/order/{order.id}"], + [ + "source", + f"{config("HOST_NAME")}/{config("COORDINATOR_ALIAS")}/order/{order.id}", + ], ["expiration", order.expires_at.timestamp()], ["y", "robosats"], - ["coordinator", config("COORDINATOR_ALIAS", cast=str)] - ["z", "order"], + ["coordinator", config("COORDINATOR_ALIAS", cast=str)]["z", "order"], ["n", order.network], ["layer", "lightning"], ["g", pygeohash.encode(order.latitude, order.longitude)], - ["bond", order.bond] + ["bond", order.bond], ] diff --git a/api/tasks.py b/api/tasks.py index 10379eac..fa1d44b7 100644 --- a/api/tasks.py +++ b/api/tasks.py @@ -263,13 +263,13 @@ def send_order_nostr_event(order_id=None, message=None): nostr = Nostr() if message == "new": coroutine = nostr.send_new_order_event(order) - if coroutine: loop = asyncio.get_event_loop() loop.run_until_complete(coroutine) return + @shared_task(name="send_notification", ignore_result=True, time_limit=120) def send_notification(order_id=None, chat_message_id=None, message=None): if order_id: