Implement a smart contract for top-up gym membership management.
Alice owns a gym. She creates an instance of this contract to manage memberships, setting the daily price to 0.1 ether. Bob uploads 1 ether to his account. Every time Bob visits the gym, he shows his public address QR code to the receptionist who scans it and checks Bob's membership through the smart contract. When Bob enters, his balance is charged with the daily price. If Bob's last payment was at most 12 hours ago (e.g. he goes out during his training session to have a phone call), he does not have to pay again to enter.
constructor: function GymMembership(uint256 dailyPrice)
msg.sender
) is the owner.dailyPrice
is the price of using the gym once.top-up: function topUp() payable
msg.value
) to the balance of the sender (msg.sender
).validate: function validate(address client)
client
has sufficient balance to enter the gym.client
has entered the gym (paying the daily price) in the last 12 hours. In this case, client
is not charged again. Orclient
has not entered the gym in the last 12 hours, and client
has sufficient balance. In this case, client
is charged with the daily price and the transaction succeeds.withdraw: function withdraw()
msg.sender
) is the owner of the contract.pragma solidity ^0.4.21;
contract GymMembership {
// <contract_variables>
// </contract_variables>
function GymMembership(uint256 dailyPrice) public {
// TODO
}
function topUp() public payable {
// TODO
}
function validate(address client) public {
// TODO
}
function withdraw() public {
// TODO
}
}