From 5c9070f7dc02dd08de9fe030a901274bb740d72e Mon Sep 17 00:00:00 2001 From: Ricardo Guilherme Schmidt <3esmit@gmail.com> Date: Wed, 28 Feb 2018 01:36:48 -0300 Subject: [PATCH] add upgradable instance factory and needed architecture --- contracts/identity/Identity.sol | 1 + contracts/identity/IdentityFactory.sol | 32 ++++++++++++++++++++++++++ contracts/identity/IdentityKernel.sol | 13 +++++++++++ 3 files changed, 46 insertions(+) create mode 100644 contracts/identity/IdentityFactory.sol create mode 100644 contracts/identity/IdentityKernel.sol diff --git a/contracts/identity/Identity.sol b/contracts/identity/Identity.sol index 27e523f..de89f6d 100644 --- a/contracts/identity/Identity.sol +++ b/contracts/identity/Identity.sol @@ -134,6 +134,7 @@ contract Identity is ERC725, ERC735 { public selfOnly { + require(_minimumApprovals > 0); minimumApprovalsByKeyType[_type] = _minimumApprovals; } diff --git a/contracts/identity/IdentityFactory.sol b/contracts/identity/IdentityFactory.sol new file mode 100644 index 0000000..6da2bf8 --- /dev/null +++ b/contracts/identity/IdentityFactory.sol @@ -0,0 +1,32 @@ +pragma solidity ^0.4.17; + +import "../deploy/Factory.sol"; +import "../deploy/UpdatableInstance.sol"; +import "./IdentityKernel.sol"; + +contract IdentityFactory is Factory { + + event IdentityCreated(address instance); + + function IdentityFactory(bytes _infohash) + Factory(new IdentityKernel(), _infohash) + public + { + + } + + function createIdentity() + external + { + createIdentity(msg.sender); + } + + function createIdentity(address _idOwner) + public + { + IdentityKernel instance = IdentityKernel(new UpdatableInstance(address(latestKernel))); + instance.initIdentity(_idOwner); + IdentityCreated(address(instance)); + } + +} diff --git a/contracts/identity/IdentityKernel.sol b/contracts/identity/IdentityKernel.sol new file mode 100644 index 0000000..7966b8b --- /dev/null +++ b/contracts/identity/IdentityKernel.sol @@ -0,0 +1,13 @@ +pragma solidity ^0.4.17; + +import "../deploy/InstanceStorage.sol"; +import "./Identity.sol"; + +contract IdentityKernel is InstanceStorage, Identity { + + function initIdentity(address _caller) external { + require(minimumApprovalsByKeyType[MANAGEMENT_KEY] == 0); + _addKey(bytes32(_caller), MANAGEMENT_KEY, 0); + minimumApprovalsByKeyType[MANAGEMENT_KEY] = 1; + } +}