From bf4381caa6f88311c8b3810763befa8cda9fb6cd Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 29 Dec 2021 14:32:06 +0000 Subject: [PATCH] Implement looking up references --- handler/agora.py | 10 ++++++++-- handler/transactions.py | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index f284f3c..164a8d4 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -83,12 +83,18 @@ class Agora(object): 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: 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") - dash_tmp.append(f"{contact_id}: {buyer} {amount}{currency} {amount_xmr}XMR") + self.irc.client.msg( + 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}") self.last_dash.add(contact_id) # Purge old trades from cache diff --git a/handler/transactions.py b/handler/transactions.py index 8cd236c..bddca55 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -113,9 +113,9 @@ class Transactions(object): reference = "".join(choices(ascii_uppercase, k=5)) reference = f"XMR-{reference}" existing_ref = r.get(f"trade.{trade_id}.reference") - if existing_ref: - self.irc.client.msg(self.irc.client.channel, f"Existing reference for {trade_id}: {existing_ref.decode('utf-8')}") - else: + # if existing_ref: + # self.irc.client.msg(self.irc.client.channel, f"Existing reference for {trade_id}: {existing_ref.decode('utf-8')}") + if not existing_ref: r.set(f"trade.{trade_id}.reference", reference) to_store = { "id": trade_id, @@ -185,7 +185,16 @@ class Transactions(object): pass def tx_to_ref(self, tx): - pass + refs = self.get_refs() + for reference in refs: + ref_data = convert(r.hgetall(f"trade.{reference}")) + if not ref_data: + continue + if ref_data["id"] == tx: + return reference def ref_to_tx(self, reference): - pass + ref_data = convert(r.hgetall(f"trade.{reference}")) + if not ref_data: + return False + return ref_data["id"]