//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.25; contract UserManagerContract { struct User { address userAddr; string userName; } mapping (address => User) public userList; string [] public userNameList; function registerUser (string _userName) public { if (!isUserAddExisted (msg.sender) && !isUserNameExisted(_userName)) { userList[msg.sender] = User(msg.sender,_userName); userNameList.push(_userName); } } function isUserAddExisted(address _userAddr) constant public returns (bool) { return userList[_userAddr].userAddr == _userAddr; } function isUserNameExisted(string _userName) constant public returns (bool) { uint length = userNameList.length; for (uint i = 0; i < length; i++) { if (equal(userNameList[i], _userName)) { return true; } } return false; } function compare(string _a, string _b) internal pure returns (int) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) minLength = b.length; //@todo unroll the loop into increments of 32 and do full 32 byte comparisons for (uint i = 0; i < minLength; i ++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.length < b.length) return -1; else if (a.length > b.length) return 1; else return 0; } /// @dev Compares two strings and returns true iff they are equal. function equal(string _a, string _b) internal pure returns (bool) { return compare(_a, _b) == 0; } } interface userChat { function isUserAddExisted(address _userAddress) external constant returns(bool); } contract ChatContract { struct Mesg { address userAddr; string mesg; } userChat public userChatList; Mesg [] public conversation; address public admin; // Constructor constructor () public { admin = msg.sender; } event SendMesg(address indexed _userAddr, string _mesg); function sendMesg(string _mesg) public{ require(userChatList.isUserAddExisted(msg.sender)); conversation.push(Mesg(msg.sender, _mesg)); } function setUserChatListAddress(userChat _userChatList) public { require(msg.sender == admin); userChatList = _userChatList; } function getMesg() view public returns ( address [] _userAddr, string _mesg) { require(userChatList.isUserAddExisted(msg.sender)); uint length = conversation.length; _userAddr = new address[] (length); bytes memory bmsg; for (uint i = 0; i < length; i++) { _userAddr[i]=conversation[i].userAddr; bmsg = abi.encodePacked(bmsg ,conversation[i].mesg, byte(0)); } return (_userAddr, string(bmsg)); } }
0.4.25