Implement more transaction handling

This commit is contained in:
Mark Veidemanis 2021-12-28 15:29:15 +00:00
parent 906048a797
commit f0b31ac17d
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 34 additions and 0 deletions

View File

@ -3,6 +3,8 @@ from twisted.logger import Logger
# Other library imports # Other library imports
from json import dumps from json import dumps
from random import choices
from string import ascii_uppercase
# Project imports # Project imports
from db import r from db import r
@ -86,6 +88,38 @@ class Transactions(object):
self.irc.client.msg( self.irc.client.msg(
self.irc.client.channel, f"AUTO Incoming transaction: {amount}{currency} ({reference}) - {state} - {description}" 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): def find_tx(self, reference, amount):
""" """