mirror of https://gitlab.com/ecentrics/concordia
Ezerous
6 years ago
5 changed files with 127 additions and 74 deletions
@ -0,0 +1,85 @@ |
|||||
|
pragma solidity >=0.5.6 <0.6.0; |
||||
|
|
||||
|
contract Posting { |
||||
|
address forumContractAddress; |
||||
|
|
||||
|
function setForumContractAddress() public{ |
||||
|
require(forumContractAddress==address(0)); |
||||
|
forumContractAddress = msg.sender; |
||||
|
} |
||||
|
|
||||
|
struct Topic { |
||||
|
uint topicID; |
||||
|
address author; |
||||
|
uint timestamp; |
||||
|
uint[] postIDs; |
||||
|
} |
||||
|
|
||||
|
struct Post { |
||||
|
uint postID; |
||||
|
address author; |
||||
|
uint timestamp; |
||||
|
uint topicID; |
||||
|
} |
||||
|
|
||||
|
uint numTopics; // Total number of topics |
||||
|
uint numPosts; // Total number of posts |
||||
|
|
||||
|
mapping (uint => Topic) topics; |
||||
|
mapping (uint => Post) posts; |
||||
|
|
||||
|
event TopicCreated(uint topicID, uint postID); |
||||
|
event PostCreated(uint postID, uint topicID); |
||||
|
|
||||
|
function createTopic(address author) public returns (uint, uint) { |
||||
|
require(msg.sender==forumContractAddress); |
||||
|
//Creates topic |
||||
|
uint topicID = numTopics++; |
||||
|
topics[topicID] = Topic(topicID, author, block.timestamp, new uint[](0)); |
||||
|
|
||||
|
//Adds first post to topic |
||||
|
uint postID = numPosts++; |
||||
|
posts[postID] = Post(postID, author, block.timestamp, topicID); |
||||
|
topics[topicID].postIDs.push(postID); |
||||
|
|
||||
|
emit TopicCreated(topicID, postID); |
||||
|
return (topicID, postID); |
||||
|
} |
||||
|
|
||||
|
function createPost(uint topicID, address author) public returns (uint) { |
||||
|
require(msg.sender==forumContractAddress); |
||||
|
require(topicID<numTopics); // Only allow posting to a topic that exists |
||||
|
uint postID = numPosts++; |
||||
|
posts[postID] = Post(postID, author, block.timestamp, topicID); |
||||
|
topics[topicID].postIDs.push(postID); |
||||
|
emit PostCreated(postID, topicID); |
||||
|
return postID; |
||||
|
} |
||||
|
|
||||
|
function getNumberOfTopics() public view returns (uint) { |
||||
|
return numTopics; |
||||
|
} |
||||
|
|
||||
|
function getTopicInfo(uint topicID) public view returns (address, uint, uint[] memory) { |
||||
|
require(topicID<numTopics); |
||||
|
return (topics[topicID].author, |
||||
|
topics[topicID].timestamp, |
||||
|
topics[topicID].postIDs |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
function getTopicPosts(uint topicID) public view returns (uint[] memory) { |
||||
|
require(topicID<numTopics); // Topic should exist |
||||
|
return topics[topicID].postIDs; |
||||
|
} |
||||
|
|
||||
|
function getPostInfo(uint postID) public view returns (address, uint, uint) { |
||||
|
require(postID<numPosts); |
||||
|
return ( |
||||
|
posts[postID].author, |
||||
|
posts[postID].timestamp, |
||||
|
posts[postID].topicID |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
} |
@ -1,5 +1,8 @@ |
|||||
const Forum = artifacts.require("Forum"); |
const Forum = artifacts.require("Forum"); |
||||
|
const Posting = artifacts.require("Posting"); |
||||
|
|
||||
module.exports = function(deployer) { |
module.exports = function(deployer) { |
||||
deployer.deploy(Forum); |
deployer.deploy(Posting).then(function() { |
||||
}; |
return deployer.deploy(Forum, Posting.address) |
||||
|
}); |
||||
|
}; |
||||
|
Loading…
Reference in new issue