Implement a smart contract for gym membership management.
Alice owns a gym. She creates an instance of this contract to manage memberships. Bob soon buys a membership for 30 days. 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.
constructor: function GymMembership(uint256 dailyPrice)
msg.sender
) is the owner.dailyPrice
is the price of buying membership for one day in wei.register: function register(uint256 numDays) payable
numDays
days starting from the time of the transaction (i.e. now
).validate: function validate(address client) view returns (bool)
true
if client
currently has a valid membership.withdraw: function withdraw()
pragma solidity ^0.4.21;
contract GymMembership {
// <contract_variables>
// </contract_variables>
function GymMembership(uint256 dailyPrice) public {
// TODO
}
function register(uint256 numDays) public payable {
// TODO
}
function validate(address client) public view returns (bool) {
// TODO
}
function withdraw() public {
// TODO
}
}