diff --git a/app/src/config/drizzleOptions.js b/app/src/config/drizzleOptions.js index ce31144..fa0b853 100644 --- a/app/src/config/drizzleOptions.js +++ b/app/src/config/drizzleOptions.js @@ -1,4 +1,5 @@ import Forum from '../contracts/Forum.json'; +import Posting from '../contracts/Posting.json'; const drizzleOptions = { web3: { @@ -7,9 +8,10 @@ const drizzleOptions = { url: 'ws://127.0.0.1:9545' } }, - contracts: [Forum], + contracts: [Forum, Posting], events: { - Forum: ['UserSignedUp', 'UsernameUpdated', 'TopicCreated', 'PostCreated'] + Forum: ['UserSignedUp', 'UsernameUpdated'], + Posting: ['TopicCreated', 'PostCreated'] }, polls: { accounts: 2000, diff --git a/app/src/containers/BoardContainer.js b/app/src/containers/BoardContainer.js index 49b1395..8486ce0 100644 --- a/app/src/containers/BoardContainer.js +++ b/app/src/containers/BoardContainer.js @@ -11,7 +11,7 @@ import FloatingButton from '../components/FloatingButton'; /* import { showProgressBar, hideProgressBar } from '../redux/actions/userInterfaceActions'; */ -const contract = 'Forum'; +const contract = 'Posting'; const getNumberOfTopicsMethod = 'getNumberOfTopics'; class BoardContainer extends Component { diff --git a/contracts/Forum.sol b/contracts/Forum.sol index add5f3c..b8b75b7 100644 --- a/contracts/Forum.sol +++ b/contracts/Forum.sol @@ -1,6 +1,14 @@ pragma solidity >=0.5.6 <0.6.0; +import "./Posting.sol"; + contract Forum { + Posting posting; + + constructor(address addr) public { + posting = Posting(addr); + posting.setForumContractAddress(); + } //----------------------------------------USER---------------------------------------- struct User { @@ -137,9 +145,9 @@ contract Forum { function getOrbitIdentityInfo(address userAddress) public view returns (string memory, string memory, string memory) { require (hasUserSignedUp(userAddress), "User hasn't signed up."); return ( - users[userAddress].orbitdb.identityId, - users[userAddress].orbitdb.identityPublicKey, - users[userAddress].orbitdb.identityPrivateKey + users[userAddress].orbitdb.identityId, + users[userAddress].orbitdb.identityPublicKey, + users[userAddress].orbitdb.identityPrivateKey ); } @@ -147,94 +155,49 @@ contract Forum { string memory, string memory, string memory) { require (hasUserSignedUp(userAddress), "User hasn't signed up."); return ( - users[userAddress].orbitdb.orbitId, - users[userAddress].orbitdb.orbitPublicKey, - users[userAddress].orbitdb.orbitPrivateKey, - users[userAddress].orbitdb.topicsDB, - users[userAddress].orbitdb.postsDB + users[userAddress].orbitdb.orbitId, + users[userAddress].orbitdb.orbitPublicKey, + users[userAddress].orbitdb.orbitPrivateKey, + users[userAddress].orbitdb.topicsDB, + users[userAddress].orbitdb.postsDB ); } - //----------------------------------------POSTING---------------------------------------- - 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); + //----POSTING----- function createTopic() public returns (uint, uint) { require(hasUserSignedUp(msg.sender)); // Only registered users can create topics - //Creates topic - uint topicID = numTopics++; - topics[topicID] = Topic(topicID, msg.sender, block.timestamp, new uint[](0)); + (uint topicID, uint postID) = posting.createTopic(msg.sender); users[msg.sender].topicIDs.push(topicID); - - //Adds first post to topic - uint postID = numPosts++; - posts[postID] = Post(postID, msg.sender, block.timestamp, topicID); - topics[topicID].postIDs.push(postID); users[msg.sender].postIDs.push(postID); - - emit TopicCreated(topicID, postID); return (topicID, postID); } function createPost(uint topicID) public returns (uint) { require(hasUserSignedUp(msg.sender)); // Only registered users can create posts - require(topicID=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