Browse Source

OrbitDB minor improvements

develop
Ezerous 7 years ago
parent
commit
04b7037de0
  1. 44
      contracts/Forum.sol
  2. 6
      src/containers/LoadingContainer.js
  3. 5
      src/containers/UsernameFormContainer.js
  4. 3
      src/util/orbit.js

44
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;

6
src/containers/LoadingContainer.js

@ -20,7 +20,7 @@ class LoadingContainer extends Component {
<main className="container loading-screen">
<div className="pure-g">
<div className="pure-u-1-1">
<h1></h1>
<h1><span role="img" aria-label="Warning Sign"></span></h1>
<p>This browser has no connection to the Ethereum network. Please use the Chrome/FireFox extension MetaMask, or dedicated Ethereum browsers Mist or Parity.</p>
</div>
</div>
@ -34,7 +34,7 @@ class LoadingContainer extends Component {
<main className="container loading-screen">
<div className="pure-g">
<div className="pure-u-1-1">
<h1>🦊</h1>
<h1><span role="img" aria-label="Fox Face">🦊</span></h1>
<p><strong>We can't find any Ethereum accounts!</strong> Please check and make sure Metamask or you browser are pointed at the correct network and your account is unlocked.</p>
</div>
</div>
@ -67,7 +67,7 @@ class LoadingContainer extends Component {
<main className="container loading-screen">
<div className="pure-g">
<div className="pure-u-1-1">
<h1></h1>
<h1><span role="img" aria-label="Gear"></span></h1>
<p>Loading dapp...</p>
</div>
</div>

5
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]);
}
}

3
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 }
Loading…
Cancel
Save