diff --git a/contracts/deploy/Factory.sol b/contracts/deploy/Factory.sol new file mode 100644 index 0000000..f63bf71 --- /dev/null +++ b/contracts/deploy/Factory.sol @@ -0,0 +1,57 @@ +pragma solidity ^0.4.17; + +import "../common/Controlled.sol"; + +contract Factory is Controlled { + + event NewKernel(address newKernel, bytes infohash); + + struct Version { + uint256 blockNumber; + uint256 timestamp; + address kernel; + bytes infohash; + } + mapping (address => uint256) versionMap; + + Version[] versionLog; + uint256 latestUpdate; + address latestKernel; + + function Factory(address _kernel, bytes _infohash) + public + { + _setKernel(_kernel, _infohash); + } + + function setKernel(address _kernel, bytes _infohash) + external + onlyController + { + _setKernel(_kernel, _infohash); + } + + function getVersion(uint256 index) public view + returns(uint256 blockNumber, + uint256 timestamp, + address kernel, + bytes infohash) + { + return (versionLog[index].blockNumber, + versionLog[index].timestamp, + versionLog[index].kernel, + versionLog[index].infohash); + } + + function _setKernel(address _kernel, bytes _infohash) + internal + { + require(_kernel != latestKernel); + versionMap[_kernel] = versionLog.length; + versionLog.push(Version({blockNumber: block.number, timestamp: block.timestamp, kernel: _kernel, infohash: _infohash})); + latestUpdate = block.timestamp; + latestKernel = _kernel; + NewKernel(_kernel, _infohash); + } + +} \ No newline at end of file diff --git a/contracts/deploy/UpdatableInstance.sol b/contracts/deploy/UpdatableInstance.sol index 550df8d..60f6d0a 100644 --- a/contracts/deploy/UpdatableInstance.sol +++ b/contracts/deploy/UpdatableInstance.sol @@ -10,6 +10,8 @@ import "./Instance.sol"; */ contract UpdatableInstance is Instance { + event InstanceUpdated(address oldKernel, address newKernel); + function UpdatableInstance(address _kernel) Instance(_kernel) public @@ -19,6 +21,7 @@ contract UpdatableInstance is Instance { function updateUpdatableInstance(address _kernel) external { require(msg.sender == address(this)); + InstanceUpdated(kernel, _kernel); kernel = _kernel; }