pragma solidity >=0.4.25; contract UserList { struct User { address _address; string userName; } User[] public userList; event AddNew(address indexed who, string what); function add(string memory userName) public { if (!checkUser(userName)){ userList.push(User(msg.sender, userName)); emit AddNew(msg.sender, 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