Skip to content

Instantly share code, notes, and snippets.

@spalladino
Created September 25, 2018 20:01
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 spalladino/2254a2058b35f7558c49d9d83b6422d8 to your computer and use it in GitHub Desktop.
Save spalladino/2254a2058b35f7558c49d9d83b6422d8 to your computer and use it in GitHub Desktop.
Sample package 2.0 contract
contract RepoPackage {
event NewVersion(uint256 versionId, uint16[3] semanticVersion);
struct Version {
uint16[3] semanticVersion;
address contractAddress;
bytes contentURI;
}
mapping (bytes32 => Version) versions;
function newVersion(uint16[3] _newSemanticVersion, address _contractAddress, bytes _contentURI) public {
versions[semanticVersionHash(_newSemanticVersion)] = Version(_newSemanticVersion, _contractAddress, _contentURI);
}
function getBySemanticVersion(uint16[3] _semanticVersion) public view returns (uint16[3], address, bytes);
Version storage version = versions[semanticVersionHash(_semanticVersion)];
return (version.semanticVersion, version.contractAddress, version.contentURI);
}
function semanticVersionHash(uint16[3] version) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(version[0], version[1], version[2]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment