From d36bf2a048527a961768fb2b81449d40a6cb168d Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 4 Apr 2022 17:41:51 +0100 Subject: [PATCH] Notify of irreconcilable trades --- handler/transactions.py | 9 +++++++++ handler/ux/notify.py | 3 +++ 2 files changed, 12 insertions(+) diff --git a/handler/transactions.py b/handler/transactions.py index 23fc380..f1b9d12 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -118,6 +118,7 @@ class Transactions(util.Base): if len(stored_trade_reference) > 1: self.log.error(f"Multiple references valid for TXID {txid}: {reference}") self.irc.sendmsg(f"Multiple references valid for TXID {txid}: {reference}") + self.ux.notify.notify_tx_lookup_failed(currency, amount, reference, "MULTIPLE_REFS_MATCH") return stored_trade = False @@ -136,6 +137,7 @@ class Transactions(util.Base): if not stored_trade: self.log.info(f"Failed to get reference by amount and currency: {txid} {currency} {amount}") self.irc.sendmsg(f"Failed to get reference by amount and currency: {txid} {currency} {amount}") + self.ux.notify.notify_tx_lookup_failed(currency, amount, reference, "ALT_LOOKUP_FAILED") return if currency == "USD": amount_usd = amount @@ -147,6 +149,10 @@ class Transactions(util.Base): self.log.info("Not checking against amount and currency as amount exceeds MAX") self.irc.sendmsg(f"Not checking against amount and currency as amount exceeds MAX") # Close here if the amount exceeds the allowable limit for no reference + if len(stored_trade_reference) == 1: # better safe than sorry + self.ux.notify.notify_tx_lookup_failed(currency, amount, reference, "EXCEEDS_MAX", stored_trade_reference[0]) + else: + self.ux.notify.notify_tx_lookup_failed(currency, amount, reference, "EXCEEDS_MAX") return # Note that we have looked it up without reference so we don't use +- below # This might be redundant given the amount checks in find_trade, but better safe than sorry! @@ -156,6 +162,7 @@ class Transactions(util.Base): if not stored_trade: self.log.info(f"No reference in DB for {reference}") self.irc.sendmsg(f"No reference in DB for {reference}") + self.ux.notify.notify_tx_lookup_failed(currency, amount, reference, "NOREF", stored_trade["id"]) return amount = float(amount) @@ -165,6 +172,7 @@ class Transactions(util.Base): if not stored_trade["currency"] == currency: self.log.info(f"Currency mismatch, Agora: {stored_trade['currency']} / Sink: {currency}") self.irc.sendmsg(f"Currency mismatch, Agora: {stored_trade['currency']} / Sink: {currency}") + self.ux.notify.notify_tx_lookup_failed(currency, amount, reference, "CURRENCY_MISMATCH", stored_trade["id"]) return # Make sure the expected amount was sent @@ -178,6 +186,7 @@ class Transactions(util.Base): if not min_amount < amount < max_amount: self.log.info("Amount mismatch - not in margins: {stored_trade['amount']} (min: {min_amount} / max: {max_amount}") self.irc.sendmsg(f"Amount mismatch - not in margins: {stored_trade['amount']} (min: {min_amount} / max: {max_amount}") + self.ux.notify.notify_tx_lookup_failed(currency, amount, reference, "AMOUNT_MARGIN_MISMATCH", stored_trade["id"]) return r.hmset(f"tx.{txid}", to_store) diff --git a/handler/ux/notify.py b/handler/ux/notify.py index 255e5c6..de5b894 100644 --- a/handler/ux/notify.py +++ b/handler/ux/notify.py @@ -38,3 +38,6 @@ class Notify(util.Base): def notify_need_topup(self, amount_usd_xmr, amount_usd_btc): self.sendmsg(f"XMR: {amount_usd_xmr} | BTC: {amount_usd_btc}", title="Topup needed", tags="admin", priority="5") + + def notify_tx_lookup_failed(self, currency, amount, reference, code, trade_id=None): + self.sendmsg(f"Unknown TX [{code}]: {amount}{currency} ({reference}) for {trade_id}")