From 4667272f76940bae6e653b017317eb02d5cf0555 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 24 May 2022 08:44:18 +0100 Subject: [PATCH] Make release funds flow async --- handler/sources/agora.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/handler/sources/agora.py b/handler/sources/agora.py index abbef85..45652eb 100644 --- a/handler/sources/agora.py +++ b/handler/sources/agora.py @@ -1,9 +1,11 @@ +# Twisted/Klein imports +from twisted.internet.defer import inlineCallbacks + # Other library imports from pyotp import TOTP # Project imports from settings import settings -import util import sources.local @@ -29,7 +31,7 @@ class Agora(sources.local.Local): # Assets that cheat has been run on self.cheat_run_on = [] - @util.handle_exceptions + @inlineCallbacks def release_funds(self, contact_id): """ Release funds for a contact_id. @@ -38,28 +40,30 @@ class Agora(sources.local.Local): :return: response dict :rtype: dict """ + print("CALLING RELEASE FUNDS", contact_id) if self.sets.Dummy == "1": self.log.error(f"Running in dummy mode, not releasing funds for {contact_id}") return payload = {"tradeId": contact_id, "password": self.sets.Pass} - rtrn = self.api._api_call( + rtrn = yield self.api._api_call( api_method=f"contact_release/{contact_id}", http_method="POST", query_values=payload, ) # Check if we can withdraw funds - self.withdraw_funds() + yield self.withdraw_funds() return rtrn # TODO: write test before re-enabling adding total_trades - @util.handle_exceptions + @inlineCallbacks def withdraw_funds(self): """ Withdraw excess funds to our XMR wallets. """ - totals_all = self.money.get_total() + print("CALLING WITHDRAW FUNDS") + totals_all = yield self.money.get_total() if totals_all is False: return False @@ -117,10 +121,10 @@ class Agora(sources.local.Local): } send_cast["address"] = settings.XMR.Wallet1 - rtrn1 = self.api.wallet_send_xmr(**send_cast) + rtrn1 = yield self.api.wallet_send_xmr(**send_cast) send_cast["address"] = settings.XMR.Wallet2 - rtrn2 = self.api.wallet_send_xmr(**send_cast) + rtrn2 = yield self.api.wallet_send_xmr(**send_cast) self.irc.sendmsg(f"Withdrawal: {rtrn1['success']} | {rtrn2['success']}") self.ux.notify.notify_withdrawal(half_rounded)