Make release funds flow async

This commit is contained in:
Mark Veidemanis 2022-05-24 08:44:18 +01:00
parent f53df32eab
commit 4667272f76
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 12 additions and 8 deletions

View File

@ -1,9 +1,11 @@
# Twisted/Klein imports
from twisted.internet.defer import inlineCallbacks
# Other library imports # Other library imports
from pyotp import TOTP from pyotp import TOTP
# Project imports # Project imports
from settings import settings from settings import settings
import util
import sources.local import sources.local
@ -29,7 +31,7 @@ class Agora(sources.local.Local):
# Assets that cheat has been run on # Assets that cheat has been run on
self.cheat_run_on = [] self.cheat_run_on = []
@util.handle_exceptions @inlineCallbacks
def release_funds(self, contact_id): def release_funds(self, contact_id):
""" """
Release funds for a contact_id. Release funds for a contact_id.
@ -38,28 +40,30 @@ class Agora(sources.local.Local):
:return: response dict :return: response dict
:rtype: dict :rtype: dict
""" """
print("CALLING RELEASE FUNDS", contact_id)
if self.sets.Dummy == "1": if self.sets.Dummy == "1":
self.log.error(f"Running in dummy mode, not releasing funds for {contact_id}") self.log.error(f"Running in dummy mode, not releasing funds for {contact_id}")
return return
payload = {"tradeId": contact_id, "password": self.sets.Pass} 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}", api_method=f"contact_release/{contact_id}",
http_method="POST", http_method="POST",
query_values=payload, query_values=payload,
) )
# Check if we can withdraw funds # Check if we can withdraw funds
self.withdraw_funds() yield self.withdraw_funds()
return rtrn return rtrn
# TODO: write test before re-enabling adding total_trades # TODO: write test before re-enabling adding total_trades
@util.handle_exceptions @inlineCallbacks
def withdraw_funds(self): def withdraw_funds(self):
""" """
Withdraw excess funds to our XMR wallets. 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: if totals_all is False:
return False return False
@ -117,10 +121,10 @@ class Agora(sources.local.Local):
} }
send_cast["address"] = settings.XMR.Wallet1 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 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.irc.sendmsg(f"Withdrawal: {rtrn1['success']} | {rtrn2['success']}")
self.ux.notify.notify_withdrawal(half_rounded) self.ux.notify.notify_withdrawal(half_rounded)