smart-contract/contracts/ProxyRegistry.sol

65 lines
1.9 KiB
Solidity
Raw Normal View History

2019-03-11 12:30:45 +00:00
pragma solidity ^0.5.0;
import "./UserProxy.sol";
2019-03-09 20:42:05 +00:00
2019-03-11 12:30:45 +00:00
// checking if the logic proxy is authorised
contract SystemAdmin {
address public logicProxyAddr;
modifier isAdmin() {
require(msg.sender == getAdmin(), "permission-denied");
_;
}
function getAdmin() internal view returns (address) {
AddressRegistryInterface registry = AddressRegistryInterface(logicProxyAddr);
return registry.getAddress("admin");
}
}
contract ProxyRegistry is SystemAdmin {
2019-03-09 20:42:05 +00:00
event Created(address indexed sender, address indexed owner, address proxy);
mapping(address => UserProxy) public proxies;
bool public guardianEnabled;
constructor(address _logicProxyAddr) public {
logicProxyAddr = _logicProxyAddr;
}
2019-03-09 20:42:05 +00:00
function build() public returns (UserProxy proxy) {
proxy = build(msg.sender);
2019-03-09 20:42:05 +00:00
}
2019-03-11 22:52:48 +00:00
// deploys a new proxy instance and sets custom owner of proxy
function build(address owner) public returns (UserProxy proxy) {
require(
proxies[owner] == UserProxy(0) || proxies[owner].owner() != owner,
"multiple-proxy-per-user-not-allowed"
); // Not allow new proxy if the user already has one and remains being the owner
proxy = new UserProxy(owner, logicProxyAddr);
2019-03-09 20:42:05 +00:00
emit Created(msg.sender, owner, address(proxy));
proxies[owner] = proxy;
}
// msg.sender should always be proxies created via this contract for successful execution
function updateProxyRecord(address currentOwner, address nextOwner) public {
require(msg.sender == address(proxies[currentOwner]), "invalid-proxy-or-owner");
proxies[nextOwner] = proxies[currentOwner];
proxies[currentOwner] = UserProxy(0);
}
function enableGuardian() public isAdmin {
guardianEnabled = true;
}
function disableGuardian() public isAdmin {
guardianEnabled = false;
}
}