Refactor add_appointment cli code

This commit is contained in:
Turtle
2019-11-30 00:42:36 -05:00
parent 49657ccbfc
commit 40d7ca1912
5 changed files with 162 additions and 106 deletions

View File

@@ -3,7 +3,7 @@ from queue import Queue
from threading import Thread
from common.cryptographer import Cryptographer
from common.constants import LOCATOR_LEN_HEX
from common.tools import compute_locator
from common.logger import Logger
from pisa.cleaner import Cleaner
@@ -71,20 +71,6 @@ class Watcher:
if not isinstance(responder, Responder):
self.responder = Responder(db_manager)
@staticmethod
def compute_locator(tx_id):
"""
Computes an appointment locator given a transaction id.
Args:
tx_id (:obj:`str`): the transaction id used to compute the locator.
Returns:
(:obj:`str`): The computed locator.
"""
return tx_id[:LOCATOR_LEN_HEX]
def add_appointment(self, appointment):
"""
Adds a new appointment to the ``appointments`` dictionary if ``max_appointments`` has not been reached.
@@ -238,7 +224,7 @@ class Watcher:
found.
"""
potential_locators = {Watcher.compute_locator(txid): txid for txid in txids}
potential_locators = {compute_locator(txid): txid for txid in txids}
# Check is any of the tx_ids in the received block is an actual match
intersection = set(self.locator_uuid_map.keys()).intersection(potential_locators.keys())