From e023b658c107f647248fe6ae82b6a5fb1fabde47 Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Thu, 4 Apr 2019 00:29:32 +0530 Subject: [PATCH] Fixed WalletRegistry error. --- contracts/InstaRegistry.sol | 17 +++++++++-------- contracts/UserWallet.sol | 25 +++++++------------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/contracts/InstaRegistry.sol b/contracts/InstaRegistry.sol index da460ca..144195b 100644 --- a/contracts/InstaRegistry.sol +++ b/contracts/InstaRegistry.sol @@ -56,13 +56,11 @@ contract LogicRegistry is AddressRegistry { * @return bool logic proxy is authorised by system admin * @return bool logic proxy is default proxy */ - function isLogicAuth(address logicAddr) public view returns (bool, bool) { - if (defaultLogicProxies[logicAddr]) { - return (true, true); - } else if (logicProxies[logicAddr]) { - return (true, false); + function logic(address logicAddr) public view returns (bool) { + if (defaultLogicProxies[logicAddr] || logicProxies[logicAddr]) { + return true; } else { - return (false, false); + return false; } } @@ -104,6 +102,7 @@ contract LogicRegistry is AddressRegistry { contract WalletRegistry is LogicRegistry { 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; @@ -121,19 +120,21 @@ contract WalletRegistry is LogicRegistry { function build(address owner) public returns (UserWallet proxy) { require(proxies[owner] == UserWallet(0), "multiple-proxy-per-user-not-allowed"); proxy = new UserWallet(); + proxies[address(this)] = proxy; // will be changed via record() in next line execution proxy.setOwner(owner); emit Created(msg.sender, owner, address(proxy)); - proxies[owner] = 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 */ - 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(proxies[nextOwner] == UserWallet(0), "multiple-proxy-per-user-not-allowed"); proxies[nextOwner] = proxies[currentOwner]; proxies[currentOwner] = UserWallet(0); + emit LogRecord(currentOwner, nextOwner, address(proxies[nextOwner])); } } diff --git a/contracts/UserWallet.sol b/contracts/UserWallet.sol index b73db1d..e70c5a1 100644 --- a/contracts/UserWallet.sol +++ b/contracts/UserWallet.sol @@ -14,11 +14,11 @@ library SafeMath { /** - * @title AddressRegistryInterface Interface + * @title RegistryInterface Interface */ -interface AddressRegistryInterface { - function isLogicAuth(address logicAddr) external view returns (bool, bool); - function updateProxyRecord(address currentOwner, address nextOwner) external; +interface RegistryInterface { + function logic(address logicAddr) external view returns (bool); + function record(address currentOwner, address nextOwner) external; } @@ -37,22 +37,11 @@ contract AddressRecord { */ modifier logicAuth(address logicAddr) { require(logicAddr != address(0), "logic-proxy-address-required"); - AddressRegistryInterface logicProxy = AddressRegistryInterface(registry); - (bool isLogicAuth, ) = logicProxy.isLogicAuth(logicAddr); - require(isLogicAuth, "logic-not-authorised"); + bool islogic = RegistryInterface(registry).logic(logicAddr); + require(islogic, "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 */ function setOwner(address nextOwner) public auth { - setProxyRecordOwner(owner, nextOwner); + RegistryInterface(registry).record(owner, nextOwner); owner = nextOwner; emit LogSetOwner(nextOwner); }