From f0b31ac17d872dd567eacb1423b4fcb226d91ba2 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 28 Dec 2021 15:29:15 +0000 Subject: [PATCH] Implement more transaction handling --- handler/transactions.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/handler/transactions.py b/handler/transactions.py index 128a4be..951b4d0 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -3,6 +3,8 @@ from twisted.logger import Logger # Other library imports from json import dumps +from random import choices +from string import ascii_uppercase # Project imports from db import r @@ -86,6 +88,38 @@ 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}") + 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": + 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']}") + + 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: + r.set(f"trade.{trade_id}.reference", reference) + to_store = { + "id": trade_id, + "buyer": buyer, + "currency": currency, + "amount": amount, + "amount_xmr": amount_xmr, + "reference": reference, + } + self.log.info(f"Storing trade information: {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}") def find_tx(self, reference, amount): """