github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/contracts/statute/src/statute.sol (about) 1 pragma solidity >=0.5.0 <=0.5.3; 2 3 contract Owned { 4 5 /// `owner` is the only address that can call a function with this 6 /// modifier 7 modifier onlyOwner() { 8 require(msg.sender == owner); 9 _; 10 } 11 12 address public owner; 13 14 /// @notice The Constructor assigns the message sender to be `owner` 15 constructor() public { 16 owner = msg.sender; 17 } 18 19 address newOwner = address(0); 20 21 event OwnerUpdate(address _prevOwner, address _newOwner); 22 23 ///change the owner 24 function changeOwner(address _newOwner) public onlyOwner { 25 require(_newOwner != owner); 26 newOwner = _newOwner; 27 } 28 29 /// accept the ownership 30 function acceptOwnership() public { 31 require(msg.sender == newOwner); 32 emit OwnerUpdate(owner, newOwner); 33 owner = newOwner; 34 newOwner = address(0); 35 } 36 } 37 38 39 contract MeshBox is Owned { 40 41 mapping(address => uint256) meshboxAddress; 42 43 address[] meshboxList; 44 45 function addAddress(address[] memory _owners, uint256 version) public onlyOwner() { 46 uint len = _owners.length; 47 for (uint i = 0; i < len; i ++) { 48 address _o = _owners[i]; 49 if (meshboxAddress[_o] == 0) { 50 meshboxList.push(_o); 51 } 52 meshboxAddress[_o] = version; 53 } 54 } 55 56 function getMeshboxList() view public returns (address[] memory) { 57 return meshboxList; 58 } 59 60 61 function cleanMeshboxList(address addr) private { 62 meshboxAddress[addr] = 0; 63 for (uint i=0;i<meshboxList.length;i++) { 64 if (meshboxList[i] == addr) { 65 for (uint j=i;j<meshboxList.length-1;j++) { 66 meshboxList[j] = meshboxList[j+1]; 67 } 68 i--; 69 meshboxList.length -= 1; 70 } 71 } 72 } 73 74 function delAddress(address[] memory _owners) public onlyOwner() { 75 uint len = _owners.length; 76 for (uint i = 0; i < len; i ++) { 77 cleanMeshboxList(_owners[i]); 78 } 79 } 80 81 function existAddress(address _owner) view public returns (uint256){ 82 return meshboxAddress[_owner]; 83 } 84 } 85 86 87 // Address and nodeid mapping 88 // used for reward txfee 89 contract Anmap is MeshBox { 90 91 mapping(address => address[]) anmap; 92 mapping(address => address) namap; 93 94 //"0x70aEfe8d97EF5984B91b5169418f3db283F65a29",28,"0xa006360ed68f21443221354903f49dce733afaaeac3b35d420bb2154746c9592","0x6f31ccfa10b449531fd0fff78db52cc02edaabd2c5e9a6abb8fc1cd6df26f442" 95 function bind(address nodePub, uint8 v, bytes32 r, bytes32 s) public { 96 97 bytes32 hash = keccak256(abi.encodePacked(msg.sender)); 98 address signer = ecrecover(hash,v,r,s); 99 100 require(nodePub == signer); 101 //require(anmap[msg.sender] == address(0)); 102 require(namap[nodePub] == address(0)); 103 104 //anmap[msg.sender] = nodePub; 105 namap[signer] = msg.sender; 106 107 anmap[msg.sender].push(signer); 108 109 } 110 111 function unbindBySig(address nodePub, uint8 v, bytes32 r, bytes32 s) public { 112 bytes32 hash = keccak256(abi.encodePacked(msg.sender)); 113 address signer = ecrecover(hash,v,r,s); 114 require(nodePub == signer); 115 address addr = namap[signer]; 116 require(addr != address(0)); 117 delete namap[signer]; 118 if (anmap[addr].length < 2) { 119 delete anmap[addr]; 120 }else{ 121 for (uint i=0;i<anmap[addr].length;i++) { 122 if (anmap[addr][i] == signer ){ 123 for ( uint j = i;j<anmap[addr].length-1;j++ ){ 124 anmap[addr][j] = anmap[addr][j+1]; 125 } 126 anmap[addr].length -= 1; 127 break; 128 } 129 } 130 } 131 } 132 133 function bindInfo(address addr) view public returns(address from, address[] memory nids) { 134 from = namap[addr]; 135 if (from == address(0)) { 136 from = addr; 137 nids = anmap[addr]; 138 }else{ 139 nids = new address[](1); 140 nids[0] = addr; 141 } 142 } 143 144 }