2018-10-24 17:12:07 +00:00
|
|
|
pragma solidity ^0.4.24;
|
|
|
|
|
2018-10-28 05:28:10 +00:00
|
|
|
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
|
|
|
|
|
2018-10-25 12:59:05 +00:00
|
|
|
|
2018-10-24 17:12:07 +00:00
|
|
|
contract AddressRegistry {
|
|
|
|
|
2018-10-28 17:33:16 +00:00
|
|
|
event SetGov(address person, bool assigned);
|
2018-10-27 11:11:57 +00:00
|
|
|
event AddressChanged(string name, address addr);
|
2018-10-28 17:33:16 +00:00
|
|
|
event PendingAdmin(string name, address addr);
|
2018-10-27 11:11:57 +00:00
|
|
|
event ResolverApproved(address user, address addr);
|
|
|
|
event ResolverDisapproved(address user, address addr);
|
2018-10-24 17:12:07 +00:00
|
|
|
|
2018-10-27 11:11:57 +00:00
|
|
|
// Addresses managing the protocol governance
|
2018-10-27 12:07:21 +00:00
|
|
|
mapping(address => bool) public governors;
|
2018-10-27 11:11:57 +00:00
|
|
|
|
|
|
|
// Address registry of connected smart contracts
|
2018-10-27 12:07:21 +00:00
|
|
|
mapping(bytes32 => address) public registry;
|
2018-10-27 11:11:57 +00:00
|
|
|
|
|
|
|
// Contract addresses having rights to perform tasks, approved by users
|
|
|
|
// Resolver Contract >> User >> Approved
|
2018-10-27 12:07:21 +00:00
|
|
|
mapping(address => mapping(address => bool)) public resolvers;
|
2018-10-27 11:11:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-27 11:15:26 +00:00
|
|
|
|
2018-10-28 17:36:35 +00:00
|
|
|
contract ManageRegistry is AddressRegistry {
|
2018-10-28 16:59:07 +00:00
|
|
|
|
2018-10-28 17:42:11 +00:00
|
|
|
using SafeMath for uint;
|
|
|
|
using SafeMath for uint256;
|
|
|
|
|
2018-10-27 12:07:21 +00:00
|
|
|
address public pendingAdmin;
|
|
|
|
uint public pendingTime;
|
|
|
|
function setPendingAdmin() public {
|
|
|
|
require(block.timestamp > pendingTime, "Pending!");
|
|
|
|
registry[keccak256("admin")] = pendingAdmin;
|
2018-10-28 17:33:16 +00:00
|
|
|
emit PendingAdmin("admin", pendingAdmin);
|
2018-10-27 12:07:21 +00:00
|
|
|
}
|
2018-10-27 11:11:57 +00:00
|
|
|
|
2018-10-27 12:07:21 +00:00
|
|
|
function setAddr(string name, address newAddr) public {
|
2018-10-28 05:28:10 +00:00
|
|
|
if (keccak256(abi.encodePacked(name)) != keccak256(abi.encodePacked("admin"))) {
|
2018-10-27 12:07:21 +00:00
|
|
|
require(
|
|
|
|
governors[msg.sender],
|
|
|
|
"Permission Denied"
|
|
|
|
);
|
|
|
|
pendingAdmin = newAddr;
|
2018-10-28 05:28:10 +00:00
|
|
|
pendingTime = block.timestamp.add(24 * 60 * 60); // adding 24 hours
|
2018-10-27 12:07:21 +00:00
|
|
|
} else {
|
|
|
|
require(
|
|
|
|
msg.sender == getAddr("admin"),
|
|
|
|
"Permission Denied"
|
|
|
|
);
|
2018-10-28 05:28:10 +00:00
|
|
|
registry[keccak256(abi.encodePacked(name))] = newAddr;
|
2018-10-27 12:07:21 +00:00
|
|
|
}
|
2018-10-28 17:33:16 +00:00
|
|
|
emit AddressChanged(name, newAddr);
|
2018-10-27 11:11:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAddr(string name) public view returns(address addr) {
|
2018-10-28 05:28:10 +00:00
|
|
|
addr = registry[keccak256(abi.encodePacked(name))];
|
2018-10-27 11:11:57 +00:00
|
|
|
require(addr != address(0), "Not a valid address.");
|
|
|
|
}
|
2018-10-25 18:44:53 +00:00
|
|
|
|
2018-10-27 11:11:57 +00:00
|
|
|
}
|
2018-10-24 17:12:07 +00:00
|
|
|
|
|
|
|
|
2018-10-28 17:36:35 +00:00
|
|
|
contract ManageGovernors is ManageRegistry {
|
|
|
|
|
|
|
|
function setGovernor(address person, bool assigned) public {
|
|
|
|
require(
|
|
|
|
msg.sender == getAddr("admin"),
|
|
|
|
"Permission Denied"
|
|
|
|
);
|
|
|
|
governors[person] = assigned;
|
|
|
|
emit SetGov(person, assigned);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
contract ManageResolvers is ManageGovernors {
|
2018-10-24 17:12:07 +00:00
|
|
|
|
2018-10-25 18:44:53 +00:00
|
|
|
function approveResolver() public {
|
2018-10-27 11:11:57 +00:00
|
|
|
resolvers[getAddr("resolver")][msg.sender] = true;
|
|
|
|
emit ResolverApproved(msg.sender, getAddr("resolver"));
|
2018-10-25 12:27:42 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 18:44:53 +00:00
|
|
|
function disapproveResolver() public {
|
2018-10-27 11:11:57 +00:00
|
|
|
resolvers[getAddr("resolver")][msg.sender] = false;
|
|
|
|
emit ResolverDisapproved(msg.sender, getAddr("resolver"));
|
2018-10-25 12:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isApprovedResolver(address user) public view returns(bool) {
|
2018-10-27 11:11:57 +00:00
|
|
|
return resolvers[getAddr("resolver")][user];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-27 11:15:26 +00:00
|
|
|
|
2018-10-27 11:11:57 +00:00
|
|
|
contract InitRegistry is ManageResolvers {
|
|
|
|
|
|
|
|
constructor() public {
|
2018-10-28 05:28:10 +00:00
|
|
|
registry[keccak256(abi.encodePacked("admin"))] = msg.sender;
|
2018-10-25 12:27:42 +00:00
|
|
|
}
|
|
|
|
|
2018-10-28 16:59:07 +00:00
|
|
|
}
|