This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
/
AppDirectory.sol
53 lines (47 loc) · 1.81 KB
/
AppDirectory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
pragma solidity ^0.4.21;
import "./versioning/ImplementationProvider.sol";
import "./versioning/ImplementationDirectory.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
/**
* @title AppDirectory
* @dev Implementation directory with a standard library as a fallback provider.
* @dev If the implementation is not found in the directory, it will search in the standard library.
*/
contract AppDirectory is ImplementationDirectory {
/**
* @dev Emitted when the standard library is changed.
* @param newStdlib Address of the new standard library.
*/
event StdlibChanged(address newStdlib);
/**
* @dev Provider for standard library implementations.
*/
ImplementationProvider public stdlib;
/**
* @dev Constructor function.
* @param _stdlib Provider for standard library implementations.
*/
function AppDirectory(ImplementationProvider _stdlib) public {
stdlib = _stdlib;
}
/**
* @dev Returns the implementation address for a given contract name.
* @dev If the implementation is not found in the directory, it will search in the standard library.
* @param contractName Name of the contract.
* @return Address where the contract is implemented, or 0 if it is not found.
*/
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);
}
/**
* @dev Sets a new implementation provider for standard library contracts.
* @param _stdlib Standard library implementation provider.
*/
function setStdlib(ImplementationProvider _stdlib) public onlyOwner {
stdlib = _stdlib;
emit StdlibChanged(_stdlib);
}
}