pragma solidity ^0.4.20;
contract MessagingContract {
struct Message {
string data;
string senderName;
}
struct Feed {
Message[] messages;
string name;
}
event FeedCreated(uint256 feedId,string feedName);
event MessageSent(uint256 feedId, uint256 msgId,string msg,string sender);
Feed[] feeds;
/// Create a new ballot with $(_numProposals) different proposals.
function MessagingContract(string firstFeedName) public {
newFeed(firstFeedName);
}
function newFeed(string name) public returns (uint256){
feeds[feeds.length++].name=name;
FeedCreated(feeds.length-1,name);
return feeds.length-1;
}
function feedMessage(uint256 feedId,string data,string alias) public{
feeds[feedId].messages[feeds[feedId].messages.length++]=Message(data,alias);
MessageSent(feedId,feeds[feedId].messages.length-1,data,alias);
}
}
{
"compilationTarget": {
"MessagingContract.sol": "MessagingContract"
},
"libraries": {},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"constant":false,"inputs":[{"name":"feedId","type":"uint256"},{"name":"data","type":"string"},{"name":"alias","type":"string"}],"name":"feedMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"}],"name":"newFeed","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"firstFeedName","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"feedId","type":"uint256"},{"indexed":false,"name":"feedName","type":"string"}],"name":"FeedCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"feedId","type":"uint256"},{"indexed":false,"name":"msgId","type":"uint256"},{"indexed":false,"name":"msg","type":"string"},{"indexed":false,"name":"sender","type":"string"}],"name":"MessageSent","type":"event"}]