From b2b7b3b923fd6fdd7f2ba001dee87607b6fd55fc Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 10 May 2022 21:41:16 +0100 Subject: [PATCH] Fix LBTC POST message signing --- handler/lib/agoradesk_py.py | 6 +++++- handler/lib/localbitcoins_py.py | 3 +-- handler/sources/local.py | 30 ++++++++++++++++++------------ handler/ux/commands.py | 20 +++++++++++++------- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/handler/lib/agoradesk_py.py b/handler/lib/agoradesk_py.py index 7170a7f..a78e5b0 100644 --- a/handler/lib/agoradesk_py.py +++ b/handler/lib/agoradesk_py.py @@ -58,7 +58,11 @@ class AgoraDesk: @inlineCallbacks def callback_api_call(self, response, result): logger.debug(response) - text = yield response.content() + try: + text = yield response.content() + except: # noqa + self.log.error(f"Error with API call") + return try: result["response"] = json.loads(text) except json.decoder.JSONDecodeError: diff --git a/handler/lib/localbitcoins_py.py b/handler/lib/localbitcoins_py.py index 649fa4f..feb879a 100644 --- a/handler/lib/localbitcoins_py.py +++ b/handler/lib/localbitcoins_py.py @@ -169,7 +169,7 @@ class LocalBitcoins: response = treq.post( api_call_url, headers=headers, - data=json.dumps(query_values), + data=query_values, ) else: # response = httpx.post( @@ -581,7 +581,6 @@ class LocalBitcoins: params["reference_type"] = reference_type if display_reference is not None: params["display_reference"] = display_reference - return self._api_call( api_method=f"api/ad/{ad_id}/", http_method="POST", diff --git a/handler/sources/local.py b/handler/sources/local.py index 0189b97..3393610 100644 --- a/handler/sources/local.py +++ b/handler/sources/local.py @@ -551,7 +551,7 @@ class Local(util.Base): } if self.platform == "agora": form["asset"] = asset - form["payment_method_details"] = (settings.Platform.PaymentMethodDetails,) + form["payment_method_details"] = settings.Platform.PaymentMethodDetails form["online_provider"] = provider elif self.platform == "lbtc": form["online_provider"] = self.map_provider(provider, reverse=True) @@ -567,14 +567,13 @@ class Local(util.Base): form["max_amount"] = round(max_amount, 2) if self.platform == "lbtc": form["bank_name"] = bank_name - if edit: - ad = self.api.ad(ad_id=ad_id, **form) + ad = yield self.api.ad(ad_id=ad_id, **form) else: - ad = self.api.ad_create(**form) + ad = yield self.api.ad_create(**form) return ad - # TODO: make async + @inlineCallbacks def dist_countries(self, filter_asset=None): """ Distribute our advert into all countries and providers listed in the config. @@ -583,18 +582,22 @@ class Local(util.Base): :rtype: bool or dict """ dist_list = list(self.markets.create_distribution_list(self.platform, filter_asset)) - our_ads = self.enum_ads() + our_ads = yield self.enum_ads() ( supported_currencies, account_info, ) = self.markets.get_valid_account_details(self.platform) # Let's get rid of the ad IDs and make it a tuple like dist_list our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads] + if not our_ads: + self.log.error("Could not get our ads.") + return False + to_return = [] for asset, countrycode, currency, provider in dist_list: if (asset, countrycode, currency, provider) not in our_ads: if currency in supported_currencies: # Create the actual ad and pass in all the stuff - rtrn = self.create_ad( + rtrn = yield self.create_ad( asset, countrycode, currency, @@ -604,9 +607,10 @@ class Local(util.Base): # Bail on first error, let's not continue if rtrn is False: return False - yield rtrn + to_return.append(rtrn) + return to_return - # TODO: make async + @inlineCallbacks def redist_countries(self): """ Redistribute our advert details into all our listed adverts. @@ -616,7 +620,7 @@ class Local(util.Base): :return: False or dict with response :rtype: bool or dict """ - our_ads = self.enum_ads() + our_ads = yield self.enum_ads() ( supported_currencies, account_info, @@ -624,9 +628,10 @@ class Local(util.Base): if not our_ads: self.log.error("Could not get our ads.") return False + to_return = [] for asset, ad_id, countrycode, currency, provider in our_ads: if currency in supported_currencies: - rtrn = self.create_ad( + rtrn = yield self.create_ad( asset, countrycode, currency, @@ -638,7 +643,8 @@ class Local(util.Base): # Bail on first error, let's not continue if rtrn is False: return False - yield (rtrn, ad_id) + to_return.append((rtrn, ad_id)) + return to_return @inlineCallbacks def strip_duplicate_ads(self): diff --git a/handler/ux/commands.py b/handler/ux/commands.py index fc8af5f..e621dd1 100644 --- a/handler/ux/commands.py +++ b/handler/ux/commands.py @@ -3,6 +3,7 @@ from json import dumps, loads # Project imports from settings import settings +import db class GenericCommands(object): @@ -117,12 +118,17 @@ class GenericCommands(object): class redist(object): @staticmethod - def run(cmd, spl, length, authed, msg, agora, tx, ux, caller): - for x in caller.redist_countries(): + def got_redist(redist_output, msg): + for x in redist_output: if x[0]["success"]: msg(f"{x[0]['response']['data']['message']}: {x[1]}") else: - msg(dumps(x[0]["response"])) + msg(dumps(x)) + + @staticmethod + def run(cmd, spl, length, authed, msg, agora, tx, ux, caller): + c = caller.redist_countries() + c.addCallback(GenericCommands.redist.got_redist, msg) class stripdupes(object): @staticmethod @@ -432,7 +438,7 @@ class IRCCommands(object): @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): - msg(f"References: {', '.join(tx.get_refs())}") + msg(f"References: {', '.join(db.get_refs())}") class ref(object): name = "ref" @@ -442,7 +448,7 @@ class IRCCommands(object): @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): if length == 2: - ref_data = tx.get_ref(spl[1]) + ref_data = db.get_ref(spl[1]) if not ref_data: msg(f"No such reference: {spl[1]}") return @@ -456,11 +462,11 @@ class IRCCommands(object): @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): if length == 2: - ref_data = tx.get_ref(spl[1]) + ref_data = db.get_ref(spl[1]) if not ref_data: msg(f"No such reference: {spl[1]}") return - tx.del_ref(spl[1]) + db.del_ref(spl[1]) msg(f"Deleted reference: {spl[1]}") class arelease(object):