github.com/codingfuture/orig-energi3@v0.8.4/energi/contracts/src/SporkRegistryV1.sol (about)

     1  // Copyright 2019 The Energi Core Authors
     2  // This file is part of Energi Core.
     3  //
     4  // Energi Core is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // Energi Core is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // Energi Governance system is the fundamental part of Energi Core.
    18  
    19  // NOTE: It's not allowed to change the compiler due to byte-to-byte
    20  //       match requirement.
    21  pragma solidity 0.5.16;
    22  //pragma experimental SMTChecker;
    23  
    24  import { GlobalConstants } from "./constants.sol";
    25  import { IGovernedContract, GovernedContract } from "./GovernedContract.sol";
    26  import { IGovernedProxy } from "./IGovernedProxy.sol";
    27  import { IUpgradeProposal } from "./IUpgradeProposal.sol";
    28  import { ISporkRegistry } from "./ISporkRegistry.sol";
    29  import { GenericProposalV1 } from "./GenericProposalV1.sol";
    30  
    31  contract UpgradeProposalV1 is
    32      GenericProposalV1,
    33      IUpgradeProposal
    34  {
    35      IGovernedContract public impl;
    36      address public creator;
    37  
    38      /**
    39       * C-tor
    40       *
    41       * @param _parent - actual parent, but not the caller
    42       * @param _impl - associated contract implementation
    43       * @param _mnregistry_proxy - IMasternodeRegistry proxy
    44       * @param _period - in seconds until deadline
    45       * @param _feePayer - the proposal initiator
    46       */
    47      constructor(
    48          address _parent,
    49          IGovernedContract _impl,
    50          IGovernedProxy _mnregistry_proxy,
    51          uint _period,
    52          address payable _feePayer
    53      )
    54          public
    55          GenericProposalV1(
    56              _mnregistry_proxy,
    57              QUORUM_MAJORITY,
    58              _period,
    59              _feePayer
    60          )
    61      {
    62          creator = msg.sender;
    63          parent = _parent;
    64          impl = _impl;
    65      }
    66  
    67      /**
    68       * Set fee amount by parent
    69       */
    70      function setFee() external payable {
    71          require(msg.sender == creator, "Only parent");
    72          // NOTE: make sure it correctly handles multiple calls
    73          fee_amount += msg.value;
    74      }
    75  }
    76  
    77  /**
    78   * Genesis hardcoded version of SporkRegistry
    79   *
    80   * NOTE: it MUST NOT change after blockchain launch!
    81   */
    82  contract SporkRegistryV1 is
    83      GlobalConstants,
    84      ISporkRegistry,
    85      GovernedContract
    86  {
    87      IGovernedProxy public mnregistry_proxy;
    88  
    89      // IGovernedContract
    90      //---------------------------------
    91      constructor(address _proxy, IGovernedProxy _mnregistry_proxy)
    92          public GovernedContract(_proxy)
    93      {
    94          mnregistry_proxy = _mnregistry_proxy;
    95      }
    96  
    97      // ISporkRegistry
    98      //---------------------------------
    99      function createUpgradeProposal(IGovernedContract _impl, uint _period, address payable _fee_payer)
   100          external payable
   101          returns (IUpgradeProposal proposal)
   102      {
   103          require(msg.value == FEE_UPGRADE_V1, "Invalid fee");
   104          require(_period >= PERIOD_UPGRADE_MIN, "Period min");
   105          require(_period <= PERIOD_UPGRADE_MAX, "Period max");
   106  
   107          proposal = new UpgradeProposalV1(
   108              msg.sender,
   109              _impl,
   110              mnregistry_proxy,
   111              _period,
   112              _fee_payer
   113          );
   114  
   115          proposal.setFee.value(msg.value)();
   116      }
   117  
   118      function consensusGasLimits()
   119          external view
   120          returns(uint callGas, uint xferGas)
   121      {
   122          callGas = 15000000;
   123          xferGas = 30000000;
   124      }
   125  
   126      // Safety
   127      //---------------------------------
   128      function () external payable {
   129          revert("Not supported");
   130      }
   131  }