Guest User

Untitled

a guest
Jan 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. address[] public validatorList = [<your first validator address>];
  2. address[] public pendingList = [<your first validator address>];
  3.  
  4. mapping(address => bool) public isAdmin;
  5.  
  6. modifier onlyAdmin() {
  7. require(isAdmin[msg.sender] == true);
  8. _;
  9. }
  10.  
  11. event validatorAdded(address newvalidator);
  12. event validatorRemoved(address oldvalidator);
  13. event adminAdded(address newadmin);
  14. event adminRemoved(address oldadmin);
  15. event InitiateChange(bytes32 indexed _parent_hash, address[] _new_set);
  16.  
  17. function AdminValidatorList() public {
  18. isAdmin[validatorList[0]] = true;
  19. }
  20.  
  21. // Called on every block to update node validator list.
  22. function getValidators() public constant returns (address[] _validators) {
  23. return validatorList;
  24. }
  25.  
  26. function getPendingValidators() public constant returns (address[] _p) {
  27. return pendingList;
  28. }
  29.  
  30. // Add a validator to the list.
  31. function addValidator(address validator) public onlyAdmin {
  32. for (uint i = 0; i < pendingList.length; i++) {
  33. require(pendingList[i] != validator);
  34. }
  35.  
  36. pendingList.push(validator);
  37. validatorAdded(validator);
  38. InitiateChange(block.blockhash(block.number - 1),pendingList);
  39. }
  40.  
  41. // Remove a validator from the list.
  42. function removeValidator(address validator) public onlyAdmin returns (bool success){
  43.  
  44. uint i=0;
  45. uint count = pendingList.length;
  46. success = false;
  47.  
  48. // you don't want to leave no validators - can't delete any until you have a minimum of 3.
  49. // This is in case your 1 remaining node goes down. Leave a safety margin of 2
  50. if (count > 2) {
  51. for (i=0; i<count;i++) {
  52. if (pendingList[i] == validator) {
  53. if (i < pendingList.length-1) {
  54. pendingList[i] = pendingList[pendingList.length-1];
  55. }
  56. pendingList.length--;
  57. success = true;
  58. validatorRemoved(validator);
  59. InitiateChange(block.blockhash(block.number - 1),pendingList);
  60. break;
  61. }
  62. }
  63. }
  64. return success;
  65. }
  66.  
  67. // Add an admin.
  68. function addAdmin(address admin) public onlyAdmin {
  69. isAdmin[admin] = true;
  70. adminAdded(admin);
  71. }
  72.  
  73. // Remove an admin.
  74. function removeAdmin(address admin) public onlyAdmin {
  75. isAdmin[admin] = false;
  76. adminRemoved(admin);
  77. }
  78.  
  79. function finalizeChange() public {
  80. validatorList = pendingList;
  81. }
Add Comment
Please, Sign In to add comment