Fix race conditions in cleanup

pull/1/head
Mark Veidemanis 3 years ago
parent 6418c5ecca
commit 712a144467
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -77,8 +77,7 @@ class Agora(object):
current_trades = [] current_trades = []
for contact_id, contact in dash.items(): for contact_id, contact in dash.items():
reference = self.tx.tx_to_ref(contact_id) reference = self.tx.tx_to_ref(contact_id)
if not reference: if reference:
reference = "not_set"
current_trades.append(reference) current_trades.append(reference)
buyer = contact["data"]["buyer"]["username"] buyer = contact["data"]["buyer"]["username"]
amount = contact["data"]["amount"] amount = contact["data"]["amount"]
@ -87,9 +86,11 @@ class Agora(object):
if not contact["data"]["is_selling"]: if not contact["data"]["is_selling"]:
continue continue
if reference not in self.last_dash: if reference not in self.last_dash:
self.tx.new_trade(contact_id, buyer, currency, amount, amount_xmr) reference = self.tx.new_trade(contact_id, buyer, currency, amount, amount_xmr)
if reference:
if reference not in current_trades:
current_trades.append(reference)
if send_irc: if send_irc:
self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {buyer} {amount}{currency} {amount_xmr}XMR") self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {buyer} {amount}{currency} {amount_xmr}XMR")
dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR") dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR")
@ -99,6 +100,8 @@ class Agora(object):
for ref in list(self.last_dash): # We're removing from the list on the fly for ref in list(self.last_dash): # We're removing from the list on the fly
if ref not in current_trades: if ref not in current_trades:
self.last_dash.remove(ref) self.last_dash.remove(ref)
if reference and reference not in current_trades:
current_trades.append(reference)
self.tx.cleanup(current_trades) self.tx.cleanup(current_trades)
return dash_tmp return dash_tmp

@ -144,6 +144,10 @@ class Transactions(object):
self.irc.client.msg(self.irc.client.channel, f"Generated reference for {trade_id}: {reference}") self.irc.client.msg(self.irc.client.channel, f"Generated reference for {trade_id}: {reference}")
if settings.Agora.Send == "1": if settings.Agora.Send == "1":
self.agora.agora.contact_message_post(trade_id, f"Hi! When sending the payment please use reference code: {reference}") self.agora.agora.contact_message_post(trade_id, f"Hi! When sending the payment please use reference code: {reference}")
if existing_ref:
return convert(existing_ref)
else:
return reference
def find_tx(self, reference, amount): def find_tx(self, reference, amount):
""" """

Loading…
Cancel
Save