mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-13 19:06:26 +00:00
Merge pull request #1476 from RoboSats/add-extra-tags-to-nostr
Add extra tags to nostr
This commit is contained in:
commit
f9b5a840ea
21
api/nostr.py
21
api/nostr.py
@ -29,10 +29,13 @@ class Nostr:
|
|||||||
await client.connect()
|
await client.connect()
|
||||||
|
|
||||||
robot_name = await self.get_robot_name(order)
|
robot_name = await self.get_robot_name(order)
|
||||||
|
robot_hash_id = await self.get_robot_hash_id(order)
|
||||||
currency = await self.get_robot_currency(order)
|
currency = await self.get_robot_currency(order)
|
||||||
|
|
||||||
event = EventBuilder(
|
event = EventBuilder(
|
||||||
Kind(38383), "", self.generate_tags(order, robot_name, currency)
|
Kind(38383),
|
||||||
|
"",
|
||||||
|
self.generate_tags(order, robot_name, robot_hash_id, currency),
|
||||||
).to_event(keys)
|
).to_event(keys)
|
||||||
await client.send_event(event)
|
await client.send_event(event)
|
||||||
print(f"Nostr event sent: {event.as_json()}")
|
print(f"Nostr event sent: {event.as_json()}")
|
||||||
@ -41,18 +44,22 @@ class Nostr:
|
|||||||
def get_robot_name(self, order):
|
def get_robot_name(self, order):
|
||||||
return order.maker.username
|
return order.maker.username
|
||||||
|
|
||||||
|
@sync_to_async
|
||||||
|
def get_robot_hash_id(self, order):
|
||||||
|
return order.maker.robot.hash_id
|
||||||
|
|
||||||
@sync_to_async
|
@sync_to_async
|
||||||
def get_robot_currency(self, order):
|
def get_robot_currency(self, order):
|
||||||
return str(order.currency)
|
return str(order.currency)
|
||||||
|
|
||||||
def generate_tags(self, order, robot_name, currency):
|
def generate_tags(self, order, robot_name, robot_hash_id, currency):
|
||||||
hashed_id = hashlib.md5(
|
hashed_id = hashlib.md5(
|
||||||
f"{config("COORDINATOR_ALIAS", cast=str)}{order.id}".encode("utf-8")
|
f"{config("COORDINATOR_ALIAS", cast=str)}{order.id}".encode("utf-8")
|
||||||
).hexdigest()
|
).hexdigest()
|
||||||
|
|
||||||
tags = [
|
tags = [
|
||||||
Tag.parse(["d", str(uuid.UUID(hashed_id))]),
|
Tag.parse(["d", str(uuid.UUID(hashed_id))]),
|
||||||
Tag.parse(["name", robot_name]),
|
Tag.parse(["name", robot_name, robot_hash_id]),
|
||||||
Tag.parse(["k", "sell" if order.type == Order.Types.SELL else "buy"]),
|
Tag.parse(["k", "sell" if order.type == Order.Types.SELL else "buy"]),
|
||||||
Tag.parse(["f", currency]),
|
Tag.parse(["f", currency]),
|
||||||
Tag.parse(["s", self.get_status_tag(order)]),
|
Tag.parse(["s", self.get_status_tag(order)]),
|
||||||
@ -73,7 +80,13 @@ class Nostr:
|
|||||||
f"http://{config("HOST_NAME")}/order/{config("COORDINATOR_ALIAS", cast=str).lower()}/{order.id}",
|
f"http://{config("HOST_NAME")}/order/{config("COORDINATOR_ALIAS", cast=str).lower()}/{order.id}",
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
Tag.parse(["expiration", str(int(order.expires_at.timestamp()))]),
|
Tag.parse(
|
||||||
|
[
|
||||||
|
"expiration",
|
||||||
|
str(int(order.expires_at.timestamp())),
|
||||||
|
str(order.escrow_duration),
|
||||||
|
]
|
||||||
|
),
|
||||||
Tag.parse(["y", "robosats", config("COORDINATOR_ALIAS", cast=str).lower()]),
|
Tag.parse(["y", "robosats", config("COORDINATOR_ALIAS", cast=str).lower()]),
|
||||||
Tag.parse(["n", str(config("NETWORK"))]),
|
Tag.parse(["n", str(config("NETWORK"))]),
|
||||||
Tag.parse(["layer"] + self.get_layer_tag(order)),
|
Tag.parse(["layer"] + self.get_layer_tag(order)),
|
||||||
|
Loading…
Reference in New Issue
Block a user