|
|
@ -18,11 +18,15 @@ contract Forum { |
|
|
|
event UserSignedUp(string username, address userAddress); |
|
|
|
event UsernameUpdated(string newName, string oldName,address userAddress); |
|
|
|
|
|
|
|
function signUp(string memory username, string memory orbitDBId, string memory orbitTopicsDB, string memory orbitPostsDB, string memory orbitPublicKey, string memory orbitPrivateKey) public returns (bool) { |
|
|
|
function signUp(string memory username, string memory orbitIdentityId, |
|
|
|
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(!isUserNameTaken(username), "Username is already taken."); |
|
|
|
users[msg.sender] = User(username, |
|
|
|
OrbitDB(orbitDBId,orbitTopicsDB, orbitPostsDB, orbitPublicKey, orbitPrivateKey), |
|
|
|
OrbitDB(orbitIdentityId, orbitIdentityPublicKey, orbitIdentityPrivateKey, |
|
|
|
orbitId, orbitPublicKey, orbitPrivateKey, orbitTopicsDB, orbitPostsDB), |
|
|
|
new uint[](0), new uint[](0), block.timestamp, true); |
|
|
|
userAddresses[username] = msg.sender; |
|
|
|
emit UserSignedUp(username, msg.sender); |
|
|
@ -75,52 +79,81 @@ contract Forum { |
|
|
|
} |
|
|
|
|
|
|
|
//----------------------------------------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 id; // TODO: set an upper bound instead of arbitrary string |
|
|
|
string topicsDB; //TODO: not sure yet which of these are actually needed |
|
|
|
string identityId; |
|
|
|
string identityPublicKey; |
|
|
|
string identityPrivateKey; |
|
|
|
string orbitId; |
|
|
|
string orbitPublicKey; |
|
|
|
string orbitPrivateKey; |
|
|
|
string topicsDB; |
|
|
|
string postsDB; |
|
|
|
string publicKey; |
|
|
|
string privateKey; |
|
|
|
} |
|
|
|
|
|
|
|
function getOrbitIdentityId(address userAddress) public view returns (string memory) { |
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
return users[userAddress].orbitdb.identityId; |
|
|
|
} |
|
|
|
|
|
|
|
function getOrbitDBId(address userAddress) public view returns (string memory) { |
|
|
|
function getOrbitIdentityPublicKey(address userAddress) public view returns (string memory) { |
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
return users[userAddress].orbitdb.id; |
|
|
|
return users[userAddress].orbitdb.identityPublicKey; |
|
|
|
} |
|
|
|
|
|
|
|
function getOrbitTopicsDB(address userAddress) public view returns (string memory) { |
|
|
|
function getOrbitIdentityPrivateKey(address userAddress) public view returns (string memory) { |
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
return users[userAddress].orbitdb.topicsDB; |
|
|
|
return users[userAddress].orbitdb.identityPrivateKey; |
|
|
|
} |
|
|
|
|
|
|
|
function getOrbitPostsDB(address userAddress) public view returns (string memory) { |
|
|
|
|
|
|
|
function getOrbitDBId(address userAddress) public view returns (string memory) { |
|
|
|
require (hasUserSignedUp(userAddress), "User hasn't signed up."); |
|
|
|
return users[userAddress].orbitdb.postsDB; |
|
|
|
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.publicKey; |
|
|
|
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.privateKey; |
|
|
|
return users[userAddress].orbitdb.orbitPrivateKey; |
|
|
|
} |
|
|
|
|
|
|
|
function getOrbitDBInfo(address userAddress) public view returns (string memory, string memory, string memory, string memory, string memory) { |
|
|
|
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.id, |
|
|
|
users[userAddress].orbitdb.topicsDB, |
|
|
|
users[userAddress].orbitdb.postsDB, |
|
|
|
users[userAddress].orbitdb.publicKey, |
|
|
|
users[userAddress].orbitdb.privateKey |
|
|
|
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---------------------------------------- |
|
|
|
struct Topic { |
|
|
|