diff --git a/contracts/Forum.sol b/contracts/Forum.sol index 693514b..c91eaa3 100644 --- a/contracts/Forum.sol +++ b/contracts/Forum.sol @@ -5,10 +5,7 @@ contract Forum { //----------------------------------------USER---------------------------------------- struct User { string username; // TODO: set an upper bound instead of arbitrary string - string orbitMainDB; // TODO: set an upper bound instead of arbitrary string - string orbitTopicsDB; - string orbitPostsDB; - + OrbitDB orbitdb; uint[] topicIDs; // IDs of the topics the user created uint[] postIDs; // IDs of the posts the user created bool signedUp; // Helper variable for hasUserSignedUp() @@ -20,10 +17,10 @@ contract Forum { event UserSignedUp(string username, address userAddress); event UsernameUpdated(string newName, string oldName,address userAddress); - function signUp(string username, string orbitMainDB, string orbitTopicsDB, string orbitPostsDB) public returns (bool) { + function signUp(string username, string orbitDBId, string orbitTopicsDB, string orbitPostsDB, string orbitPublicKey, string orbitPrivateKey) public returns (bool) { require (!hasUserSignedUp(msg.sender), "User has already signed up."); require(!isUserNameTaken(username), "Username is already taken."); - users[msg.sender] = User(username, orbitMainDB, orbitTopicsDB, orbitPostsDB, new uint[](0), new uint[](0), true); + users[msg.sender] = User(username, OrbitDB(orbitDBId, orbitTopicsDB, orbitPostsDB, orbitPublicKey, orbitPrivateKey), new uint[](0), new uint[](0), true); userAddresses[username] = msg.sender; emit UserSignedUp(username, msg.sender); return true; @@ -58,17 +55,44 @@ contract Forum { return false; } - function getOrbitMainDB(address userAddress) public view returns (string) { - return users[userAddress].orbitMainDB; + //---------OrbitDB--------- + 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 postsDB; + string publicKey; + string privateKey; + } + + + function getOrbitDBId(address userAddress) public view returns (string) { + require (hasUserSignedUp(userAddress), "User hasn't signed up."); + return users[userAddress].orbitdb.id; } function getOrbitTopicsDB(address userAddress) public view returns (string) { - return users[userAddress].orbitTopicsDB; + require (hasUserSignedUp(userAddress), "User hasn't signed up."); + return users[userAddress].orbitdb.topicsDB; } function getOrbitPostsDB(address userAddress) public view returns (string) { - return users[userAddress].orbitPostsDB; + require (hasUserSignedUp(userAddress), "User hasn't signed up."); + return users[userAddress].orbitdb.postsDB; + } + + function getOrbitPublicKey() public view returns (string) { + require (hasUserSignedUp(msg.sender), "User hasn't signed up."); + return users[msg.sender].orbitdb.publicKey; } + + //TODO: encrypt using Metamask in the future + function getOrbitPrivateKey() public view returns (string) { + require (hasUserSignedUp(msg.sender), "User hasn't signed up."); + return users[msg.sender].orbitdb.privateKey; + } + + + //----------------------------------------POSTING---------------------------------------- struct Topic { uint topicID; diff --git a/src/containers/LoadingContainer.js b/src/containers/LoadingContainer.js index 71720db..4a08b5f 100644 --- a/src/containers/LoadingContainer.js +++ b/src/containers/LoadingContainer.js @@ -20,7 +20,7 @@ class LoadingContainer extends Component {
-

⚠️

+

This browser has no connection to the Ethereum network. Please use the Chrome/FireFox extension MetaMask, or dedicated Ethereum browsers Mist or Parity.

@@ -34,7 +34,7 @@ class LoadingContainer extends Component {
-

🦊

+

🦊

We can't find any Ethereum accounts! Please check and make sure Metamask or you browser are pointed at the correct network and your account is unlocked.

@@ -67,7 +67,7 @@ class LoadingContainer extends Component {
-

⚙️

+

Loading dapp...

diff --git a/src/containers/UsernameFormContainer.js b/src/containers/UsernameFormContainer.js index bf5cdfa..8a4b7ec 100644 --- a/src/containers/UsernameFormContainer.js +++ b/src/containers/UsernameFormContainer.js @@ -25,8 +25,9 @@ class UsernameFormContainer extends Component { this.contracts[contract].methods[updateUsernameMethod].cacheSend(...[this.state.usernameInput]); else { - const orbitdb = await createDatabases(); - this.contracts[contract].methods[signUpMethod].cacheSend(...[this.state.usernameInput, orbitdb.mainDB, orbitdb.topicsDB, orbitdb.postsDB]); + const orbitdbInfo = await createDatabases(); + this.contracts[contract].methods[signUpMethod].cacheSend(...[this.state.usernameInput, orbitdbInfo.id, + orbitdbInfo.topicsDB, orbitdbInfo.postsDB, orbitdbInfo.publicKey, orbitdbInfo.privateKey]); } } diff --git a/src/util/orbit.js b/src/util/orbit.js index 9d9d571..8a13422 100644 --- a/src/util/orbit.js +++ b/src/util/orbit.js @@ -26,7 +26,8 @@ async function createDatabases() { const topicsDB = await orbitdb.keyvalue('topics'); const postsDB = await orbitdb.keyvalue('posts'); console.log("OrbitDBs created successfully!"); - return {mainDB: orbitdb.id, topicsDB: topicsDB.address.toString(), postsDB: postsDB.address.toString()}; //TODO: regex in the latter two + return {id: orbitdb.id, topicsDB: topicsDB.address.root, postsDB: postsDB.address.root, + publicKey: orbitdb.key.getPublic('hex'), privateKey:orbitdb.key.getPrivate('hex')}; } export { createDatabases } \ No newline at end of file