pragma solidity >=0.4.24; contract UserList { struct User { address _address; string userName; } User[] public userList; event AddNew(address indexed who, string what); function addUser(string memory userName) public { if (!checkUser(userName)){ userList.push(User(msg.sender, userName)); emit AddNew(msg.sender, userName); } } function getUserName(address varAddress) view public returns(string){ for (uint i = 0; i < userList.length; i ++) { if (userList[i]._address == varAddress) { return userList[i].userName; } } } function checkUser(string memory _userName) view public returns(bool){ for (uint i = 0; i < userList.length; i ++) { if (keccak256(userList[i].userName) == keccak256(_userName)) { return true; } } } function count() view public returns(uint){ return userList.length; } }
0.4.25