github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/xc/eth-v1.0.3/README.md (about) 1 # eth-v1.0.3 2 3 ## XC.sol 4 5 * Add modifier: nonzeroAddress(account) 6 ``` 7 function setToken(address account) onlyAdmin nonzeroAddress(account) external { 8 if (token != account) { 9 token = Token(account); 10 } 11 } 12 ``` 13 14 * Add modifier: nonzeroAddress(account) 15 ``` 16 function setXCPlugin(address account) onlyAdmin nonzeroAddress(account) external { 17 if (xcPlugin != account) { 18 xcPlugin = XCPlugin(account); 19 } 20 } 21 ``` 22 23 ## XCPlugin.sol 24 25 * Add modifier: nonzeroAddress(caller) 26 ``` 27 function addCaller(address caller) onlyAdmin nonzeroAddress(caller) external { 28 if (!_existCaller(caller)) { 29 callers.push(caller); 30 } 31 } 32 ``` 33 34 * Add modifier: nonzeroAddress(caller) 35 * Optimize for loop structure, remove extra var 36 ``` 37 function deleteCaller(address caller) onlyAdmin nonzeroAddress(caller) external { 38 for (uint i = 0; i < callers.length; i++) { 39 if (callers[i] == caller) { 40 if (i != callers.length - 1 ) { 41 callers[i] = callers[callers.length - 1]; 42 } 43 callers.length--; 44 return; 45 } 46 } 47 } 48 ``` 49 50 * Optimize for loop structure, remove extra var 51 ``` 52 function bytes32ToStr(bytes32 b) internal pure returns (string) { 53 uint length = b.length; 54 for (uint i = 0; i < b.length; i++) { 55 if (b[b.length - 1 - i] != "") { 56 length -= i; 57 break; 58 } 59 } 60 bytes memory bs = new bytes(length); 61 for (uint j = 0; j < length; j++) { 62 bs[j] = b[j]; 63 } 64 return string(bs); 65 } 66 ``` 67 68 * Modify var: listOfPublicKey => publicKeys 69 ``` 70 function _existPublicKey(address publicKey) internal view returns (bool) { 71 address[] memory publicKeys = platform.publicKeys; 72 for (uint i = 0; i < publicKeys.length; i++) { 73 if (publicKeys[i] == publicKey) { 74 return true; 75 } 76 } 77 return false; 78 } 79 ``` 80 81 * Modify var: listOfPublicKey => publicKeys 82 ``` 83 function addPublicKey(address publicKey) onlyAdmin nonzeroAddress(publicKey) external { 84 address[] storage publicKeys = platform.publicKeys; 85 for (uint i; i < publicKeys.length; i++) { 86 if (publicKey == publicKeys[i]) { 87 return; 88 } 89 } 90 publicKeys.push(publicKey); 91 } 92 ``` 93 94 * The array overbounds problem was fixed 95 * Optimize for loop structure, remove extra var 96 ``` 97 function deletePublicKey(address publicKey) onlyAdmin nonzeroAddress(publicKey) external { 98 address[] storage publicKeys = platform.publicKeys; 99 for (uint i = 0; i < publicKeys.length; i++) { 100 if (publicKeys[i] == publicKey) { 101 if (i != publicKeys.length - 1 ) { 102 publicKeys[i] = publicKeys[publicKeys.length - 1]; 103 } 104 publicKeys.length--; 105 return; 106 } 107 } 108 } 109 ``` 110 111 * Modify var: listOfPublicKey => publicKeys 112 ``` 113 function _existPublicKey(address publicKey) internal view returns (bool) { 114 address[] memory publicKeys = platform.publicKeys; 115 for (uint i = 0; i < publicKeys.length; i++) { 116 if (publicKeys[i] == publicKey) { 117 return true; 118 } 119 } 120 return false; 121 } 122 ``` 123 124 * Optimize for loop structure, remove extra var 125 ``` 126 function changeVoters(address publicKey, string txid) internal { 127 address[] storage voters = platform.proposals[txid].voters; 128 for (uint i = 0; i < voters.length; i++) { 129 if (voters[i] == publicKey) { 130 return; 131 } 132 } 133 voters.push(publicKey); 134 } 135 ```