github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/contracts/chief/src/chief_base_s0.5_v0.0.1.sol (about)

     1  pragma solidity >=0.5.0 <=0.5.3;
     2  
     3  /* for remix
     4  import "github.com/SmartMeshFoundation/Spectrum/contracts/chief/src/poc_s0.5.sol"; // for remix
     5  */
     6  
     7  
     8  
     9  /* local */
    10  import "./poc_s0.5.sol";
    11  
    12  contract ChiefBase_1_0_0 {
    13  
    14      string public vsn = "1.0.0";
    15  
    16      POC_1_0_0 private poc;
    17  
    18      address public _owner;
    19      address public _tribe;
    20  
    21      address[] public leaderList;
    22  
    23      modifier owner() {
    24          require(msg.sender == _owner);
    25          _;
    26      }
    27  
    28      //config >>>>
    29      uint public leaderLimit = 5;//5
    30      uint public signerLimit = 3;
    31      uint public epoch = 6171; // block time 14s, 6171 block = 24H
    32      uint public volunteerLimit = signerLimit - 1; //留0号位置给Leader
    33      //只有一次修改pocInitBlockNumber的机会
    34      bool public pocUpdatedInitBlockNumber;
    35      //config <<<<
    36      //function setEpoch(uint _epoch) public payable {epoch = _epoch;}
    37      //function setSignerLimit(uint _signerLimit) public payable {signerLimit = _signerLimit;}
    38  
    39  //    function setLeaderLimit(uint _leaderLimit) public  owner() {leaderLimit = _leaderLimit;}
    40  
    41      function setOwner(address newOwner) public  owner() {_owner = newOwner;}
    42  
    43      function takeEpoch() public view returns (uint) {return epoch;}
    44  
    45      function takeSignerLimit() public view returns (uint) {return signerLimit;}
    46  
    47      function takeLeaderLimit() public view returns (uint) {return leaderLimit;}
    48  
    49      function takeVolunteerLimit() public view returns (uint) {return volunteerLimit;}
    50  
    51      function takeLeaderList() public view returns (address[] memory) {return leaderList;}
    52  
    53      function takeOwner() public view returns (address) {return _owner;}
    54  
    55      constructor(uint _epoch, uint _signerLimit) public {
    56          _owner = msg.sender;
    57          epoch = _epoch;
    58          signerLimit = _signerLimit;
    59          volunteerLimit = signerLimit - 1;
    60          pocUpdatedInitBlockNumber=false;
    61      }
    62  
    63      function appendLeader(address addr) public owner() {
    64          if (leaderList.length < leaderLimit) {
    65              for (uint i = 0; i < leaderList.length; i++) {
    66                  require(leaderList[i] != addr);
    67              }
    68              leaderList.push(addr);
    69          }
    70      }
    71  
    72      function removeLeader(address addr) public owner() {
    73          require(leaderList.length != 1);
    74          for (uint i = 0; i < leaderList.length; i++) {
    75              if (leaderList[i] == addr) {
    76                  for (uint j = i; j < leaderList.length - 1; j++) {
    77                      leaderList[j] = leaderList[j + 1];
    78                  }
    79                  i--;
    80                  leaderList.length -= 1;
    81              }
    82          }
    83      }
    84  
    85      function isLeader(address addr) public view returns (bool) {
    86          for (uint i = 0; i < leaderList.length; i++) {
    87              if (uint160(addr) != uint160(0) && addr == leaderList[i]) {
    88                  return true;
    89              }
    90          }
    91          return false;
    92      }
    93  
    94      function init(address pocAddr, address tribeAddr) public {
    95          require(msg.sender == tribeAddr);
    96          if (address(poc) == address(0) && pocAddr != address(0)) {
    97              poc = POC_1_0_0(pocAddr);
    98          }
    99          if (tribeAddr != address(0) && _tribe==address(0)) {
   100              _tribe = tribeAddr;
   101          }
   102      }
   103      /*
   104      影响奖励减半启用周期,只能调用一次
   105      保证生效块数要在当前块之前,否则会造成poc.minDepositAmount立即降到定额的八分之一
   106      */
   107      function pocSetInitBlockNumber(uint256 num) owner() public{
   108          require(!pocUpdatedInitBlockNumber);
   109          require(num<=block.number);
   110          pocUpdatedInitBlockNumber=true;
   111          poc.ownerSetInitBlockNumber(num);
   112      }
   113      function pocChangeOwner(address newOwner, uint256 num) owner() public {
   114          poc.changeOwner(newOwner, num);
   115      }
   116  
   117      function pocAddStop(address minerAddress) public returns (int8) {
   118          require(msg.sender == _tribe);
   119          return poc.ownerStop(minerAddress);
   120      }
   121  
   122      // chief -> base -> poc : blacklist options >>>>
   123      function pocAddBlackList(address minerAddress) public {
   124          require(msg.sender == _tribe);
   125          poc.ownerPushBlackList(minerAddress);
   126      }
   127  
   128      function pocCleanBlackList()  public{
   129          require(msg.sender == _tribe);
   130          poc.ownerEmptyBlackList();
   131      }
   132  
   133      function pocGetBlackList() public view returns(address[] memory) {
   134          return poc.getBlackList();
   135      }
   136  
   137      function pocAddLockList(address minerAddress) public {
   138          require(msg.sender == _tribe);
   139          poc.ownerPushLockList(minerAddress);
   140      }
   141  
   142      function pocDelLockList(address minerAddress) public returns (int8) {
   143          require(msg.sender == _tribe);
   144          return poc.ownerPopLockList(minerAddress);
   145      }
   146      // chief -> base -> poc : locklist options <<<<
   147  
   148  }