github.com/cwntr/go-defi@v0.0.0-20210629134751-07f9ec2f7e66/contracts/Registry.sol (about)

     1  pragma solidity 0.5.16;
     2  
     3  contract Context {
     4      // Empty internal constructor, to prevent people from mistakenly deploying
     5      // an instance of this contract, which should be used via inheritance.
     6      constructor () internal { }
     7      // solhint-disable-previous-line no-empty-blocks
     8  
     9      function _msgSender() internal view returns (address payable) {
    10          return msg.sender;
    11      }
    12  
    13      function _msgData() internal view returns (bytes memory) {
    14          // silence state mutability warning without generating bytecode - 
    15          // see https://github.com/ethereum/solidity/issues/2691
    16          this;
    17          return msg.data;
    18      }
    19  }
    20  
    21  contract Ownable is Context {
    22      address private _owner;
    23  
    24      event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    25  
    26      /**
    27       * @dev Initializes the contract setting the deployer as the initial owner.
    28       */
    29      constructor () internal {
    30          address msgSender = _msgSender();
    31          _owner = msgSender;
    32          emit OwnershipTransferred(address(0), msgSender);
    33      }
    34  
    35      /**
    36       * @dev Returns the address of the current owner.
    37       */
    38      function owner() public view returns (address) {
    39          return _owner;
    40      }
    41  
    42      /**
    43       * @dev Throws if called by any account other than the owner.
    44       */
    45      modifier onlyOwner() {
    46          require(isOwner(), "Ownable: caller is not the owner");
    47          _;
    48      }
    49  
    50      /**
    51       * @dev Returns true if the caller is the current owner.
    52       */
    53      function isOwner() public view returns (bool) {
    54          return _msgSender() == _owner;
    55      }
    56  
    57      /**
    58       * @dev Leaves the contract without owner. It will not be possible to call
    59       * `onlyOwner` functions anymore. Can only be called by the current owner.
    60       *
    61       * NOTE: Renouncing ownership will leave the contract without an owner,
    62       * thereby removing any functionality that is only available to the owner.
    63       */
    64      function renounceOwnership() public onlyOwner {
    65          emit OwnershipTransferred(_owner, address(0));
    66          _owner = address(0);
    67      }
    68  
    69      /**
    70       * @dev Transfers ownership of the contract to a new account (`newOwner`).
    71       * Can only be called by the current owner.
    72       */
    73      function transferOwnership(address newOwner) public onlyOwner {
    74          _transferOwnership(newOwner);
    75      }
    76  
    77      /**
    78       * @dev Transfers ownership of the contract to a new account (`newOwner`).
    79       */
    80      function _transferOwnership(address newOwner) internal {
    81          require(newOwner != address(0), "Ownable: new owner is the zero address");
    82          emit OwnershipTransferred(_owner, newOwner);
    83          _owner = newOwner;
    84      }
    85  }
    86  
    87  contract Registry is Ownable {
    88      mapping(address => bytes32) handlers;
    89  
    90      bytes32 constant DEPRECATED = bytes10(0x64657072656361746564);
    91  
    92      function register(address registration, bytes32 info) external onlyOwner {
    93          require(registration != address(0), "zero address");
    94          require(handlers[registration] == bytes32(0), "registered");
    95          handlers[registration] = info;
    96      }
    97  
    98      function unregister(address registration) external onlyOwner {
    99          require(registration != address(0), "zero address");
   100          require(handlers[registration] != bytes32(0), "no registration");
   101          require(handlers[registration] != DEPRECATED, "unregistered");
   102          handlers[registration] = DEPRECATED;
   103      }
   104  
   105      function isValid(address handler) external view returns (bool result) {
   106          if (handlers[handler] == 0 || handlers[handler] == DEPRECATED)
   107              return false;
   108          else
   109              return true;
   110      }
   111  
   112      function getInfo(address handler) external view returns (bytes32 info) {
   113          return handlers[handler];
   114      }
   115  }