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
| contract TextContract1{ address public owner=msg.sender; function setOwner(address _owner)public{ require(msg.sender==owner,"not owner"); owner=_owner; } }
contract TestContract2{ address public owner=msg.sender; uint public value=msg.value; uint public x; uint public y; constructor(uint _x,uint _y){ x=_x; y=_y; } }
contract Proxy{ event Deploy(address); function deploy(bytes memory _code)external payable returns(address addr){ assembly{ addr :=create(callvalue(),add(_code,0x20),mload(_code)) } require(addr!=address(0),"deploy failed"); emit Deploy(addr); } function execute(address _target,bytes memory _date)external payable{ (bool success, )=_target.call{value:msg.value}(_date); require(success,"failed"); } }
contract Helper{ function getBytecode1()external pure returns(bytes memory){ bytes memory bytecode=type(TestContract1).creationCode; return bytecode; 没有构造函数时用此方法获得bytecode; } function getBytecode2(uint _x,uint _y)external pure returns(bytes memory){ bytes memory bytecode=type(TestContract2).creationCode; return abi.encodePacked(bytecode,abi.encode(_x,_y)); } function getCalldate(address _owner)external pure returns(bytes memory){ return abi.encodeWithSignature("setOwner(address)",_owner); } }
|