Add some docstrings

This commit is contained in:
Mark Veidemanis 2021-12-29 00:04:24 +00:00
parent 82b70991a4
commit d5c272d3f9
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 17 additions and 0 deletions

View File

@ -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']}") 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): 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 = "".join(choices(ascii_uppercase, k=5))
reference = f"XMR-{reference}" reference = f"XMR-{reference}"
existing_ref = r.get(f"trade.{trade_id}.reference") existing_ref = r.get(f"trade.{trade_id}.reference")
@ -148,6 +152,11 @@ class Transactions(object):
return False return False
def get_refs(self): def get_refs(self):
"""
Get all reference IDs for trades.
:return: list of trade IDs
:rtype: list
"""
references = [] references = []
ref_keys = r.keys("trade.*.reference") ref_keys = r.keys("trade.*.reference")
for key in ref_keys: for key in ref_keys:
@ -155,12 +164,20 @@ class Transactions(object):
return convert(references) return convert(references)
def get_ref(self, reference): 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}")) ref_data = convert(r.hgetall(f"trade.{reference}"))
if not ref_data: if not ref_data:
return False return False
return ref_data return ref_data
def del_ref(self, reference): def del_ref(self, reference):
"""
Delete a given reference from the Redis database.
"""
r.delete(f"trade.{reference}") r.delete(f"trade.{reference}")
r.delete(f"trade.{reference}.reference") r.delete(f"trade.{reference}.reference")