Created
November 1, 2019 12:09
-
-
Save ericoporto/f52b70cf1105750f4461aee2e8b89ff5 to your computer and use it in GitHub Desktop.
exercise: Simple contract to store software licenses in solidity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.11; | |
contract SoftwareLicense { | |
struct License { | |
uint serial; | |
address user; | |
uint datetime; | |
} | |
mapping (address => License) license; | |
mapping (uint => address) serialOwner; | |
function registerLicense(uint _serial) public { | |
license[msg.sender].user = msg.sender; | |
license[msg.sender].serial = _serial; | |
license[msg.sender].datetime = now; | |
} | |
function getLicenseFromUser(address user) public view returns (uint, address, uint) { | |
return (license[user].serial, license[user].user, license[user].datetime); | |
} | |
function getLicenseFromSerial(uint serial) public view returns (uint, address, uint) { | |
return getLicenseFromUser(serialOwner[serial]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment