UserComments.sol
1 pragma solidity 0.4.18; 2 3 4 /// @title User Comments 5 /// @author Mark Beylin <mark.beylin@consensys.net> 6 7 contract UserComments { 8 event CommentAdded(string _comment, address _from, address _to, uint _time); 9 10 struct Comment{ 11 string comment; 12 address from; 13 address to; 14 bool aboutBounty; 15 uint bountyId; 16 uint time; 17 } 18 19 Comment[] public comments; 20 21 modifier isValidCommentIndex(uint i){ 22 require (i < comments.length); 23 _; 24 } 25 26 function addComment(string _comment, address _to, bool _aboutBounty, uint _bountyId) 27 public 28 { 29 if (_aboutBounty){ 30 comments.push(Comment(_comment, msg.sender, address(0), _aboutBounty, _bountyId, block.timestamp)); 31 } else { 32 comments.push(Comment(_comment, msg.sender, _to, _aboutBounty, _bountyId, block.timestamp)); 33 } 34 CommentAdded(_comment, msg.sender, _to, block.timestamp); 35 } 36 37 function numComments() 38 public 39 constant 40 returns (uint){ 41 return comments.length; 42 } 43 44 function getComment(uint _commentId) 45 isValidCommentIndex(_commentId) 46 public 47 constant 48 returns (string, address, address, bool, uint, uint){ 49 return (comments[_commentId].comment, 50 comments[_commentId].from, 51 comments[_commentId].to, 52 comments[_commentId].aboutBounty, 53 comments[_commentId].bountyId, 54 comments[_commentId].time); 55 } 56 }