github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/contracts/statute/src/anmap.sol (about) 1 pragma solidity >=0.5.0 <=0.5.3; 2 3 // Address and nodeid mapping 4 // used for reward txfee 5 contract Anmap { 6 7 mapping(address => address[]) anmap; 8 mapping(address => address) namap; 9 10 //"0x70aEfe8d97EF5984B91b5169418f3db283F65a29",28,"0xa006360ed68f21443221354903f49dce733afaaeac3b35d420bb2154746c9592","0x6f31ccfa10b449531fd0fff78db52cc02edaabd2c5e9a6abb8fc1cd6df26f442" 11 function bind(address nodePub, uint8 v, bytes32 r, bytes32 s) public { 12 13 bytes32 hash = keccak256(abi.encodePacked(msg.sender)); 14 address signer = ecrecover(hash, v, r, s); 15 16 require(nodePub == signer); 17 //require(anmap[msg.sender] == address(0)); 18 require(namap[nodePub] == address(0)); 19 20 //anmap[msg.sender] = nodePub; 21 namap[signer] = msg.sender; 22 23 anmap[msg.sender].push(signer); 24 25 } 26 27 function unbindBySig(address nodePub, uint8 v, bytes32 r, bytes32 s) public { 28 bytes32 hash = keccak256(abi.encodePacked(msg.sender)); 29 address signer = ecrecover(hash, v, r, s); 30 require(nodePub == signer); 31 address addr = namap[signer]; 32 require(addr != address(0)); 33 delete namap[signer]; 34 if (anmap[addr].length < 2) { 35 delete anmap[addr]; 36 } else { 37 for (uint i = 0; i < anmap[addr].length; i++) { 38 if (anmap[addr][i] == signer) { 39 for (uint j = i; j < anmap[addr].length - 1; j++) { 40 anmap[addr][j] = anmap[addr][j + 1]; 41 } 42 anmap[addr].length -= 1; 43 break; 44 } 45 } 46 } 47 } 48 49 function bindInfo(address addr) view public returns (address from, address[] memory nids) { 50 from = namap[addr]; 51 if (from == address(0)) { 52 from = addr; 53 nids = anmap[addr]; 54 } else { 55 nids = new address[](1); 56 nids[0] = addr; 57 } 58 } 59 60 }