文件 1 的 3:Lib_AddressManager.sol
pragma solidity >0.5.0 <0.8.0;
import { Ownable } from "./Lib_Ownable.sol";
contract Lib_AddressManager is Ownable {
event AddressSet(
string _name,
address _newAddress
);
mapping (bytes32 => address) private addresses;
function setAddress(
string memory _name,
address _address
)
public
onlyOwner
{
emit AddressSet(_name, _address);
addresses[_getNameHash(_name)] = _address;
}
function getAddress(
string memory _name
)
public
view
returns (address)
{
return addresses[_getNameHash(_name)];
}
function _getNameHash(
string memory _name
)
internal
pure
returns (
bytes32 _hash
)
{
return keccak256(abi.encodePacked(_name));
}
}
文件 2 的 3:Lib_Ownable.sol
pragma solidity >0.5.0 <0.8.0;
abstract contract Ownable {
address public owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() internal {
owner = msg.sender;
emit OwnershipTransferred(address(0), owner);
}
modifier onlyOwner() {
require(
owner == msg.sender,
"Ownable: caller is not the owner"
);
_;
}
function renounceOwnership()
public
virtual
onlyOwner
{
emit OwnershipTransferred(owner, address(0));
owner = address(0);
}
function transferOwnership(address _newOwner)
public
virtual
onlyOwner
{
require(
_newOwner != address(0),
"Ownable: new owner cannot be the zero address"
);
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
}
文件 3 的 3:Lib_ResolvedDelegateProxy.sol
pragma solidity ^0.7.0;
import { Lib_AddressManager } from "./Lib_AddressManager.sol";
contract Lib_ResolvedDelegateProxy {
mapping(address=>string) private implementationName;
mapping(address=>Lib_AddressManager) private addressManager;
constructor(
address _libAddressManager,
string memory _implementationName
)
{
addressManager[address(this)] = Lib_AddressManager(_libAddressManager);
implementationName[address(this)] = _implementationName;
}
fallback()
external
{
address target = addressManager[address(this)].getAddress((implementationName[address(this)]));
require(
target != address(0),
"Target address must be initialized."
);
(bool success, bytes memory returndata) = target.delegatecall(msg.data);
if (success == true) {
assembly {
return(add(returndata, 0x20), mload(returndata))
}
} else {
assembly {
revert(add(returndata, 0x20), mload(returndata))
}
}
}
}
{
"compilationTarget": {
"contracts/optimistic-ethereum/libraries/resolver/Lib_ResolvedDelegateProxy.sol": "Lib_ResolvedDelegateProxy"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_libAddressManager","type":"address"},{"internalType":"string","name":"_implementationName","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"stateMutability":"nonpayable","type":"fallback"}]