pragma solidity ^0.5.0; contract Decentragram { string public name; uint public questionCount=0; uint public modelCount=0; mapping(uint => Question) public question; mapping(uint => Model) public model; mapping(uint => mapping(address => bool)) public voter; //mapping(uint => uint) public linkModelQuestion; struct Question { string text; // for question uint id; string hash; //for csv file dataset address payable author; } struct Model{ uint id; //uint qId; uint vote; string hash; string description; string quesModelId; address payable author; } event QuestionCreated( uint id, string hash, string text, address payable author ); event ModelCreated( uint id, //uint qId, uint vote, string hash, string description, string quesModelId, address payable author ); event Voting( uint id, string hash, string description, uint vote ); constructor() public { name="Decentragram"; } function questionAsked(string memory _questionHash, string memory _text) public { require(bytes(_questionHash).length>0); require(bytes(_text).length>0); require(msg.sender!=address(0)); questionCount++; question[questionCount].id=questionCount; question[questionCount].hash=_questionHash; question[questionCount].text=_text; question[questionCount].author=msg.sender; emit QuestionCreated(questionCount, _questionHash, _text, msg.sender); } function uploadModels(string memory _modelHash, string memory _description, string memory _quesModelId) public { require(bytes(_modelHash).length>0); require(bytes(_description).length>0); require(msg.sender!=address(0)); modelCount++; uint vote = 0; model[modelCount].id=modelCount; model[modelCount].hash=_modelHash; model[modelCount].description=_description; model[modelCount].quesModelId=_quesModelId; model[modelCount].author=msg.sender; emit ModelCreated(modelCount, vote, _modelHash, _description, _quesModelId, msg.sender); } function voting(uint _id) public { // Make sure model id is valid require(_id > 0 && _id <= modelCount); require(msg.sender!=model[_id].author,"can not vote your own model"); require(!voter[_id][msg.sender],"can not vote twice"); voter[_id][msg.sender]=true; // Fetch the model Model memory _model = model[_id]; model[_id].vote++; emit Voting(_id, model[_id].hash, model[_id].description, model[_id].vote); } }
0.4.18