File size: 2,068 Bytes
dec6d5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
pragma solidity ^0.4.18;
contract Proxy {
function implementation() public view returns (address);
function () payable public {
address impl = implementation();
require(impl != address(0));
bytes memory data = msg.data;
assembly {
let result := delegatecall(gas, impl, add(data, 0x20), mload(data), 0, 0)
let size := returndatasize
let ptr := mload(0x40)
returndatacopy(ptr, 0, size)
}
}
}
contract Ownable {
address[] public owners;
event OwnerAdded(address indexed authorizer, address indexed newOwner, uint256 index);
event OwnerRemoved(address indexed authorizer, address indexed oldOwner);
function Ownable() public {
owners.push(msg.sender);
OwnerAdded(0x0, msg.sender, 0);
}
modifier onlyOwner() {
bool isOwner = false;
for (uint256 i = 0; i < owners.length; i++) {
if (msg.sender == owners[i]) {
isOwner = true;
break;
}
}
require(isOwner);
_;
}
function addOwner(address newOwner) onlyOwner public {
require(newOwner != address(0));
uint256 i = owners.push(newOwner) - 1;
OwnerAdded(msg.sender, newOwner, i);
}
function removeOwner(uint256 index) onlyOwner public {
address owner = owners[index];
owners[index] = owners[owners.length - 1];
delete owners[owners.length - 1];
OwnerRemoved(msg.sender, owner);
}
function ownersCount() constant public returns (uint256) {
return owners.length;
}
}
contract UpgradableStorage is Ownable {
address internal _implementation;
event NewImplementation(address implementation);
function implementation() public view returns (address) {
return _implementation;
}
}
contract Upgradable is UpgradableStorage {
function initialize() public payable { }
}
contract KnowledgeProxy is Proxy, UpgradableStorage {
function upgradeTo(address imp) onlyOwner public payable {
_implementation = imp;
Upgradable(this).initialize.value(msg.value)();
NewImplementation(imp);
}
} |