Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.24;
- contract _useful {
- mapping (address => bool) public owners;
- address[] deployed;
- event Deployed(address d);
- event SD();
- modifier oo {
- require(owners[msg.sender]);
- _;
- }
- constructor() public payable {
- owners[msg.sender] = true;
- }
- function() payable public {}
- function addOwner(address o) external oo {
- owners[o] = true;
- }
- function deploy(bytes _code) public oo returns (address d) {
- assembly {
- d := create(0, add(_code, 0x20), mload(_code))
- if iszero(extcodesize(d)) { revert(0x00, 0x00) }
- }
- // bytes4 addOwnerSig = mkSig("addOwner(address)");
- // let's only deploy _useful contracts
- _useful(d).addOwner(msg.sender);
- deployed.push(d);
- emit Deployed(d);
- }
- function destroy() external oo {
- bytes4 dSig = mkSig("destroy()");
- for (uint i = 0; i < deployed.length; i++) {
- deployed[i].call(dSig);
- }
- sd();
- }
- function sd() public oo {
- emit SD();
- selfdestruct(msg.sender);
- }
- function mkSig(string s) internal returns (bytes4) {
- return bytes4(keccak256(abi.encodePacked(s)));
- }
- function amIOwner() external view returns (bool) {
- return owners[msg.sender];
- }
- }
- contract Root is _useful {
- function deployForBaseGame(address baseGame, bytes _code) external oo returns (address) {
- address d = deploy(_code);
- BaseGame(baseGame).addAuthorizedWallet(d);
- }
- }
- contract BaseGame{
- uint256 public contractBalance;
- function addAuthorizedWallet(address _wallet) external;
- }
Add Comment
Please, Sign In to add comment