This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New lib model for supporting multiple deps
App contract now has multiple providers, instead of having a single one which could have a fallback (stdlib). Now the app explicitly manages its dependencies. App is still offered in two flavours: unversioned (which accepts directories) and versioned (which accepts packages with a pinned version). All contract wrapper models were also updated. In particular, App no longer acts as a facade, but is instead an actual wrapper of the App contract. A new abstraction, Project, is introduced to be used as a facade by the CLI (or lib users). Project is subclassed by LibProject and AppProject.
- Loading branch information
1 parent
f5c850a
commit beb7afd
Showing
55 changed files
with
1,878 additions
and
2,212 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
import "./BaseApp.sol"; | ||
import "./versioning/Package.sol"; | ||
import "../upgradeability/UpgradeabilityProxyFactory.sol"; | ||
|
||
/** | ||
* @title VersionedApp | ||
* @dev App for an upgradeable project that can use different versions from packages. | ||
* This is the standard entry point for an upgradeable app. | ||
*/ | ||
contract VersionedApp is BaseApp { | ||
|
||
struct ProviderInfo { | ||
Package package; | ||
string version; | ||
} | ||
|
||
mapping(string => ProviderInfo) internal providers; | ||
|
||
/** | ||
* @dev Emitted when a package dependency is changed in the application. | ||
* @param providerName Name of the package that changed. | ||
* @param package Address of the package associated to the name. | ||
* @param version Version of the package in use. | ||
*/ | ||
event PackageChanged(string providerName, address package, string version); | ||
|
||
/** | ||
* @dev Constructor function. | ||
* @param _factory Proxy factory. | ||
*/ | ||
constructor(UpgradeabilityProxyFactory _factory) BaseApp(_factory) public { } | ||
|
||
/** | ||
* @dev Returns the provider for a given package name, or zero if not set. | ||
* @param packageName Name of the package to be retrieved. | ||
* @return The provider. | ||
*/ | ||
function getProvider(string packageName) public view returns (ImplementationProvider) { | ||
ProviderInfo storage info = providers[packageName]; | ||
if (address(info.package) == address(0)) return ImplementationProvider(0); | ||
return info.package.getVersion(info.version); | ||
} | ||
|
||
/** | ||
* @dev Returns information on a package given its name. | ||
* @param packageName Name of the package to be queried. | ||
* @return A tuple with the package address and pinned version given a package name, or zero if not set | ||
*/ | ||
function getPackage(string packageName) public view returns (Package, string) { | ||
ProviderInfo storage info = providers[packageName]; | ||
return (info.package, info.version); | ||
} | ||
|
||
/** | ||
* @dev Sets a package in a specific version as a dependency for this application. | ||
* Requires the version to be present in the package. | ||
* @param packageName Name of the package to set or overwrite. | ||
* @param package Address of the package to register. | ||
* @param version Version of the package to use in this application. | ||
*/ | ||
function setPackage(string packageName, Package package, string version) public onlyOwner { | ||
require(package.hasVersion(version), "The requested version must be registered in the given package"); | ||
providers[packageName] = ProviderInfo(package, version); | ||
emit PackageChanged(packageName, package, version); | ||
} | ||
|
||
/** | ||
* @dev Unsets a package given its name. | ||
* Reverts if the package is not set in the application. | ||
* @param packageName Name of the package to remove. | ||
*/ | ||
function unsetPackage(string packageName) public onlyOwner { | ||
require(address(providers[packageName].package) != address(0), "Package to unset not found"); | ||
delete providers[packageName]; | ||
} | ||
} |
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
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
Oops, something went wrong.