智能合约与区块链的结合形成了智能合约法规自动执行系统,该系统有三个重要的原则:
首先,智能合约数据来源于链上。这是指智能合约的输入是从区块链的数据库里面出来的。这些数据是由区块链保证的,具有真实难以篡改的特征。
其次,智能合约的执行在链上。这是指智能合约是在多个节点上面执行,而所执行的结果必须是相同,智能合约所出的结果一定要被共识才能被接受。
再者,智能合约输出在链上。这是指智能合约的输出结果必须存在区块链上面,这样保证结果的真实与可追溯性,并且为其他相衔接的智能合约提供输入数据的准确性保障。
File 1 of 4: OwnedUpgradeabilityProxy.sol
pragma solidity ^0.4.24;
import './UpgradeabilityProxy.sol';
/**
- @title OwnedUpgradeabilityProxy
- @dev This contract combines an upgradeability proxy with basic authorization control functionalities
*/
contract OwnedUpgradeabilityProxy is UpgradeabilityProxy {
/**
- @dev Event to show ownership has been transferred
- @param previousOwner representing the address of the previous owner
- @param newOwner representing the address of the new owner
*/
event ProxyOwnershipTransferred(address previousOwner, address newOwner);
// Storage position of the owner of the contract
bytes32 private constant proxyOwnerPosition = keccak256("org.zeppelinos.proxy.owner");
/**
- @dev the constructor sets the original owner of the contract to the sender account.
*/
constructor() public {
setUpgradeabilityOwner(msg.sender);
}
/**
- @dev Throws if called by any account other than the owner.
*/
modifier onlyProxyOwner() {
require(msg.sender == proxyOwner());
_;
}
/**
- @dev Tells the address of the owner
- @return the address of the owner
*/
function proxyOwner() public view returns (address owner) {
bytes32 position = proxyOwnerPosition;
assembly {
owner := sload(position)
}
}
/**
- @dev Sets the address of the owner
*/
function setUpgradeabilityOwner(address newProxyOwner) internal {
bytes32 position = proxyOwnerPosition;
assembly {
sstore(position, newProxyOwner)
}
}
/**
- @dev Allows the current owner to transfer control of the contract to a newOwner.
- @param newOwner The address to transfer ownership to.
*/
function transferProxyOwnership(address newOwner) public onlyProxyOwner {
require(newOwner != address(0));
emit ProxyOwnershipTransferred(proxyOwner(), newOwner);
setUpgradeabilityOwner(newOwner);
}
/**
- @dev Allows the proxy owner to upgrade the current version of the proxy.
- @param implementation representing the address of the new implementation to be set.
*/
function upgradeTo(address implementation) public onlyProxyOwner {
_upgradeTo(implementation);
}
/**
- @dev Allows the proxy owner to upgrade the current version of the proxy and call the new implementation
- to initialize whatever is needed through a low level call.
- @param implementation representing the address of the new implementation to be set.
- @param data represents the msg.data to bet sent in the low level call. This parameter may include the function
- signature of the implementation to be called with the needed payload
*/
function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner {
upgradeTo(implementation);
require(implementation.delegatecall(data));
}
}