Skip to content

Commit

Permalink
Merge 4b7472e into f65b959
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed May 10, 2019
2 parents f65b959 + 4b7472e commit ad9d767
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 58 deletions.
90 changes: 65 additions & 25 deletions contracts/PackageRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract PackageRegistry is Authorized, PackageRegistryInterface {
ReleaseValidator private releaseValidator;

// Events
event PackageRelease(bytes32 indexed nameHash, bytes32 indexed releaseId);
event VersionRelease(string packageName, string version, string manifestURI);
event PackageTransfer(address indexed oldOwner, address indexed newOwner);

//
Expand Down Expand Up @@ -73,7 +73,7 @@ contract PackageRegistry is Authorized, PackageRegistryInterface {
)
public
auth
returns (bytes32 id)
returns (bytes32 releaseId)
{
require(address(packageDb) != 0x0, "escape:PackageIndex:package-db-not-set");
require(address(releaseDb) != 0x0, "escape:PackageIndex:release-db-not-set");
Expand Down Expand Up @@ -117,8 +117,8 @@ contract PackageRegistry is Authorized, PackageRegistryInterface {
releaseDb.setRelease(nameHash, versionHash, manifestURI);

// Log the release.
bytes32 releaseId = releaseDb.hashRelease(nameHash, versionHash);
emit PackageRelease(nameHash, releaseId);
releaseId = releaseDb.hashRelease(nameHash, versionHash);
emit VersionRelease(packageName, version, manifestURI);

return releaseId;
}
Expand Down Expand Up @@ -210,27 +210,27 @@ contract PackageRegistry is Authorized, PackageRegistryInterface {
}

/// @dev Returns a slice of the array of all package hashes for the named package.
/// @param _offset The starting index for the slice.
/// @param offset The starting index for the slice.
/// @param limit The length of the slice
function getAllPackageIds(uint _offset, uint limit)
function getAllPackageIds(uint offset, uint limit)
public
view
returns(
bytes32[] packageIds,
uint offset
uint pointer
)
{
return packageDb.getAllPackageIds(_offset, limit);
return packageDb.getAllPackageIds(offset, limit);
}

/// @dev Retrieves the name for the given name hash.
/// @param nameHash The name hash to lookup the name for.
function getPackageName(bytes32 nameHash)
/// @param packageId The name hash of package to lookup the name for.
function getPackageName(bytes32 packageId)
public
view
returns (string)
returns (string packageName)
{
return packageDb.getPackageName(nameHash);
return packageDb.getPackageName(packageId);
}

/// @dev Returns the package data.
Expand All @@ -257,7 +257,7 @@ contract PackageRegistry is Authorized, PackageRegistryInterface {
public
view
returns (
string name,
string packageName,
string version,
string manifestURI
)
Expand All @@ -266,41 +266,81 @@ contract PackageRegistry is Authorized, PackageRegistryInterface {
bytes32 nameHash;
(nameHash,versionHash, ,) = releaseDb.getReleaseData(releaseId);

name = packageDb.getPackageName(nameHash);
packageName = packageDb.getPackageName(nameHash);
version = releaseDb.getVersion(versionHash);
manifestURI = releaseDb.getManifestURI(releaseId);

return (name, version, manifestURI);
return (packageName, version, manifestURI);
}

/// @dev Returns a slice of the array of all package hashes for the named package.
/// @param offset The starting index for the slice.
/// @param limit The length of the slice
function getAllReleaseIds(string name, uint _offset, uint limit)
function getAllReleaseIds(string packageName, uint offset, uint limit)
public
view
returns (
bytes32[] releaseIds,
uint offset
uint pointer
)
{
bytes32 nameHash = packageDb.hashName(name);
return releaseDb.getAllReleaseIds(nameHash, _offset, limit);
bytes32 nameHash = packageDb.hashName(packageName);
return releaseDb.getAllReleaseIds(nameHash, offset, limit);
}

// @dev Returns release id that *would* be generated for a name and version pair on `release`.
// @param name Package name
// @param version Version string (ex: '1.0.0')
function generateReleaseId(string name, string version)
/// @dev Returns release id that *would* be generated for a name and version pair on `release`.
/// @param packageName Package name
/// @param version Version string (ex: '1.0.0')
function generateReleaseId(string packageName, string version)
public
view
returns (bytes32)
returns (bytes32 releaseId)
{
bytes32 nameHash = packageDb.hashName(name);
bytes32 nameHash = packageDb.hashName(packageName);
bytes32 versionHash = releaseDb.hashVersion(version);
return keccak256(abi.encodePacked(nameHash, versionHash));
}

/// @dev Returns the release id for a given name and version pair if present on registry.
/// @param packageName Package name
/// @param version Version string(ex: '1.0.0')
function getReleaseId(string packageName, string version)
public
view
returns (bytes32 releaseId)
{
releaseId = generateReleaseId(packageName, version);
bool _releaseExists = releaseDb.releaseExists(releaseId);
if (!_releaseExists) {
return 0;
}
return releaseId;
}

/// @dev Returns the number of packages stored on the registry
function numPackageIds()
public
view
returns (uint totalCount)
{
return packageDb.getNumPackages();
}

/// @dev Returns the number of releases for a given package name on the registry
/// @param packageName Package name
function numReleaseIds(string packageName)
public
view
returns (uint totalCount)
{
bool _packageExists = packageExists(packageName);
if (!_packageExists) {
return 0;
}
bytes32 nameHash = packageDb.hashName(packageName);
return releaseDb.getNumReleasesForNameHash(nameHash);
}

//
// +----------------+
// | Internal API |
Expand Down
39 changes: 27 additions & 12 deletions contracts/PackageRegistryInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ contract PackageRegistryInterface {

/// @dev Creates a a new release for the named package.
/// @notice Will create a new release the given package with the given release information.
/// @param name Package name
/// @param packageName Package name
/// @param version Version string (ex: 1.0.0)
/// @param manifestURI The URI for the release manifest for this release.
function release(
string name,
string packageName,
string version,
string manifestURI
)
Expand All @@ -36,7 +36,7 @@ contract PackageRegistryInterface {
function getPackageName(bytes32 packageId)
public
view
returns (string);
returns (string packageName);

/// @dev Returns a slice of the array of all package ids for the named package.
/// @param offset The starting index for the slice.
Expand All @@ -45,20 +45,20 @@ contract PackageRegistryInterface {
public
view
returns (
bytes32[] ids,
uint _offset
bytes32[] packageIds,
uint pointer
);

/// @dev Returns a slice of the array of all release hashes for the named package.
/// @param name Package name
/// @param packageName Package name
/// @param offset The starting index for the slice.
/// @param limit The length of the slice
function getAllReleaseIds(string name, uint offset, uint limit)
function getAllReleaseIds(string packageName, uint offset, uint limit)
public
view
returns (
bytes32[] ids,
uint _offset
bytes32[] releaseIds,
uint pointer
);

/// @dev Returns the package data for a release.
Expand All @@ -73,10 +73,25 @@ contract PackageRegistryInterface {
);

// @dev Returns release id that *would* be generated for a name and version pair on `release`.
// @param name Package name
// @param packageName Package name
// @param version Version string (ex: '1.0.0')
function generateReleaseId(string name, string version)
function generateReleaseId(string packageName, string version)
public
view
returns (bytes32);
returns (bytes32 releaseId);

/// @dev Returns the release id for a given name and version pair if present on registry.
/// @param packageName Package name
/// @param version Version string(ex: '1.0.0')
function getReleaseId(string packageName, string version)
public
view
returns (bytes32 releaseId);

/// @dev Returns the number of packages stored on the registry
function numPackageIds() public view returns (uint totalCount);

/// @dev Returns the number of releases for a given package name on the registry
/// @param packageName Package name
function numReleaseIds(string packageName) public view returns (uint totalCount);
}

0 comments on commit ad9d767

Please sign in to comment.