Address syntax issues and convert release_trade to async

This commit is contained in:
Mark Veidemanis 2022-06-04 13:42:25 +01:00
parent fe1ff870e2
commit 79caec1680
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 14 additions and 9 deletions

View File

@ -61,7 +61,7 @@ class AgoraDesk:
try: try:
text = yield response.content() text = yield response.content()
except: # noqa except: # noqa
self.log.error(f"Error with API call") self.log.error("Error with API call")
return return
try: try:
result["response"] = json.loads(text) result["response"] = json.loads(text)

View File

@ -1,3 +1,6 @@
# Twisted/Klein imports
from twisted.internet.defer import inlineCallbacks
# Other library imports # Other library imports
from json import dumps from json import dumps
from random import choices from random import choices
@ -95,7 +98,7 @@ class Transactions(util.Base):
# Amount is reliable here as it is checked by find_trade, so no need for stored_trade["amount"] # Amount is reliable here as it is checked by find_trade, so no need for stored_trade["amount"]
if float(amount_usd) > float(settings.Agora.AcceptableAltLookupUSD): if float(amount_usd) > float(settings.Agora.AcceptableAltLookupUSD):
self.log.info("Not checking against amount and currency as amount exceeds MAX") self.log.info("Not checking against amount and currency as amount exceeds MAX")
self.irc.sendmsg(f"Not checking against amount and currency as amount exceeds MAX") self.irc.sendmsg("Not checking against amount and currency as amount exceeds MAX")
# Close here if the amount exceeds the allowable limit for no reference # Close here if the amount exceeds the allowable limit for no reference
self.ux.notify.notify_tx_lookup_failed(currency, amount, reference, "EXCEEDS_MAX") self.ux.notify.notify_tx_lookup_failed(currency, amount, reference, "EXCEEDS_MAX")
return False return False
@ -166,6 +169,7 @@ class Transactions(util.Base):
return False return False
return True return True
@inlineCallbacks
def transaction(self, data): def transaction(self, data):
""" """
Store details of transaction and post notifications to IRC. Store details of transaction and post notifications to IRC.
@ -252,8 +256,9 @@ class Transactions(util.Base):
# self.log.error(f"Cannot release trade {reference}.") # self.log.error(f"Cannot release trade {reference}.")
# return # return
self.release_funds(stored_trade["id"], stored_trade["reference"]) yield self.release_funds(stored_trade["id"], stored_trade["reference"])
@inlineCallbacks
def release_funds(self, trade_id, reference): def release_funds(self, trade_id, reference):
stored_trade = db.get_ref(reference) stored_trade = db.get_ref(reference)
platform = stored_trade["subclass"] platform = stored_trade["subclass"]
@ -267,7 +272,7 @@ class Transactions(util.Base):
release = self.lbtc.release_funds release = self.lbtc.release_funds
post_message = self.lbtc.api.contact_message_post post_message = self.lbtc.api.contact_message_post
rtrn = release(trade_id) rtrn = yield release(trade_id)
if rtrn["message"] == "OK": if rtrn["message"] == "OK":
post_message(trade_id, "Thanks! Releasing now :)") post_message(trade_id, "Thanks! Releasing now :)")
else: else:

View File

@ -128,7 +128,7 @@ class TrueLayer(util.Base):
if self.current_authcode_bank: if self.current_authcode_bank:
self.tokens[self.current_authcode_bank] = access_token self.tokens[self.current_authcode_bank] = access_token
else: else:
self.log.error(f"Received an authcode we didn't ask for") self.log.error("Received an authcode we didn't ask for")
return return
self.log.info(f"Retrieved access/refresh tokens for {self.current_authcode_bank}") self.log.info(f"Retrieved access/refresh tokens for {self.current_authcode_bank}")

View File

@ -510,10 +510,10 @@ class IRCCommands(object):
msg("Trade or TX invalid") msg("Trade or TX invalid")
return return
elif is_released is True: elif is_released is True:
msg(f"Trade released") msg("Trade released")
return return
elif is_released is False: elif is_released is False:
msg(f"Could not release trade") msg("Could not release trade")
return return
class anuke(object): class anuke(object):
@ -878,7 +878,7 @@ class IRCCommands(object):
account_id = spl[2] account_id = spl[2]
account_name = tx.sinks.truelayer.map_account(bank, account_id) account_name = tx.sinks.truelayer.map_account(bank, account_id)
if not account_name: if not account_name:
msg(f"Failed to map the account") msg("Failed to map the account")
return return
msg(f"Mapped account ID {account_id} at bank {bank} to {account_name}") msg(f"Mapped account ID {account_id} at bank {bank} to {account_name}")
@ -890,7 +890,7 @@ class IRCCommands(object):
@staticmethod @staticmethod
def got_map_account(account_name, account_id, msg): def got_map_account(account_name, account_id, msg):
if not account_name: if not account_name:
msg(f"Failed to map the account") msg("Failed to map the account")
return return
msg(f"Mapped account ID {account_id} to {account_name}") msg(f"Mapped account ID {account_id} to {account_name}")