Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. pragma solidity >=0.5.2;
  2.  
  3. import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-solidity/master/contracts/ownership/Ownable.sol";
  4.  
  5. contract P2POwnable is Ownable {
  6. uint constant BLOCK_EXPIRED_TIME = 5760;
  7. uint constant MOVE_OWNER_LIMIT = 1e18;
  8.  
  9. mapping(address => uint) public weight;
  10. // request to update weights and protect from
  11. mapping (bytes32 => uint) public weightUpdateRequest;
  12.  
  13.  
  14. event AddWeightUpdateRequest(bytes32 hash);
  15. event RemoveWeightUpdateRequest(bytes32 hash);
  16.  
  17. function addWeightUpdateRequest(bytes32 hash) public onlyOwner returns(bool) {
  18. weightUpdateRequest[hash] = block.number;
  19. emit AddWeightUpdateRequest(hash);
  20. return true;
  21. }
  22.  
  23. function discardWeightUpdateRequest(bytes32 hash) public onlyOwner returns(bool) {
  24. weightUpdateRequest[hash] = 0;
  25. emit RemoveWeightUpdateRequest(hash);
  26. return true;
  27. }
  28.  
  29. function finalizeWeightUpdateRequest(bytes32 hash, address[] memory friends, uint[] memory weights) public onlyOwner returns(bool) {
  30. require(weightUpdateRequest[hash] > 0);
  31. require(weightUpdateRequest[hash] < (block.number - BLOCK_EXPIRED_TIME));
  32. require(friends.length == weights.length);
  33. require(hash == keccak256(abi.encodePacked(friends, weights)));
  34. for (uint i=0; i<friends.length; i++) {
  35. weight[friends[i]] = weights[i];
  36. }
  37. return true;
  38. }
  39.  
  40. function moveOwner(address newOwner, uint blockLimit, address[] memory friends, uint8[] memory v, bytes32[] memory r, bytes32[] memory s) public returns(bool) {
  41. uint n = friends.length;
  42. require((n== v.length) && (n==r.length) &&(n==s.length));
  43. require(blockLimit < block.number);
  44. bytes32 msg = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n52", newOwner, blockLimit));
  45. uint totalWeight = 0;
  46. for (uint i =0; i<n; i++){
  47. require(friends[i] == ecrecover(msg, v[i], r[i], s[i]));
  48. totalWeight+=weight[friends[i]];
  49. }
  50. require(totalWeight>=MOVE_OWNER_LIMIT);
  51. _transferOwnership(newOwner);
  52. return true;
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement