teos.builder¶
-
class
Builder
[source]¶ Bases:
object
The
Builder
class is in charge of reconstructing data loaded from the appointments database and build the data structures of theWatcher
and theResponder
.-
static
build_appointments
(appointments_data)[source]¶ Builds an appointments dictionary (
uuid:extended_appointment
) and a locator_uuid_map (locator:uuid
) given a dictionary of appointments from the database.- Parameters
appointments_data (
dict
) –a dictionary of dictionaries representing all the
Watcher
appointments stored in the database. The structure is as follows:{uuid: {locator: str, ...}, uuid: {locator:...}}
- Returns
A tuple with two dictionaries.
appointments
containing the appointment information inExtendedAppointment
objects andlocator_uuid_map
containing a map of appointment (uuid:locator
).- Return type
tuple
-
static
build_trackers
(tracker_data)[source]¶ Builds a tracker dictionary (
uuid:TransactionTracker
) and a tx_tracker_map (penalty_txid:uuid
) given a dictionary of trackers from the database.- Parameters
tracker_data (
dict
) –a dictionary of dictionaries representing all the
Responder
trackers stored in the database. The structure is as follows:{uuid: {locator: str, dispute_txid: str, ...}, uuid: {locator:...}}
- Returns
A tuple with two dictionaries.
trackers
containing the trackers’ information inTransactionTracker
objects and atx_tracker_map
containing the map of trackers (penalty_txid: uuid
).- Return type
tuple
-
static
populate_block_queue
(block_queue, missed_blocks)[source]¶ Populates a
Queue
of block hashes to initialize theWatcher
or theResponder
using backed up data.- Parameters
block_queue (
Queue
) – a queue.missed_blocks (
list
) – list of block hashes missed by the Watchtower (due to a crash or shutdown).
- Returns
A queue containing all the missed blocks hashes.
- Return type
Queue
-
static
update_states
(watcher, missed_blocks_watcher, missed_blocks_responder)[source]¶ Updates the states of both the
Watcher
and theResponder
. If both have pending blocks to process they need to be updated at the same time, block by block.If only one instance has to be updated,
populate_block_queue
should be used.- Parameters
watcher (
Watcher
) – aWatcher
instance (including aResponder
).missed_blocks_watcher (
list
) – the list of block missed by theWatcher
.missed_blocks_responder (
list
) – the list of block missed by theResponder
.
- Raises
ValueError – if one of the provided list is empty.
-
static