mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-14 03:16:24 +00:00
Prepare for other events
This commit is contained in:
parent
3e460bb255
commit
97bb2dc777
16
api/nostr.py
16
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
|
||||
|
||||
@ -19,9 +18,8 @@ class Nostr:
|
||||
await client.add_relays(["ws://localhost:888"])
|
||||
await client.connect()
|
||||
|
||||
event = EventBuilder(38383, "", generate_tags(order)).to_event(keys)
|
||||
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],
|
||||
]
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user