Created
June 17, 2019 08:10
-
-
Save 0xdewy/9475bbaae1d146122b6f2d5b054be6e3 to your computer and use it in GitHub Desktop.
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
pragma solidity >=0.5.0; | |
import './Proxy.sol'; | |
import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | |
// @title is where Proxy can lookup users version preference and update valid implementations | |
// @notice resolver is ownable | |
contract Resolver is Ownable{ | |
Proxy public proxy; | |
mapping (address => address) public userVersion; | |
mapping (address => bool) public validImplementation; | |
// @notice proxy creates this contract and sets the owner | |
constructor(address owner) | |
public { | |
proxy = Proxy(msg.sender); | |
transferOwnership(owner); | |
} | |
// @notice user can set his preferred version of the contract here | |
function setUserVersion(address addr) | |
public { | |
require(validImplementation[addr]); | |
userVersion[msg.sender] = addr; | |
} | |
// @notice authorizes contracts to act as the implementation for Proxy | |
function setValidImplementation(address addr, bool valid) | |
public | |
returns (bool) { | |
require(msg.sender == address(proxy)); | |
validImplementation[addr] = valid; | |
return true; | |
} | |
// @notice get the version preferred by this user | |
function getUserVersion(address user) | |
public | |
view | |
returns (address){ | |
if (userVersion[user] == address(0)) | |
return proxy.implementation(); | |
else | |
return userVersion[user]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment