文件 1 的 3:EvaverseTurtle.sol
pragma solidity ^0.8.0;
import "./Proxy.sol";
contract EvaverseTurtle is Proxy {
constructor (address logicAddress) {
_delegateAddress = logicAddress;
}
}
文件 2 的 3:Ownable.sol
pragma solidity ^0.8.0;
abstract contract Ownable {
address internal _owner;
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == msg.sender, "Ownable: caller is not the owner");
_;
}
constructor () {
_owner = msg.sender;
}
function SetOwner(address newOwner) external onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_owner = newOwner;
}
}
文件 3 的 3:Proxy.sol
pragma solidity ^0.8.0;
import "./Ownable.sol";
abstract contract Proxy is Ownable {
address internal _delegateAddress;
function GetLogic() external view onlyOwner returns (address) {
return _delegateAddress;
}
function SetLogic(address delegate) external onlyOwner {
_delegateAddress = delegate;
}
fallback () external payable {
_delegate(_delegateAddress);
}
receive () external payable {
_delegate(_delegateAddress);
}
function _delegate(address implementation) internal {
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 { revert(0, returndatasize()) }
default { return(0, returndatasize()) }
}
}
}
abstract contract ProxyTarget is Ownable {
address internal _delegateAddress;
function GetLogicContract() external view onlyOwner returns (address) {
return _delegateAddress;
}
}
{
"compilationTarget": {
"EvaverseTurtle.sol": "EvaverseTurtle"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"logicAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"GetLogic","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegate","type":"address"}],"name":"SetLogic","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"SetOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]