From 84bb005997e8a0c116a43ccce9cf3c47e5986d9a Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Sat, 3 Mar 2018 17:16:32 -0300 Subject: [PATCH] constructor logic encapsulated to prevent programming errors --- contracts/identity/Identity.sol | 19 +++++++++++++------ contracts/identity/IdentityKernel.sol | 4 +--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/contracts/identity/Identity.sol b/contracts/identity/Identity.sol index ff6c76b..745d0b7 100644 --- a/contracts/identity/Identity.sol +++ b/contracts/identity/Identity.sol @@ -80,11 +80,8 @@ contract Identity is ERC725, ERC735 { } function Identity() public { - _addKey(bytes32(msg.sender), MANAGEMENT_KEY, 0); - - minimumApprovalsByKeyPurpose[MANAGEMENT_KEY] = 1; - minimumApprovalsByKeyPurpose[ACTION_KEY] = 1; - } + _constructIdentity(msg.sender); + } function () public @@ -417,6 +414,16 @@ contract Identity is ERC725, ERC735 { require(recoveryContract == address(0)); recoveryContract = _recoveryContract; } + + function _constructIdentity(address _manager) + internal + { + require(minimumApprovalsByKeyPurpose[MANAGEMENT_KEY] == 0); + _addKey(bytes32(_manager), MANAGEMENT_KEY, 0); + + minimumApprovalsByKeyPurpose[MANAGEMENT_KEY] = 1; + minimumApprovalsByKeyPurpose[ACTION_KEY] = 1; + } function _execute( address _to, @@ -478,7 +485,7 @@ contract Identity is ERC725, ERC735 { uint256 _purpose, uint256 _type ) - internal + private { bytes32 keyHash = keccak256(_key, _purpose); diff --git a/contracts/identity/IdentityKernel.sol b/contracts/identity/IdentityKernel.sol index 0f74cc4..f05d2d7 100644 --- a/contracts/identity/IdentityKernel.sol +++ b/contracts/identity/IdentityKernel.sol @@ -6,8 +6,6 @@ import "./Identity.sol"; contract IdentityKernel is InstanceStorage, Identity { function initIdentity(address _caller) external { - require(minimumApprovalsByKeyPurpose[MANAGEMENT_KEY] == 0); - _addKey(bytes32(_caller), MANAGEMENT_KEY, 0); - minimumApprovalsByKeyPurpose[MANAGEMENT_KEY] = 1; + _constructIdentity(_caller); } }