smart-contract/ProxyRegistry.sol

34 lines
1.1 KiB
Solidity
Raw Normal View History

pragma solidity ^0.4.23;
2019-03-09 20:42:05 +00:00
import "./UserProxy.sol";
2019-03-09 20:42:05 +00:00
// ProxyRegistry
contract ProxyRegistry {
event Created(address indexed sender, address indexed owner, address proxy);
mapping(address => UserProxy) public proxies;
address public logicProxyAddr;
constructor(address logicProxyAddr_) public {
logicProxyAddr = logicProxyAddr_;
}
2019-03-09 20:42:05 +00:00
// deploys a new proxy instance
// sets owner of proxy to caller
function build(uint activeDays) public returns (UserProxy proxy) {
proxy = build(msg.sender, activeDays);
2019-03-09 20:42:05 +00:00
}
// deploys a new proxy instance
// sets custom owner of proxy
function build(address owner, uint activeDays) 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(logicProxyAddr, activeDays);
2019-03-09 20:42:05 +00:00
emit Created(msg.sender, owner, address(proxy));
proxy.setOwner(owner);
proxies[owner] = proxy;
}
}