mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 22:54:23 +01:00
Comments and sleep -> asleep
This commit is contained in:
committed by
Sergi Delgado Segura
parent
803712e9b1
commit
8aba0f7daf
@@ -34,12 +34,21 @@ class Watcher:
|
|||||||
def __init__(self, max_appointments=MAX_APPOINTMENTS):
|
def __init__(self, max_appointments=MAX_APPOINTMENTS):
|
||||||
self.appointments = dict()
|
self.appointments = dict()
|
||||||
self.block_queue = Queue()
|
self.block_queue = Queue()
|
||||||
self.sleep = True
|
self.asleep = True
|
||||||
self.max_appointments = max_appointments
|
self.max_appointments = max_appointments
|
||||||
|
|
||||||
def add_appointment(self, appointment, debug):
|
def add_appointment(self, appointment, debug):
|
||||||
# ToDo: Discuss about validation of input data
|
# ToDo: Discuss about validation of input data
|
||||||
|
|
||||||
|
# Rationale:
|
||||||
|
# The Watcher will analyze every received block looking for appointment matches. If there is no work
|
||||||
|
# to do the watcher can sleep (appointments = {} and sleep = True) otherwise for every received block
|
||||||
|
# the watcher will get the list of transactions and compare it with the list of appointments.
|
||||||
|
# If the watcher is awake, every new appointment will just be added to the appointment list until
|
||||||
|
# max_appointments is reached.
|
||||||
|
|
||||||
|
# ToDo: Check how to handle appointment completion
|
||||||
|
|
||||||
if len(self.appointments) < self.max_appointments:
|
if len(self.appointments) < self.max_appointments:
|
||||||
# Appointments are identified by the locator: the most significant 16 bytes of the commitment txid.
|
# Appointments are identified by the locator: the most significant 16 bytes of the commitment txid.
|
||||||
# While 16-byte hash collisions are not likely, they are possible, so we will store appointments in lists
|
# While 16-byte hash collisions are not likely, they are possible, so we will store appointments in lists
|
||||||
@@ -52,8 +61,8 @@ class Watcher:
|
|||||||
appointment.id = len(self.appointments[appointment.locator])
|
appointment.id = len(self.appointments[appointment.locator])
|
||||||
self.appointments[appointment.locator].append(appointment)
|
self.appointments[appointment.locator].append(appointment)
|
||||||
|
|
||||||
if self.sleep:
|
if self.asleep:
|
||||||
self.sleep = False
|
self.asleep = False
|
||||||
zmq_subscriber = Thread(target=self.do_subscribe, args=[self.block_queue, debug])
|
zmq_subscriber = Thread(target=self.do_subscribe, args=[self.block_queue, debug])
|
||||||
watcher = Thread(target=self.do_watch, args=[debug])
|
watcher = Thread(target=self.do_watch, args=[debug])
|
||||||
zmq_subscriber.start()
|
zmq_subscriber.start()
|
||||||
@@ -61,10 +70,6 @@ class Watcher:
|
|||||||
|
|
||||||
appointment_added = True
|
appointment_added = True
|
||||||
|
|
||||||
# Rationale:
|
|
||||||
# The Watcher will analyze every received block looking for appointment matches. If there is no work
|
|
||||||
# to do the watcher can sleep (appointments = [] and sleep = True) otherwise for every received block
|
|
||||||
# the watcher will get the list of transactions and compare it with the list of appointments
|
|
||||||
else:
|
else:
|
||||||
appointment_added = False
|
appointment_added = False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user