Package
contract Package
A package is composed by a set of versions, identified via semantic versioning, where each version has a contract address that refers to a reusable implementation, plus an optional content URI with metadata. Note that the semver identifier is restricted to major, minor, and patch, as prerelease tags are not supported.
Index
Reference
Events
VersionAdded
event VersionAdded(uint64[] semanticVersion, address contractAddress, bytes contentURI)
Emitted when a version is added to the package.
- Parameters:
semanticVersion
- Name of the added version.contractAddress
- Contract associated with the version.contentURI
- Optional content URI with metadata of the version.
Functions
addVersion
function addVersion(uint64[] semanticVersion, address contractAddress, bytes contentURI) public
Adds a new version to the package. Only the Owner can add new versions. Reverts if the specified semver identifier already exists. Emits a `VersionAdded` event if successful.
- Modifiers:
- onlyOwner
- Parameters:
semanticVersion
- Semver identifier of the version.contractAddress
- Contract address for the version, must be non-zero.contentURI
- Optional content URI for the version.
getContract
function getContract(uint64[] semanticVersion) public view returns (address)
Returns a contract for a version given its semver identifier. This method is equivalent to `getVersion`, but returns only the contract address.
- Parameters:
semanticVersion
- Semver identifier of the version.- Returns:
- Contract address for the version, or zero if not exists.
getLatest
function getLatest() public view returns (uint64[], address, bytes)
Returns the version with the highest semver identifier registered in the package. For instance, if `1.2.0`, `1.3.0`, and `2.0.0` are present, will always return `2.0.0`, regardless of the order in which they were registered. Returns zero if no versions are registered.
- Returns:
- Semver identifier, contract address, and content URI for the version, or zero if not exists.
getLatestByMajor
function getLatestByMajor(uint64 major) public view returns (uint64[], address, bytes)
Returns the version with the highest semver identifier for the given major. For instance, if `1.2.0`, `1.3.0`, and `2.0.0` are present, will return `1.3.0` for major `1`, regardless of the order in which they were registered. Returns zero if no versions are registered for the specified major.
- Parameters:
major
- Major identifier to query- Returns:
- Semver identifier, contract address, and content URI for the version, or zero if not exists.
getVersion
function getVersion(uint64[] semanticVersion) public view returns (address, bytes)
Returns a version given its semver identifier.
- Parameters:
semanticVersion
- Semver identifier of the version.- Returns:
- Contract address and content URI for the version, or zero if not exists.
hasVersion
function hasVersion(uint64[] semanticVersion) public view returns (bool)
Checks whether a version is present in the package.
- Parameters:
semanticVersion
- Semver identifier of the version.- Returns:
- true if the version is registered in this package, false otherwise.
semanticVersionHash
function semanticVersionHash(uint64[] version) internal pure returns (bytes32)
- Parameters:
version
- uint64[]- Returns:
- bytes32
semanticVersionIsZero
function semanticVersionIsZero(uint64[] version) internal pure returns (bool)
- Parameters:
version
- uint64[]- Returns:
- bool