Use reference instead of transaction ID

This commit is contained in:
Mark Veidemanis 2021-12-29 14:41:05 +00:00
parent bf4381caa6
commit b160ac10e3
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 31 additions and 25 deletions

View File

@ -76,31 +76,29 @@ class Agora(object):
dash_tmp = []
current_trades = []
for contact_id, contact in dash.items():
current_trades.append(contact_id)
reference = self.tx.tx_to_ref(contact_id)
if not reference:
reference = "not_set"
current_trades.append(reference)
buyer = contact["data"]["buyer"]["username"]
amount = contact["data"]["amount"]
amount_xmr = contact["data"]["amount_xmr"]
currency = contact["data"]["currency"]
if not contact["data"]["is_selling"]:
continue
reference = self.tx.tx_to_ref(contact_id)
if not reference:
reference = "not_set"
if contact_id not in self.last_dash:
if reference not in self.last_dash:
self.tx.new_trade(contact_id, buyer, currency, amount, amount_xmr)
if send_irc:
self.irc.client.msg(
self.irc.client.channel, f"AUTO {contact_id}: {buyer} {amount}{currency} {amount_xmr}XMR {reference}"
)
self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {buyer} {amount}{currency} {amount_xmr}XMR")
dash_tmp.append(f"{contact_id}: {buyer} {amount}{currency} {amount_xmr}XMR {reference}")
self.last_dash.add(contact_id)
dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR")
self.last_dash.add(reference)
# Purge old trades from cache
for trade in list(self.last_dash): # We're removing from the list on the fly
if trade not in current_trades:
self.last_dash.remove(trade)
for ref in list(self.last_dash): # We're removing from the list on the fly
if ref not in current_trades:
self.last_dash.remove(ref)
return dash_tmp
def dashboard_release_urls(self):
@ -125,8 +123,10 @@ class Agora(object):
release_url = contact["actions"]["release_url"]
if not contact["data"]["is_selling"]:
continue
dash_tmp.append(f"{contact_id}: {buyer} {amount}{currency} {amount_xmr}XMR {release_url}")
reference = self.tx.tx_to_ref(contact_id)
if not reference:
reference = "not_set"
dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR {release_url}")
return dash_tmp
@ -140,18 +140,21 @@ class Agora(object):
"""
messages = self.agora.contact_messages(contact_id)
messages_tmp = []
reference = self.tx.tx_to_ref(contact_id)
if not reference:
reference = "not_set"
for message in messages["response"]["data"]["message_list"]:
messages_tmp.append(f"({message['sender']['username']}): {message['msg']}")
if send_irc:
if contact_id in self.last_messages:
if not len(self.last_messages[contact_id]) == len(messages_tmp):
difference = set(messages_tmp) ^ self.last_messages[contact_id]
if reference in self.last_messages:
if not len(self.last_messages[reference]) == len(messages_tmp):
difference = set(messages_tmp) ^ self.last_messages[reference]
for x in difference:
self.irc.client.msg(self.irc.client.channel, f"AUTO {contact_id}: {x}")
self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {x}")
else:
self.last_messages[contact_id] = messages_tmp
self.last_messages[reference] = messages_tmp
for x in messages_tmp:
self.irc.client.msg(self.irc.client.channel, f"NEW {contact_id}: {x}")
self.irc.client.msg(self.irc.client.channel, f"NEW {reference}: {x}")
return messages_tmp
def get_all_messages(self, send_irc=True):
@ -174,13 +177,16 @@ class Agora(object):
"""
messages_tmp = {}
for contact_id in dash:
reference = self.tx.tx_to_ref(contact_id)
if not reference:
reference = "not_set"
messages = self.get_messages(contact_id, send_irc=send_irc)
messages_tmp[contact_id] = messages
messages_tmp[reference] = messages
# Purge old trades from cache
for trade in list(self.last_messages): # We're removing from the list on the fly
if trade not in messages_tmp:
del self.last_messages[trade]
for ref in list(self.last_messages): # We're removing from the list on the fly
if ref not in messages_tmp:
del self.last_messages[ref]
return messages_tmp