Use reference instead of transaction ID

pull/1/head
Mark Veidemanis 3 years ago
parent bf4381caa6
commit b160ac10e3
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

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

Loading…
Cancel
Save