From 15281e8335de59dceb8496e50a157ca43bf6abd5 Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Wed, 20 Mar 2019 01:50:40 +0530 Subject: [PATCH] Registry change ownership after build() --- contracts/AddressRegistry.sol | 3 ++- contracts/UserWallet.sol | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/contracts/AddressRegistry.sol b/contracts/AddressRegistry.sol index d529c8c..e2194a4 100644 --- a/contracts/AddressRegistry.sol +++ b/contracts/AddressRegistry.sol @@ -122,7 +122,8 @@ 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(owner); + proxy = new UserWallet(); + proxy.setOwnerOnce(owner); emit Created(msg.sender, owner, address(proxy)); proxies[owner] = proxy; } diff --git a/contracts/UserWallet.sol b/contracts/UserWallet.sol index daf8d45..3244cd2 100644 --- a/contracts/UserWallet.sol +++ b/contracts/UserWallet.sol @@ -25,12 +25,12 @@ interface AddressRegistryInterface { /** - * @title Address Record + * @title Address Registry Record */ contract AddressRecord { /** - * @dev address registry of system, logic and proxy addresses + * @dev address registry of system, logic and wallet addresses */ address public registry; @@ -111,6 +111,18 @@ contract UserAuth is AddressRecord { emit LogSetOwner(owner, msg.sender); } + /** + * @dev sets owner and function is only be called once by registry on build() + * and this hack verifiy the contract on etherscan automatically + * as no dynamic owner address is sent in the constructor + * @param _owner is the new owner of this contract wallet + */ + function setOwnerOnce(address _owner) public auth { + require(msg.sender == registry, "permission-denied"); + owner = _owner; + emit LogSetOwner(owner, msg.sender); + } + /** * @dev checks if called by owner or contract itself * @param src is the address initiating the call @@ -288,9 +300,9 @@ contract UserWallet is UserManager, UserNote { * @dev sets the "address registry", owner's last activity, owner's active period and initial owner * @param _owner initial owner of the contract */ - constructor(address _owner) public { + constructor() public { registry = msg.sender; - owner = _owner; + owner = msg.sender; // will be changed in initial call itself lastActivity = block.timestamp; activePeriod = 30 days; // default on deployment and changeable afterwards }