Begin implementing ad deduplication and re-enable releasing

This commit is contained in:
2023-04-18 11:25:56 +01:00
parent 84871d5a7c
commit 2b7e83dc0d
4 changed files with 44 additions and 15 deletions

View File

@@ -610,6 +610,7 @@ class LocalPlatformClient(ABC):
:rtype: bool or dict
"""
dist_list = list(self.create_distribution_list(ad, filter_asset))
print("Dist list", dist_list)
our_ads = await self.enum_ads()
(
supported_currencies,
@@ -620,10 +621,12 @@ class LocalPlatformClient(ABC):
log.error("Could not get our ads")
return False
our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads]
print("our_ads", our_ads)
to_return = []
for asset, countrycode, currency, provider in dist_list:
if (asset, countrycode, currency, provider) not in our_ads:
print("NOT IN OUR ADS", asset, countrycode, currency, provider)
if currency not in supported_currencies:
continue
# Create the actual ad and pass in all the stuff
@@ -692,7 +695,9 @@ class LocalPlatformClient(ABC):
:rtype: list
"""
existing_ads = await self.enum_ads()
print("EXISTING", existing_ads)
_size = len(existing_ads)
print("SIZE", _size)
repeated = []
for i in range(_size):
k = i + 1
@@ -704,10 +709,12 @@ class LocalPlatformClient(ABC):
repeated.append(existing_ads[i])
actioned = []
print("repeated", repeated)
for ad_id, country, currency in repeated:
rtrn = await self.api.ad_delete(ad_id)
actioned.append(rtrn["success"])
print("actioned", actioned)
return all(actioned)
async def release_trade_escrow(self, trade_id, reference):
@@ -716,21 +723,16 @@ class LocalPlatformClient(ABC):
title = "Releasing escrow"
await notify.sendmsg(self.instance.user, logmessage, title=title)
# THIS IS NOT A COMMENT
# THIS IS FOR SECURITY
# WHEN IT HAS BEEN CONFIRMED TO WORK
# THIS CAN BE UNCOMMENTED
# rtrn = await self.release_funds(trade_id)
# if rtrn["message"] == "OK":
# await self.api.contact_message_post(trade_id, "Thanks! Releasing now :)")
# return True
# else:
# logmessage = f"Release funds unsuccessful: {rtrn['message']}"
# title = "Release unsuccessful"
# log.error(logmessage)
# await notify.sendmsg(self.instance.user, logmessage, title=title)
# return
# UNCOMMENT TO HERE
rtrn = await self.release_funds(trade_id)
if rtrn["message"] == "OK":
await self.api.contact_message_post(trade_id, "Thanks! Releasing now :)")
return True
else:
logmessage = f"Release funds unsuccessful: {rtrn['message']}"
title = "Release unsuccessful"
log.error(logmessage)
await notify.sendmsg(self.instance.user, logmessage, title=title)
return
async def update_trade_tx(self, stored_trade, tx_obj):
"""