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 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]));
}
}

View File

@ -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);
}