Implement a smart contract for gym machine rental.
Alice owns a gym. She creates an instance of this contract to manage access to one of the popular machines in her gym, setting the minimum price per time slot to 0.005 ether.
Bob reserves the time slot between 11:00am and 11:30am this Sunday for 0.005 ether using the time slot's number since contract creation. After 11:00am he scans the QR code of his Ethereum address on the machine. The machine checks if Bob has access and unlocks.
Alternatively, Claire reserves the same time slot at 10:30am for 0.01 ether. Bob gets his money back, and Claire can use the machine from 11:00am the same way Bob would have used it.
constructor: function GymMachineRental(uint256 minimumPricePerSlot)
msg.sender
) is the owner.minimumPricePerSlot
is the minimum price for renting the machine for a single time slot.reserve: function reserve(uint24 slotId) payable
slotId
'th time slot since contract creation. For example, if the contract was created today at 00:00, then slot number 16 would be the one from 07:30 to 08:00, while slot number 64 would be the same time slot on the next day.validate: function validate(address client) view returns (bool)
true
if client
is entitled to use the machine at the time of the validation.withdraw: function withdraw()
pragma solidity ^0.4.21;
contract GymMachineRental {
// <contract_variables>
// </contract_variables>
function GymMachineRental(uint256 minimumPricePerSlot) public {
// TODO
}
function reserve(uint24 slotId) public payable {
// TODO
}
function validate(address client) public view returns (bool) {
// TODO
}
function withdraw() public {
// TODO
}
}