mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 06:04:21 +01:00
Removes start/end time from appointment
This commit is contained in:
@@ -65,8 +65,6 @@ class Inspector:
|
||||
raise InspectionFailed(errors.UNKNOWN_JSON_RPC_EXCEPTION, "unexpected error occurred")
|
||||
|
||||
self.check_locator(appointment_data.get("locator"))
|
||||
self.check_start_time(appointment_data.get("start_time"), block_height)
|
||||
self.check_end_time(appointment_data.get("end_time"), appointment_data.get("start_time"), block_height)
|
||||
self.check_to_self_delay(appointment_data.get("to_self_delay"))
|
||||
self.check_blob(appointment_data.get("encrypted_blob"))
|
||||
|
||||
@@ -100,87 +98,6 @@ class Inspector:
|
||||
elif not is_locator(locator):
|
||||
raise InspectionFailed(errors.APPOINTMENT_WRONG_FIELD_FORMAT, "wrong locator format ({})".format(locator))
|
||||
|
||||
@staticmethod
|
||||
def check_start_time(start_time, block_height):
|
||||
"""
|
||||
Checks if the provided ``start_time`` is correct.
|
||||
|
||||
Start times must be ahead the current best chain tip.
|
||||
|
||||
Args:
|
||||
start_time (:obj:`int`): the block height at which the tower is requested to start watching for breaches.
|
||||
block_height (:obj:`int`): the chain height.
|
||||
|
||||
Raises:
|
||||
:obj:`InspectionFailed`: if any of the fields is wrong.
|
||||
"""
|
||||
|
||||
if start_time is None:
|
||||
raise InspectionFailed(errors.APPOINTMENT_EMPTY_FIELD, "empty start_time received")
|
||||
|
||||
elif type(start_time) != int:
|
||||
raise InspectionFailed(
|
||||
errors.APPOINTMENT_WRONG_FIELD_TYPE, "wrong start_time data type ({})".format(type(start_time))
|
||||
)
|
||||
|
||||
elif start_time < block_height:
|
||||
raise InspectionFailed(errors.APPOINTMENT_FIELD_TOO_SMALL, "start_time is in the past")
|
||||
|
||||
elif start_time == block_height:
|
||||
raise InspectionFailed(
|
||||
errors.APPOINTMENT_FIELD_TOO_SMALL,
|
||||
"start_time is too close to current height. Accepted times are: [current_height+1, current_height+6]",
|
||||
)
|
||||
|
||||
elif start_time > block_height + 6:
|
||||
raise InspectionFailed(
|
||||
errors.APPOINTMENT_FIELD_TOO_BIG,
|
||||
"start_time is too far in the future. Accepted start times are up to 6 blocks in the future",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def check_end_time(end_time, start_time, block_height):
|
||||
"""
|
||||
Checks if the provided ``end_time`` is correct.
|
||||
|
||||
End times must be ahead both the ``start_time`` and the current best chain tip.
|
||||
|
||||
Args:
|
||||
end_time (:obj:`int`): the block height at which the tower is requested to stop watching for breaches.
|
||||
start_time (:obj:`int`): the block height at which the tower is requested to start watching for breaches.
|
||||
block_height (:obj:`int`): the chain height.
|
||||
|
||||
Raises:
|
||||
:obj:`InspectionFailed`: if any of the fields is wrong.
|
||||
"""
|
||||
|
||||
# TODO: What's too close to the current height is not properly defined. Right now any appointment that ends in
|
||||
# the future will be accepted (even if it's only one block away).
|
||||
|
||||
if end_time is None:
|
||||
raise InspectionFailed(errors.APPOINTMENT_EMPTY_FIELD, "empty end_time received")
|
||||
|
||||
elif type(end_time) != int:
|
||||
raise InspectionFailed(
|
||||
errors.APPOINTMENT_WRONG_FIELD_TYPE, "wrong end_time data type ({})".format(type(end_time))
|
||||
)
|
||||
|
||||
elif end_time > block_height + BLOCKS_IN_A_MONTH: # 4320 = roughly a month in blocks
|
||||
raise InspectionFailed(
|
||||
errors.APPOINTMENT_FIELD_TOO_BIG, "end_time should be within the next month (<= current_height + 4320)"
|
||||
)
|
||||
elif start_time > end_time:
|
||||
raise InspectionFailed(errors.APPOINTMENT_FIELD_TOO_SMALL, "end_time is smaller than start_time")
|
||||
|
||||
elif start_time == end_time:
|
||||
raise InspectionFailed(errors.APPOINTMENT_FIELD_TOO_SMALL, "end_time is equal to start_time")
|
||||
|
||||
elif block_height > end_time:
|
||||
raise InspectionFailed(errors.APPOINTMENT_FIELD_TOO_SMALL, "end_time is in the past")
|
||||
|
||||
elif block_height == end_time:
|
||||
raise InspectionFailed(errors.APPOINTMENT_FIELD_TOO_SMALL, "end_time is too close to current height")
|
||||
|
||||
def check_to_self_delay(self, to_self_delay):
|
||||
"""
|
||||
Checks if the provided ``to_self_delay`` is correct.
|
||||
|
||||
Reference in New Issue
Block a user