Implement more transaction handling
This commit is contained in:
parent
906048a797
commit
f0b31ac17d
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue