-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request zeppelinos/zos-lib#42 from zeppelinos/feature/41_r…
…efactor_project_controller Refactor project controller to work with a single distribution
- Loading branch information
Showing
23 changed files
with
1,182 additions
and
670 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
packages/lib/contracts/application/management/AppDirectory.sol
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,24 @@ | ||
pragma solidity ^0.4.21; | ||
|
||
import "../versioning/ContractProvider.sol"; | ||
import "../versioning/ContractDirectory.sol"; | ||
import "zeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
|
||
contract AppDirectory is ContractDirectory { | ||
ContractProvider public stdlib; | ||
|
||
function AppDirectory(ContractProvider _stdlib) public { | ||
stdlib = _stdlib; | ||
} | ||
|
||
function getImplementation(string contractName) public view returns (address) { | ||
address implementation = super.getImplementation(contractName); | ||
if(implementation != address(0)) return implementation; | ||
if(stdlib != address(0)) return stdlib.getImplementation(contractName); | ||
return address(0); | ||
} | ||
|
||
function setStdlib(ContractProvider _stdlib) public onlyOwner { | ||
stdlib = _stdlib; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/lib/contracts/application/management/BaseAppManager.sol
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,47 @@ | ||
pragma solidity ^0.4.21; | ||
|
||
import "../versioning/ContractProvider.sol"; | ||
import "../../upgradeability/OwnedUpgradeabilityProxy.sol"; | ||
import "../../upgradeability/UpgradeabilityProxyFactory.sol"; | ||
import "zeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
|
||
contract BaseAppManager is Ownable { | ||
UpgradeabilityProxyFactory public factory; | ||
|
||
function BaseAppManager(UpgradeabilityProxyFactory _factory) public { | ||
require(address(_factory) != address(0)); | ||
factory = _factory; | ||
} | ||
|
||
function getProvider() internal view returns (ContractProvider); | ||
|
||
function getImplementation(string contractName) public view returns (address) { | ||
return getProvider().getImplementation(contractName); | ||
} | ||
|
||
function create(string contractName) public returns (OwnedUpgradeabilityProxy) { | ||
address implementation = getImplementationOrRevert(contractName); | ||
return factory.createProxy(this, implementation); | ||
} | ||
|
||
function createAndCall(string contractName, bytes data) payable public returns (OwnedUpgradeabilityProxy) { | ||
address implementation = getImplementationOrRevert(contractName); | ||
return factory.createProxyAndCall.value(msg.value)(this, implementation, data); | ||
} | ||
|
||
function upgradeTo(OwnedUpgradeabilityProxy proxy, string contractName) public onlyOwner { | ||
address implementation = getImplementationOrRevert(contractName); | ||
proxy.upgradeTo(implementation); | ||
} | ||
|
||
function upgradeToAndCall(OwnedUpgradeabilityProxy proxy, string contractName, bytes data) payable public onlyOwner { | ||
address implementation = getImplementationOrRevert(contractName); | ||
proxy.upgradeToAndCall.value(msg.value)(implementation, data); | ||
} | ||
|
||
function getImplementationOrRevert(string contractName) internal view returns (address) { | ||
address implementation = getImplementation(contractName); | ||
require(implementation != address(0)); | ||
return implementation; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/lib/contracts/application/management/PackagedAppManager.sol
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,29 @@ | ||
pragma solidity ^0.4.21; | ||
|
||
import "./BaseAppManager.sol"; | ||
import "../versioning/Package.sol"; | ||
import "../../upgradeability/UpgradeabilityProxyFactory.sol"; | ||
|
||
contract PackagedAppManager is BaseAppManager { | ||
Package public package; | ||
string public version; | ||
|
||
function PackagedAppManager(Package _package, string _version, UpgradeabilityProxyFactory _factory) | ||
BaseAppManager(_factory) | ||
public | ||
{ | ||
require(address(_package) != address(0)); | ||
require(_package.hasVersion(_version)); | ||
package = _package; | ||
version = _version; | ||
} | ||
|
||
function setVersion(string newVersion) public onlyOwner { | ||
require(package.hasVersion(newVersion)); | ||
version = newVersion; | ||
} | ||
|
||
function getProvider() internal view returns (ContractProvider) { | ||
return package.getVersion(version); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/lib/contracts/application/management/UnversionedAppManager.sol
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,25 @@ | ||
pragma solidity ^0.4.21; | ||
|
||
import "./BaseAppManager.sol"; | ||
import "../versioning/ContractProvider.sol"; | ||
import "../../upgradeability/UpgradeabilityProxyFactory.sol"; | ||
|
||
contract UnversionedAppManager is BaseAppManager { | ||
ContractProvider internal provider; | ||
|
||
function UnversionedAppManager(ContractProvider _provider, UpgradeabilityProxyFactory _factory) | ||
BaseAppManager(_factory) | ||
public | ||
{ | ||
setProvider(_provider); | ||
} | ||
|
||
function getProvider() internal view returns (ContractProvider) { | ||
return provider; | ||
} | ||
|
||
function setProvider(ContractProvider _provider) public onlyOwner { | ||
require(address(_provider) != address(0)); | ||
provider = _provider; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/lib/contracts/application/versioning/ContractDirectory.sol
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,19 @@ | ||
pragma solidity ^0.4.21; | ||
|
||
import "./ContractProvider.sol"; | ||
import "zeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
|
||
contract ContractDirectory is ContractProvider, Ownable { | ||
event ImplementationAdded(string contractName, address indexed implementation); | ||
|
||
mapping (string => address) internal implementations; | ||
|
||
function getImplementation(string contractName) public view returns (address) { | ||
return implementations[contractName]; | ||
} | ||
|
||
function setImplementation(string contractName, address implementation) public onlyOwner { | ||
implementations[contractName] = implementation; | ||
emit ImplementationAdded(contractName, implementation); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/lib/contracts/application/versioning/ContractProvider.sol
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,5 @@ | ||
pragma solidity ^0.4.21; | ||
|
||
interface ContractProvider { | ||
function getImplementation(string contractName) public view returns (address); | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/lib/contracts/application/versioning/FreezableContractDirectory.sol
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,20 @@ | ||
pragma solidity ^0.4.21; | ||
|
||
import "./ContractDirectory.sol"; | ||
|
||
contract FreezableContractDirectory is ContractDirectory { | ||
bool public frozen; | ||
|
||
modifier whenNotFrozen() { | ||
require(!frozen); | ||
_; | ||
} | ||
|
||
function freeze() onlyOwner whenNotFrozen public { | ||
frozen = true; | ||
} | ||
|
||
function setImplementation(string contractName, address implementation) public onlyOwner whenNotFrozen { | ||
super.setImplementation(contractName, implementation); | ||
} | ||
} |
Oops, something went wrong.