Implement a smart contract for virtual server rental.
Alice owns a server park. She creates an instance of this contract to manage access to one of her servers, setting the price per time slot to 0.01 ether.
Bob reserves the time slot between 11:00am and 11:30am this Sunday using the time slot's number since contract creation. Later, he decides to transfer his reservation to Claire. After 11:00am, Claire sends her address and a packet signed with her private key to the server. The server validates the packet, checks is she has access during the current time slot, and grants access to Claire.
constructor: function ReserveVS(uint256 pricePerSlot)
msg.sender
) is the owner.pricePerSlot
is the price for renting the server 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.transfer: function transfer(uint24 slotId, address to)
slotId
'th time slot to address to
.msg.sender
).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 ReserveVS {
// <contract_variables>
// </contract_variables>
function ReserveVS(uint256 pricePerSlot) public {
// TODO
}
function reserve(uint24 slotId) public payable {
// TODO
}
function transfer(uint24 slotId, address to) public {
// TODO
}
function validate(address client) public view returns (bool) {
// TODO
}
function withdraw() public {
// TODO
}
}