mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
from pisa import logging, M
|
|
|
|
# Dictionaries in Python are "passed-by-reference", so no return is needed for the Cleaner"
|
|
# https://docs.python.org/3/faq/programming.html#how-do-i-write-a-function-with-output-parameters-call-by-reference
|
|
|
|
|
|
class Cleaner:
|
|
@staticmethod
|
|
def delete_expired_appointment(expired_appointments, appointments, locator_uuid_map):
|
|
for uuid in expired_appointments:
|
|
locator = appointments[uuid].locator
|
|
|
|
appointments.pop(uuid)
|
|
|
|
if len(locator_uuid_map[locator]) == 1:
|
|
locator_uuid_map.pop(locator)
|
|
|
|
else:
|
|
locator_uuid_map[locator].remove(uuid)
|
|
|
|
logging.info(M("[Cleaner] end time reached with no match! Deleting appointment.",
|
|
locator=locator, uuid=uuid))
|
|
|
|
@staticmethod
|
|
def delete_completed_jobs(jobs, tx_job_map, completed_jobs, height):
|
|
for uuid, confirmations in completed_jobs:
|
|
logging.info(M("[Cleaner] job completed. Appointment ended after reaching enough confirmations.",
|
|
uuid=uuid, height=height, confirmations=confirmations))
|
|
|
|
# ToDo: #9-add-data-persistence
|
|
justice_txid = jobs[uuid].justice_txid
|
|
jobs.pop(uuid)
|
|
|
|
if len(tx_job_map[justice_txid]) == 1:
|
|
tx_job_map.pop(justice_txid)
|
|
|
|
logging.info(M("[Cleaner] no more jobs for justice transaction.", justice_txid=justice_txid))
|
|
|
|
else:
|
|
tx_job_map[justice_txid].remove(uuid)
|