Guest User

Untitled

a guest
Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. pragma solidity ^0.4.24;
  2.  
  3.  
  4. contract _useful {
  5. mapping (address => bool) public owners;
  6.  
  7. address[] deployed;
  8.  
  9. event Deployed(address d);
  10. event SD();
  11.  
  12. modifier oo {
  13. require(owners[msg.sender]);
  14. _;
  15. }
  16.  
  17. constructor() public payable {
  18. owners[msg.sender] = true;
  19. }
  20.  
  21. function() payable public {}
  22.  
  23. function addOwner(address o) external oo {
  24. owners[o] = true;
  25. }
  26.  
  27. function deploy(bytes _code) public oo returns (address d) {
  28. assembly {
  29. d := create(0, add(_code, 0x20), mload(_code))
  30. if iszero(extcodesize(d)) { revert(0x00, 0x00) }
  31. }
  32.  
  33. // bytes4 addOwnerSig = mkSig("addOwner(address)");
  34. // let's only deploy _useful contracts
  35. _useful(d).addOwner(msg.sender);
  36. deployed.push(d);
  37. emit Deployed(d);
  38. }
  39.  
  40. function destroy() external oo {
  41. bytes4 dSig = mkSig("destroy()");
  42. for (uint i = 0; i < deployed.length; i++) {
  43. deployed[i].call(dSig);
  44. }
  45. sd();
  46. }
  47.  
  48. function sd() public oo {
  49. emit SD();
  50. selfdestruct(msg.sender);
  51. }
  52.  
  53. function mkSig(string s) internal returns (bytes4) {
  54. return bytes4(keccak256(abi.encodePacked(s)));
  55. }
  56.  
  57. function amIOwner() external view returns (bool) {
  58. return owners[msg.sender];
  59. }
  60. }
  61.  
  62. contract Root is _useful {
  63. function deployForBaseGame(address baseGame, bytes _code) external oo returns (address) {
  64. address d = deploy(_code);
  65. BaseGame(baseGame).addAuthorizedWallet(d);
  66. }
  67. }
  68.  
  69. contract BaseGame{
  70. uint256 public contractBalance;
  71. function addAuthorizedWallet(address _wallet) external;
  72. }
Add Comment
Please, Sign In to add comment