Implement a smart contract for tokenized gym membership management.
Alice owns a gym. She creates an instance of this contract with 100 monthly pass tokens and transfers these tokens to the lucky winners of their recent contest.
The winners can trade with these passes, transferring them to other addresses if they want to.
Bob bought one of these passes from his friend, Claire. After this, every time Bob visits the gym, he shows his public address QR code to the receptionist, who scans it and validates Bob's membership through the smart contract. Bob's membership is valid for 30 days from the first time he went to the gym.
constructor: function GymMembership(uint16 numPasses)
msg.sender
) is the owner.numPasses
is the number of monthly pass tokens issued.0
to numPasses - 1
).register: function transfer(uint16 passId, address to)
passId
to the owner of the address to
.passId
is a valid pass id and the sender of the transaction (msg.sender
) is the current owner of the associated pass. (Note: initially, all passes belong to the contract's owner.)validate: function validate(uint16 passId)
passId
is a valid pass identifier, the sender of the transaction (msg.sender
) is the owner of the associated pass, and the pass has not yet expired.validate
is called with the given passId
, we set the expiry date of the associated pass to 30 days from the time of the transaction (i.e. now
).pragma solidity ^0.4.21;
contract GymMembership {
// <contract_variables>
// </contract_variables>
function GymMembership(uint16 numPasses) public {
// TODO
}
function transfer(uint16 passId, address to) public {
// TODO
}
function validate(uint16 passId) public {
// TODO
}
}