Fixed WalletRegistry error.

This commit is contained in:
Sowmayjain 2019-04-04 00:29:32 +05:30
parent 690547bbef
commit e023b658c1
2 changed files with 16 additions and 26 deletions

View File

@ -56,13 +56,11 @@ contract LogicRegistry is AddressRegistry {
* @return bool logic proxy is authorised by system admin * @return bool logic proxy is authorised by system admin
* @return bool logic proxy is default proxy * @return bool logic proxy is default proxy
*/ */
function isLogicAuth(address logicAddr) public view returns (bool, bool) { function logic(address logicAddr) public view returns (bool) {
if (defaultLogicProxies[logicAddr]) { if (defaultLogicProxies[logicAddr] || logicProxies[logicAddr]) {
return (true, true); return true;
} else if (logicProxies[logicAddr]) {
return (true, false);
} else { } else {
return (false, false); return false;
} }
} }
@ -104,6 +102,7 @@ contract LogicRegistry is AddressRegistry {
contract WalletRegistry is LogicRegistry { contract WalletRegistry is LogicRegistry {
event Created(address indexed sender, address indexed owner, address proxy); event Created(address indexed sender, address indexed owner, address proxy);
event LogRecord(address indexed currentOwner, address indexed nextOwner, address proxy);
mapping(address => UserWallet) public proxies; mapping(address => UserWallet) public proxies;
@ -121,19 +120,21 @@ contract WalletRegistry is LogicRegistry {
function build(address owner) public returns (UserWallet proxy) { function build(address owner) public returns (UserWallet proxy) {
require(proxies[owner] == UserWallet(0), "multiple-proxy-per-user-not-allowed"); require(proxies[owner] == UserWallet(0), "multiple-proxy-per-user-not-allowed");
proxy = new UserWallet(); proxy = new UserWallet();
proxies[address(this)] = proxy; // will be changed via record() in next line execution
proxy.setOwner(owner); proxy.setOwner(owner);
emit Created(msg.sender, owner, address(proxy)); emit Created(msg.sender, owner, address(proxy));
proxies[owner] = proxy;
} }
/** /**
* @dev update the proxy record whenever owner changed on any proxy * @dev update the proxy record whenever owner changed on any proxy
* Throws if msg.sender is not a proxy contract created via this contract * Throws if msg.sender is not a proxy contract created via this contract
*/ */
function updateProxyRecord(address currentOwner, address nextOwner) public { function record(address currentOwner, address nextOwner) public {
require(msg.sender == address(proxies[currentOwner]), "invalid-proxy-or-owner"); require(msg.sender == address(proxies[currentOwner]), "invalid-proxy-or-owner");
require(proxies[nextOwner] == UserWallet(0), "multiple-proxy-per-user-not-allowed");
proxies[nextOwner] = proxies[currentOwner]; proxies[nextOwner] = proxies[currentOwner];
proxies[currentOwner] = UserWallet(0); proxies[currentOwner] = UserWallet(0);
emit LogRecord(currentOwner, nextOwner, address(proxies[nextOwner]));
} }
} }

View File

@ -14,11 +14,11 @@ library SafeMath {
/** /**
* @title AddressRegistryInterface Interface * @title RegistryInterface Interface
*/ */
interface AddressRegistryInterface { interface RegistryInterface {
function isLogicAuth(address logicAddr) external view returns (bool, bool); function logic(address logicAddr) external view returns (bool);
function updateProxyRecord(address currentOwner, address nextOwner) external; function record(address currentOwner, address nextOwner) external;
} }
@ -37,22 +37,11 @@ contract AddressRecord {
*/ */
modifier logicAuth(address logicAddr) { modifier logicAuth(address logicAddr) {
require(logicAddr != address(0), "logic-proxy-address-required"); require(logicAddr != address(0), "logic-proxy-address-required");
AddressRegistryInterface logicProxy = AddressRegistryInterface(registry); bool islogic = RegistryInterface(registry).logic(logicAddr);
(bool isLogicAuth, ) = logicProxy.isLogicAuth(logicAddr); require(islogic, "logic-not-authorised");
require(isLogicAuth, "logic-not-authorised");
_; _;
} }
/**
* @dev this updates the internal proxy ownership on "registry" contract
* @param currentOwner is the current owner
* @param nextOwner is the new assigned owner
*/
function setProxyRecordOwner(address currentOwner, address nextOwner) internal {
AddressRegistryInterface initCall = AddressRegistryInterface(registry);
initCall.updateProxyRecord(currentOwner, nextOwner);
}
} }
@ -78,7 +67,7 @@ contract UserAuth is AddressRecord {
* @dev sets new owner * @dev sets new owner
*/ */
function setOwner(address nextOwner) public auth { function setOwner(address nextOwner) public auth {
setProxyRecordOwner(owner, nextOwner); RegistryInterface(registry).record(owner, nextOwner);
owner = nextOwner; owner = nextOwner;
emit LogSetOwner(nextOwner); emit LogSetOwner(nextOwner);
} }