|
@ -5,7 +5,6 @@ contract Forum { |
|
|
//----------------------------------------USER---------------------------------------- |
|
|
//----------------------------------------USER---------------------------------------- |
|
|
struct User { |
|
|
struct User { |
|
|
string username; // TODO: set an upper bound instead of arbitrary string |
|
|
string username; // TODO: set an upper bound instead of arbitrary string |
|
|
OrbitDB orbitdb; |
|
|
|
|
|
uint[] topicIDs; // IDs of the topics the user created |
|
|
uint[] topicIDs; // IDs of the topics the user created |
|
|
uint[] postIDs; // IDs of the posts the user created |
|
|
uint[] postIDs; // IDs of the posts the user created |
|
|
uint timestamp; |
|
|
uint timestamp; |
|
@ -18,15 +17,10 @@ contract Forum { |
|
|
event UserSignedUp(string username, address userAddress); |
|
|
event UserSignedUp(string username, address userAddress); |
|
|
event UsernameUpdated(string newName, string oldName,address userAddress); |
|
|
event UsernameUpdated(string newName, string oldName,address userAddress); |
|
|
|
|
|
|
|
|
function signUp(string memory username, string memory orbitIdentityId, |
|
|
function signUp(string memory username) public returns (bool) { |
|
|
string memory orbitIdentityPublicKey, string memory orbitIdentityPrivateKey, |
|
|
|
|
|
string memory orbitId, string memory orbitPublicKey, string memory orbitPrivateKey, |
|
|
|
|
|
string memory orbitTopicsDB, string memory orbitPostsDB) public returns (bool) { |
|
|
|
|
|
require (!hasUserSignedUp(msg.sender), "User has already signed up."); |
|
|
require (!hasUserSignedUp(msg.sender), "User has already signed up."); |
|
|
require(!isUserNameTaken(username), "Username is already taken."); |
|
|
require(!isUserNameTaken(username), "Username is already taken."); |
|
|
users[msg.sender] = User(username, |
|
|
users[msg.sender] = User(username, |
|
|
OrbitDB(orbitIdentityId, orbitIdentityPublicKey, orbitIdentityPrivateKey, |
|
|
|
|
|
orbitId, orbitPublicKey, orbitPrivateKey, orbitTopicsDB, orbitPostsDB), |
|
|
|
|
|
new uint[](0), new uint[](0), block.timestamp, true); |
|
|
new uint[](0), new uint[](0), block.timestamp, true); |
|
|
userAddresses[username] = msg.sender; |
|
|
userAddresses[username] = msg.sender; |
|
|
emit UserSignedUp(username, msg.sender); |
|
|
emit UserSignedUp(username, msg.sender); |
|
@ -78,82 +72,6 @@ contract Forum { |
|
|
return users[userAddress].timestamp; |
|
|
return users[userAddress].timestamp; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//----------------------------------------OrbitDB---------------------------------------- |
|
|
|
|
|
// TODO: set upper bounds to strings (instead of being of arbitrary length) |
|
|
|
|
|
// TODO: not sure if topicsDB//postsDB are actually needed |
|
|
|
|
|
struct OrbitDB { |
|
|
|
|
|
string identityId; |
|
|
|
|
|
string identityPublicKey; |
|
|
|
|
|
string identityPrivateKey; |
|
|
|
|
|
string orbitId; |
|
|
|
|
|
string orbitPublicKey; |
|
|
|
|
|
string orbitPrivateKey; |
|
|
|
|
|
string topicsDB; |
|
|
|
|
|
string postsDB; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getOrbitIdentityId(address userAddress) public view returns (string memory) { |
|
|
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
|
|
return users[userAddress].orbitdb.identityId; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getOrbitIdentityPublicKey(address userAddress) public view returns (string memory) { |
|
|
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
|
|
return users[userAddress].orbitdb.identityPublicKey; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getOrbitIdentityPrivateKey(address userAddress) public view returns (string memory) { |
|
|
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
|
|
return users[userAddress].orbitdb.identityPrivateKey; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getOrbitDBId(address userAddress) public view returns (string memory) { |
|
|
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
|
|
return users[userAddress].orbitdb.orbitId; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getOrbitPublicKey(address userAddress) public view returns (string memory) { |
|
|
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
|
|
return users[userAddress].orbitdb.orbitPublicKey; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO: encrypt using Metamask in the future |
|
|
|
|
|
function getOrbitPrivateKey(address userAddress) public view returns (string memory) { |
|
|
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
|
|
return users[userAddress].orbitdb.orbitPrivateKey; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getOrbitTopicsDB(address userAddress) public view returns (string memory) { |
|
|
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
|
|
return users[userAddress].orbitdb.topicsDB; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getOrbitPostsDB(address userAddress) public view returns (string memory) { |
|
|
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
|
|
return users[userAddress].orbitdb.postsDB; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getOrbitDBInfo(address userAddress) public view returns (string memory, string memory, |
|
|
|
|
|
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 |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------POSTING---------------------------------------- |
|
|
//----------------------------------------POSTING---------------------------------------- |
|
|
struct Topic { |
|
|
struct Topic { |
|
@ -211,10 +129,10 @@ contract Forum { |
|
|
return numTopics; |
|
|
return numTopics; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function getTopic(uint topicID) public view returns (string memory, address, string memory, uint, uint[] memory) { |
|
|
function getTopic(uint topicID) public view returns (address, string memory, uint, uint[] memory) { |
|
|
//require(hasUserSignedUp(msg.sender)); needed? |
|
|
//require(hasUserSignedUp(msg.sender)); needed? |
|
|
require(topicID<numTopics); |
|
|
require(topicID<numTopics); |
|
|
return (getOrbitTopicsDB(topics[topicID].author), |
|
|
return ( |
|
|
topics[topicID].author, |
|
|
topics[topicID].author, |
|
|
users[topics[topicID].author].username, |
|
|
users[topics[topicID].author].username, |
|
|
topics[topicID].timestamp, |
|
|
topics[topicID].timestamp, |
|
@ -227,10 +145,10 @@ contract Forum { |
|
|
return topics[topicID].postIDs; |
|
|
return topics[topicID].postIDs; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function getPost(uint postID) public view returns (string memory, address, string memory, uint, uint) { |
|
|
function getPost(uint postID) public view returns (address, string memory, uint, uint) { |
|
|
//require(hasUserSignedUp(msg.sender)); needed? |
|
|
//require(hasUserSignedUp(msg.sender)); needed? |
|
|
require(postID<numPosts); |
|
|
require(postID<numPosts); |
|
|
return (getOrbitPostsDB(posts[postID].author), |
|
|
return ( |
|
|
posts[postID].author, |
|
|
posts[postID].author, |
|
|
users[posts[postID].author].username, |
|
|
users[posts[postID].author].username, |
|
|
posts[postID].timestamp, |
|
|
posts[postID].timestamp, |
|
|