Fix LBTC POST message signing

master
Mark Veidemanis 2 years ago
parent 644444c02f
commit b2b7b3b923
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -58,7 +58,11 @@ class AgoraDesk:
@inlineCallbacks @inlineCallbacks
def callback_api_call(self, response, result): def callback_api_call(self, response, result):
logger.debug(response) logger.debug(response)
try:
text = yield response.content() text = yield response.content()
except: # noqa
self.log.error(f"Error with API call")
return
try: try:
result["response"] = json.loads(text) result["response"] = json.loads(text)
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:

@ -169,7 +169,7 @@ class LocalBitcoins:
response = treq.post( response = treq.post(
api_call_url, api_call_url,
headers=headers, headers=headers,
data=json.dumps(query_values), data=query_values,
) )
else: else:
# response = httpx.post( # response = httpx.post(
@ -581,7 +581,6 @@ class LocalBitcoins:
params["reference_type"] = reference_type params["reference_type"] = reference_type
if display_reference is not None: if display_reference is not None:
params["display_reference"] = display_reference params["display_reference"] = display_reference
return self._api_call( return self._api_call(
api_method=f"api/ad/{ad_id}/", api_method=f"api/ad/{ad_id}/",
http_method="POST", http_method="POST",

@ -551,7 +551,7 @@ class Local(util.Base):
} }
if self.platform == "agora": if self.platform == "agora":
form["asset"] = asset form["asset"] = asset
form["payment_method_details"] = (settings.Platform.PaymentMethodDetails,) form["payment_method_details"] = settings.Platform.PaymentMethodDetails
form["online_provider"] = provider form["online_provider"] = provider
elif self.platform == "lbtc": elif self.platform == "lbtc":
form["online_provider"] = self.map_provider(provider, reverse=True) form["online_provider"] = self.map_provider(provider, reverse=True)
@ -567,14 +567,13 @@ class Local(util.Base):
form["max_amount"] = round(max_amount, 2) form["max_amount"] = round(max_amount, 2)
if self.platform == "lbtc": if self.platform == "lbtc":
form["bank_name"] = bank_name form["bank_name"] = bank_name
if edit: if edit:
ad = self.api.ad(ad_id=ad_id, **form) ad = yield self.api.ad(ad_id=ad_id, **form)
else: else:
ad = self.api.ad_create(**form) ad = yield self.api.ad_create(**form)
return ad return ad
# TODO: make async @inlineCallbacks
def dist_countries(self, filter_asset=None): def dist_countries(self, filter_asset=None):
""" """
Distribute our advert into all countries and providers listed in the config. Distribute our advert into all countries and providers listed in the config.
@ -583,18 +582,22 @@ class Local(util.Base):
:rtype: bool or dict :rtype: bool or dict
""" """
dist_list = list(self.markets.create_distribution_list(self.platform, filter_asset)) 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, supported_currencies,
account_info, account_info,
) = self.markets.get_valid_account_details(self.platform) ) = self.markets.get_valid_account_details(self.platform)
# Let's get rid of the ad IDs and make it a tuple like dist_list # 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] 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: for asset, countrycode, currency, provider in dist_list:
if (asset, countrycode, currency, provider) not in our_ads: if (asset, countrycode, currency, provider) not in our_ads:
if currency in supported_currencies: if currency in supported_currencies:
# Create the actual ad and pass in all the stuff # Create the actual ad and pass in all the stuff
rtrn = self.create_ad( rtrn = yield self.create_ad(
asset, asset,
countrycode, countrycode,
currency, currency,
@ -604,9 +607,10 @@ class Local(util.Base):
# Bail on first error, let's not continue # Bail on first error, let's not continue
if rtrn is False: if rtrn is False:
return False return False
yield rtrn to_return.append(rtrn)
return to_return
# TODO: make async @inlineCallbacks
def redist_countries(self): def redist_countries(self):
""" """
Redistribute our advert details into all our listed adverts. Redistribute our advert details into all our listed adverts.
@ -616,7 +620,7 @@ class Local(util.Base):
:return: False or dict with response :return: False or dict with response
:rtype: bool or dict :rtype: bool or dict
""" """
our_ads = self.enum_ads() our_ads = yield self.enum_ads()
( (
supported_currencies, supported_currencies,
account_info, account_info,
@ -624,9 +628,10 @@ class Local(util.Base):
if not our_ads: if not our_ads:
self.log.error("Could not get our ads.") self.log.error("Could not get our ads.")
return False return False
to_return = []
for asset, ad_id, countrycode, currency, provider in our_ads: for asset, ad_id, countrycode, currency, provider in our_ads:
if currency in supported_currencies: if currency in supported_currencies:
rtrn = self.create_ad( rtrn = yield self.create_ad(
asset, asset,
countrycode, countrycode,
currency, currency,
@ -638,7 +643,8 @@ class Local(util.Base):
# Bail on first error, let's not continue # Bail on first error, let's not continue
if rtrn is False: if rtrn is False:
return False return False
yield (rtrn, ad_id) to_return.append((rtrn, ad_id))
return to_return
@inlineCallbacks @inlineCallbacks
def strip_duplicate_ads(self): def strip_duplicate_ads(self):

@ -3,6 +3,7 @@ from json import dumps, loads
# Project imports # Project imports
from settings import settings from settings import settings
import db
class GenericCommands(object): class GenericCommands(object):
@ -117,12 +118,17 @@ class GenericCommands(object):
class redist(object): class redist(object):
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux, caller): def got_redist(redist_output, msg):
for x in caller.redist_countries(): for x in redist_output:
if x[0]["success"]: if x[0]["success"]:
msg(f"{x[0]['response']['data']['message']}: {x[1]}") msg(f"{x[0]['response']['data']['message']}: {x[1]}")
else: 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): class stripdupes(object):
@staticmethod @staticmethod
@ -432,7 +438,7 @@ class IRCCommands(object):
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): 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): class ref(object):
name = "ref" name = "ref"
@ -442,7 +448,7 @@ class IRCCommands(object):
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 2: if length == 2:
ref_data = tx.get_ref(spl[1]) ref_data = db.get_ref(spl[1])
if not ref_data: if not ref_data:
msg(f"No such reference: {spl[1]}") msg(f"No such reference: {spl[1]}")
return return
@ -456,11 +462,11 @@ class IRCCommands(object):
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 2: if length == 2:
ref_data = tx.get_ref(spl[1]) ref_data = db.get_ref(spl[1])
if not ref_data: if not ref_data:
msg(f"No such reference: {spl[1]}") msg(f"No such reference: {spl[1]}")
return return
tx.del_ref(spl[1]) db.del_ref(spl[1])
msg(f"Deleted reference: {spl[1]}") msg(f"Deleted reference: {spl[1]}")
class arelease(object): class arelease(object):

Loading…
Cancel
Save