Move function from IRC into transactions

This commit is contained in:
Mark Veidemanis 2021-12-27 21:04:57 +00:00
parent 5d21953199
commit 83090ff6a5
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 15 additions and 12 deletions

View File

@ -10,16 +10,6 @@ from json import dumps
from settings import settings
def convert(data):
if isinstance(data, bytes):
return data.decode("ascii")
if isinstance(data, dict):
return dict(map(convert, data.items()))
if isinstance(data, tuple):
return map(convert, data)
return data
class IRCBot(irc.IRCClient):
def __init__(self, log):
self.log = log
@ -128,7 +118,7 @@ class IRCBot(irc.IRCClient):
elif not rtrn:
return dumps({"success": False, "msg": "Reference not found"})
else:
return dumps(convert(rtrn))
return dumps(rtrn)
def stopcall(self, call):
call.stop()

View File

@ -8,6 +8,19 @@ from json import dumps
from db import r
def convert(data):
"""
Recursively convert a dictionary.
"""
if isinstance(data, bytes):
return data.decode("ascii")
if isinstance(data, dict):
return dict(map(convert, data.items()))
if isinstance(data, tuple):
return map(convert, data)
return data
class Transactions(object):
"""
Handler class for incoming Revolut transactions.
@ -73,7 +86,7 @@ class Transactions(object):
tx_obj = r.hgetall(tx_iter)
if tx_obj[b"reference"] == str.encode(reference):
if tx_obj[b"amount"] == str.encode(amount):
return tx_obj
return convert(tx_obj)
else:
return "AMOUNT_INVALID"
return False