mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-14 11:26: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
|
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 api.models import Order
|
||||||
from decouple import config
|
from decouple import config
|
||||||
|
|
||||||
@ -19,9 +18,8 @@ class Nostr:
|
|||||||
await client.add_relays(["ws://localhost:888"])
|
await client.add_relays(["ws://localhost:888"])
|
||||||
await client.connect()
|
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)
|
output = await client.send_event(event)
|
||||||
|
|
||||||
print(f"Nostr event sent: {output}")
|
print(f"Nostr event sent: {output}")
|
||||||
|
|
||||||
def generate_tags(self, order):
|
def generate_tags(self, order):
|
||||||
@ -35,13 +33,15 @@ class Nostr:
|
|||||||
["fa", order.amount],
|
["fa", order.amount],
|
||||||
["pm", order.payment_method.split(" ")],
|
["pm", order.payment_method.split(" ")],
|
||||||
["premium", order.premium_percentile],
|
["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()],
|
["expiration", order.expires_at.timestamp()],
|
||||||
["y", "robosats"],
|
["y", "robosats"],
|
||||||
["coordinator", config("COORDINATOR_ALIAS", cast=str)]
|
["coordinator", config("COORDINATOR_ALIAS", cast=str)]["z", "order"],
|
||||||
["z", "order"],
|
|
||||||
["n", order.network],
|
["n", order.network],
|
||||||
["layer", "lightning"],
|
["layer", "lightning"],
|
||||||
["g", pygeohash.encode(order.latitude, order.longitude)],
|
["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()
|
nostr = Nostr()
|
||||||
if message == "new":
|
if message == "new":
|
||||||
coroutine = nostr.send_new_order_event(order)
|
coroutine = nostr.send_new_order_event(order)
|
||||||
|
|
||||||
if coroutine:
|
if coroutine:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(coroutine)
|
loop.run_until_complete(coroutine)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@shared_task(name="send_notification", ignore_result=True, time_limit=120)
|
@shared_task(name="send_notification", ignore_result=True, time_limit=120)
|
||||||
def send_notification(order_id=None, chat_message_id=None, message=None):
|
def send_notification(order_id=None, chat_message_id=None, message=None):
|
||||||
if order_id:
|
if order_id:
|
||||||
|
Loading…
Reference in New Issue
Block a user