marketplace: simplify requestEnd()

This commit is contained in:
Mark Spanbroek 2025-04-16 13:50:46 +02:00
parent 7a566182d5
commit 9603025202
2 changed files with 1 additions and 22 deletions

View File

@ -478,19 +478,10 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
function requestEnd(RequestId requestId) public view returns (Timestamp) {
RequestState state = requestState(requestId);
if (
state == RequestState.New ||
state == RequestState.Started ||
state == RequestState.Failed
) {
return _requestContexts[requestId].endsAt;
}
if (state == RequestState.Cancelled) {
return _requestContexts[requestId].expiresAt;
}
Timestamp currentTime = Timestamps.currentTime();
Timestamp end = _requestContexts[requestId].endsAt;
return Timestamps.earliest(end, currentTime);
return _requestContexts[requestId].endsAt;
}
function requestExpiry(RequestId requestId) public view returns (Timestamp) {

View File

@ -67,16 +67,4 @@ library Timestamps {
) internal pure returns (Duration) {
return Duration.wrap(Timestamp.unwrap(end) - Timestamp.unwrap(start));
}
/// Returns the earliest of the two timestamps
function earliest(
Timestamp a,
Timestamp b
) internal pure returns (Timestamp) {
if (a <= b) {
return a;
} else {
return b;
}
}
}