Make release funds flow async

master
Mark Veidemanis 2 years ago
parent f53df32eab
commit 4667272f76
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -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)

Loading…
Cancel
Save