Skip to content

Instantly share code, notes, and snippets.

@ericoporto
Created November 1, 2019 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericoporto/f52b70cf1105750f4461aee2e8b89ff5 to your computer and use it in GitHub Desktop.
Save ericoporto/f52b70cf1105750f4461aee2e8b89ff5 to your computer and use it in GitHub Desktop.
exercise: Simple contract to store software licenses in solidity
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