diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index b8265f9..e88065a 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -60,7 +60,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { addToMyRequests(request.client, id); - uint256 amount = price(request); + uint256 amount = request.price(); funds.received += amount; funds.balance += amount; transferFrom(msg.sender, amount); @@ -178,7 +178,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { removeFromMySlots(slot.host, slotId); - uint256 amount = pricePerSlot(requests[requestId]); + uint256 amount = requests[requestId].pricePerSlot(); funds.sent += amount; funds.balance -= amount; slot.state = SlotState.Paid; @@ -205,7 +205,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { // TODO: To be changed once we start paying out hosts for the time they // fill a slot. The amount that we paid to hosts will then have to be // deducted from the price. - uint256 amount = _price(request); + uint256 amount = request.price(); funds.sent += amount; funds.balance -= amount; require(token.transfer(msg.sender, amount), "Withdraw failed"); @@ -241,26 +241,6 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { } } - function _price( - uint64 numSlots, - uint256 duration, - uint256 reward - ) internal pure returns (uint256) { - return numSlots * duration * reward; - } - - function _price(Request memory request) internal pure returns (uint256) { - return _price(request.ask.slots, request.ask.duration, request.ask.reward); - } - - function price(Request calldata request) private pure returns (uint256) { - return _price(request.ask.slots, request.ask.duration, request.ask.reward); - } - - function pricePerSlot(Request memory request) private pure returns (uint256) { - return request.ask.duration * request.ask.reward; - } - function requestState( RequestId requestId ) public view requestIsKnown(requestId) returns (RequestState) { diff --git a/contracts/Requests.sol b/contracts/Requests.sol index 3433605..4349218 100644 --- a/contracts/Requests.sol +++ b/contracts/Requests.sol @@ -82,4 +82,14 @@ library Requests { result := ids } } + + function pricePerSlot( + Request memory request + ) internal pure returns (uint256) { + return request.ask.duration * request.ask.reward; + } + + function price(Request memory request) internal pure returns (uint256) { + return request.ask.slots * pricePerSlot(request); + } }