Implement looking up references

This commit is contained in:
Mark Veidemanis 2021-12-29 14:32:06 +00:00
parent 64bf5a77ee
commit bf4381caa6
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 22 additions and 7 deletions

View File

@ -83,12 +83,18 @@ class Agora(object):
currency = contact["data"]["currency"]
if not contact["data"]["is_selling"]:
continue
reference = self.tx.tx_to_ref(contact_id)
if not reference:
reference = "not_set"
if contact_id not in self.last_dash:
self.tx.new_trade(contact_id, buyer, currency, amount, amount_xmr)
if send_irc:
self.irc.client.msg(self.irc.client.channel, f"AUTO {contact_id}: {buyer} {amount}{currency} {amount_xmr}XMR")
dash_tmp.append(f"{contact_id}: {buyer} {amount}{currency} {amount_xmr}XMR")
self.irc.client.msg(
self.irc.client.channel, f"AUTO {contact_id}: {buyer} {amount}{currency} {amount_xmr}XMR {reference}"
)
dash_tmp.append(f"{contact_id}: {buyer} {amount}{currency} {amount_xmr}XMR {reference}")
self.last_dash.add(contact_id)
# Purge old trades from cache

View File

@ -113,9 +113,9 @@ class Transactions(object):
reference = "".join(choices(ascii_uppercase, k=5))
reference = f"XMR-{reference}"
existing_ref = r.get(f"trade.{trade_id}.reference")
if existing_ref:
self.irc.client.msg(self.irc.client.channel, f"Existing reference for {trade_id}: {existing_ref.decode('utf-8')}")
else:
# if existing_ref:
# self.irc.client.msg(self.irc.client.channel, f"Existing reference for {trade_id}: {existing_ref.decode('utf-8')}")
if not existing_ref:
r.set(f"trade.{trade_id}.reference", reference)
to_store = {
"id": trade_id,
@ -185,7 +185,16 @@ class Transactions(object):
pass
def tx_to_ref(self, tx):
pass
refs = self.get_refs()
for reference in refs:
ref_data = convert(r.hgetall(f"trade.{reference}"))
if not ref_data:
continue
if ref_data["id"] == tx:
return reference
def ref_to_tx(self, reference):
pass
ref_data = convert(r.hgetall(f"trade.{reference}"))
if not ref_data:
return False
return ref_data["id"]