From d5c272d3f94a828c521248aca8545fc962dc78a3 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 29 Dec 2021 00:04:24 +0000 Subject: [PATCH] Add some docstrings --- handler/transactions.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/handler/transactions.py b/handler/transactions.py index 87c78fe..8cd236c 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -106,6 +106,10 @@ class Transactions(object): self.irc.client.msg(self.irc.client.channel, f"All checks passed, would release funds for {stored_trade['id']}") def new_trade(self, trade_id, buyer, currency, amount, amount_xmr): + """ + Called when we have a new trade in Agora. + Store details in Redis, generate a reference and optionally let the customer know the reference. + """ reference = "".join(choices(ascii_uppercase, k=5)) reference = f"XMR-{reference}" existing_ref = r.get(f"trade.{trade_id}.reference") @@ -148,6 +152,11 @@ class Transactions(object): return False def get_refs(self): + """ + Get all reference IDs for trades. + :return: list of trade IDs + :rtype: list + """ references = [] ref_keys = r.keys("trade.*.reference") for key in ref_keys: @@ -155,12 +164,20 @@ class Transactions(object): return convert(references) def get_ref(self, reference): + """ + Get a reference ID for a single trade. + :return: trade ID + :rtype: string + """ ref_data = convert(r.hgetall(f"trade.{reference}")) if not ref_data: return False return ref_data def del_ref(self, reference): + """ + Delete a given reference from the Redis database. + """ r.delete(f"trade.{reference}") r.delete(f"trade.{reference}.reference")