From cd6e19a38a1af456372de0cdac375095ac4235a7 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 28 Dec 2021 17:47:07 +0000 Subject: [PATCH] Fix incoming transaction matching --- handler/transactions.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/handler/transactions.py b/handler/transactions.py index 951b4d0..1756488 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -88,14 +88,20 @@ class Transactions(object): self.irc.client.msg( self.irc.client.channel, f"AUTO Incoming transaction: {amount}{currency} ({reference}) - {state} - {description}" ) - stored_trade = r.hmget(f"trade.{reference}") + stored_trade = r.hgetall(f"trade.{reference}") + if not stored_trade: + self.log.info(f"No reference in DB for {reference}") + return + stored_trade = convert(stored_trade) + amount = float(amount) + stored_trade["amount"] = float(stored_trade["amount"]) if not stored_trade["currency"] == currency: self.irc.client.msg(self.irc.client.channel, f"Currency mismatch, Agora: {stored_trade['currency']} / Revolut: {currency}") return if not stored_trade["amount"] == amount: self.irc.client.msg(self.irc.client.channel, f"Amount mismatch, Agora: {stored_trade['amount']} / Revolut: {amount}") return - if not account_type == "Revolut": + if not account_type == "revolut": self.irc.client.msg(self.irc.client.channel, f"Account type is not Revolut: {account_type}") return self.irc.client.msg(self.irc.client.channel, f"All checks passed, would release funds for {stored_trade['id']}") @@ -103,9 +109,10 @@ class Transactions(object): def new_trade(self, trade_id, buyer, currency, amount, amount_xmr): reference = "".join(choices(ascii_uppercase, k=5)) reference = f"XMR-{reference}" - print("NEW TRADE") existing_ref = r.get(f"trade.{trade_id}.reference") - if not existing_ref: + if existing_ref: + self.irc.client.msg(self.irc.client.channel, f"Existing reference for {trade_id}: {existing_ref.decode('utf-8')}") + else: r.set(f"trade.{trade_id}.reference", reference) to_store = { "id": trade_id, @@ -115,11 +122,10 @@ class Transactions(object): "amount_xmr": amount_xmr, "reference": reference, } - self.log.info(f"Storing trade information: {to_store}") + self.log.info(f"Storing trade information: {str(to_store)}") r.hmset(f"trade.{reference}", to_store) - self.irc.client.msg(self.irc.client.channel, f"Would send reference to {trade_id}: {reference}") - else: - self.irc.client.msg(self.irc.client.channel, f"Using existing reference for stored trade {trade_id}: {existing_ref}") + self.irc.client.msg(self.irc.client.channel, f"Generated reference for {trade_id}: {reference}") + self.agora.agora.contact_message_post(trade_id, f"Hi! When sending the payment please user reference code: {reference}") def find_tx(self, reference, amount): """