Implement a smart contract for smart parking.
Alice owns a parking lot. She creates an instance of this contract for each parking spot, setting the price per time slot to 0.01 ether.
Bob reserves one of the parking spots for the time slot between 10:00am and 11:00am this Sunday using his license plate number "ABC123". When the time arrives, Bob parks his car at the spot and leaves to do his business. The cameras in the parking lot detect his license plate number ("ABC123") and check if he has access to the parking spot at that time. If not, they might send a payment notice to the address associated with the plate number.
constructor: function SmartParking(uint256 pricePerSlot)
msg.sender
) is the owner.pricePerSlot
is the price for renting the parking spot for a single time slot.reserve: function reserve(uint24 slotId, string licensePlate) payable
slotId
'th time slot since contract creation for the car identified by licensePlate
. For example, if the contract was created today at 00:00, then slot number 8 would be the one from 08:00 to 09:00, while slot number 32 would be the same time slot on the next day.transfer: function transfer(uint24 slotId, address to, string newLicensePlate)
slotId
'th time slot since contract creation to the address to
(with the license plate number newLicensePlate
).msg.sender
).validate: function validate(string licensePlate) view returns (bool)
true
if the car identified by licensePlate
is entitled to use the parking spot at the time of the validation.a
and b
like this: keccak256(a) == keccak256(b)
.withdraw: function withdraw()
pragma solidity ^0.4.21;
contract SmartParking {
// <contract_variables>
// </contract_variables>
function SmartParking(uint256 pricePerSlot) public {
// TODO
}
function reserve(uint24 slotId, string licensePlate) public payable {
// TODO
}
function transfer(uint24 slotId, address to, string newLicensePlate) public {
// TODO
}
function validate(string licensePlate) public view returns (bool) {
// TODO
}
function withdraw() public {
// TODO
}
}