[Marketplace] Move `slotId()` to `Requests` library

Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
This commit is contained in:
Mark Spanbroek 2023-01-11 10:52:08 +01:00 committed by markspanbroek
parent 07e9043b30
commit 6aa76257f8
2 changed files with 8 additions and 8 deletions

View File

@ -82,7 +82,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
Request storage request = _request(requestId); Request storage request = _request(requestId);
require(slotIndex < request.ask.slots, "Invalid slot"); require(slotIndex < request.ask.slots, "Invalid slot");
SlotId slotId = _toSlotId(requestId, slotIndex); SlotId slotId = Requests.slotId(requestId, slotIndex);
Slot storage slot = slots[slotId]; Slot storage slot = slots[slotId];
require(slot.host == address(0), "Slot already filled"); require(slot.host == address(0), "Slot already filled");
@ -399,13 +399,6 @@ contract Marketplace is Collateral, Proofs, StateRetrieval {
return s == RequestState.New || s == RequestState.Started; return s == RequestState.New || s == RequestState.Started;
} }
function _toSlotId(
RequestId requestId,
uint256 slotIndex
) internal pure returns (SlotId) {
return SlotId.wrap(keccak256(abi.encode(requestId, slotIndex)));
}
function _notEqual(RequestId a, uint256 b) internal pure returns (bool) { function _notEqual(RequestId a, uint256 b) internal pure returns (bool) {
return RequestId.unwrap(a) != bytes32(b); return RequestId.unwrap(a) != bytes32(b);
} }

View File

@ -42,6 +42,13 @@ library Requests {
return RequestId.wrap(keccak256(abi.encode(request))); return RequestId.wrap(keccak256(abi.encode(request)));
} }
function slotId(
RequestId requestId,
uint256 slotIndex
) internal pure returns (SlotId) {
return SlotId.wrap(keccak256(abi.encode(requestId, slotIndex)));
}
function toRequestIds( function toRequestIds(
bytes32[] memory ids bytes32[] memory ids
) internal pure returns (RequestId[] memory result) { ) internal pure returns (RequestId[] memory result) {