From fb911b76da16674d4e960360330d9df16f4c31b9 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Sat, 2 Mar 2019 17:47:03 +0200 Subject: [PATCH] IPFS/ Orbit fix --- app/package.json | 4 ++-- app/src/config/drizzleOptions.js | 2 +- app/src/orbit.js | 19 ++++++++----------- app/src/redux/sagas/drizzleUtilsSaga.js | 2 +- app/src/utils/drizzleUtils.js | 1 + 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/package.json b/app/package.json index 60a798b..de8be6f 100644 --- a/app/package.json +++ b/app/package.json @@ -10,8 +10,8 @@ "connected-react-router": "^6.3.1", "drizzle": "^1.3.3", "history": "^4.7.2", - "ipfs": "~0.34.4", - "orbit-db": "github:mistakia/orbit-db#proto/read-from-disk", + "ipfs": "github:ipfs/js-ipfs#e849dbcab4a313f7ffc1532a389097ee76344067", + "orbit-db": "~0.19.9", "orbit-db-keystore": "^0.1.0", "prop-types": "^15.7.2", "react": "^16.8.3", diff --git a/app/src/config/drizzleOptions.js b/app/src/config/drizzleOptions.js index ff3ea6a..65fa246 100644 --- a/app/src/config/drizzleOptions.js +++ b/app/src/config/drizzleOptions.js @@ -9,7 +9,7 @@ const drizzleOptions = { }, contracts: [Forum], events: { - Forum: ['UserSignedUp', 'UsernameUpdated'] + Forum: ['UserSignedUp', 'UsernameUpdated', 'TopicCreated', 'PostCreated'] }, polls: { accounts: 2000, diff --git a/app/src/orbit.js b/app/src/orbit.js index aebe570..41e81a3 100644 --- a/app/src/orbit.js +++ b/app/src/orbit.js @@ -15,7 +15,8 @@ function initIPFS(){ } async function createDatabases() { - orbitdb = await OrbitDB.createInstance(ipfs); + console.log("Creating databases..."); + orbitdb = await new OrbitDB(ipfs); topicsDB = await orbitdb.keyvalue('topics'); postsDB = await orbitdb.keyvalue('posts'); store.dispatch({ @@ -26,13 +27,12 @@ async function createDatabases() { id: orbitdb.id }); - const identityKey = orbitdb.keystore.getKey(orbitdb.identity.id); const orbitKey = orbitdb.keystore.getKey(orbitdb.id); const returnValue = { - identityId: orbitdb.identity.id, - identityPublicKey: identityKey.getPublic('hex'), - identityPrivateKey: identityKey.getPrivate('hex'), + identityId: "Tempus", + identityPublicKey: "edax", + identityPrivateKey: "rerum", orbitId: orbitdb.id, orbitPublicKey: orbitKey.getPublic('hex'), orbitPrivateKey: orbitKey.getPrivate('hex'), @@ -46,19 +46,16 @@ async function createDatabases() { async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, orbitId, orbitPublicKey, orbitPrivateKey, topicsDB, postsDB) { + console.log("Loading databases..."); let directory = "./orbitdb"; - let keystore = Keystore.create(path.join(directory, identityId, '/keystore')); - keystore._storage.setItem(identityId, JSON.stringify({ - publicKey: identityPublicKey, - privateKey: identityPrivateKey - })); + let keystore = Keystore.create(path.join(directory, orbitId, '/keystore')); keystore._storage.setItem(orbitId, JSON.stringify({ publicKey: orbitPublicKey, privateKey: orbitPrivateKey })); - orbitdb = await OrbitDB.createInstance(ipfs, {directory: directory, peerId:identityId, keystore:keystore}); + orbitdb = await new OrbitDB(ipfs, directory, { peerId:orbitId, keystore:keystore}); topicsDB = await orbitdb.keyvalue('/orbitdb/' + topicsDB +'/topics'); postsDB = await orbitdb.keyvalue('/orbitdb/' + postsDB +'/posts'); diff --git a/app/src/redux/sagas/drizzleUtilsSaga.js b/app/src/redux/sagas/drizzleUtilsSaga.js index 69d3ee2..0278ade 100644 --- a/app/src/redux/sagas/drizzleUtilsSaga.js +++ b/app/src/redux/sagas/drizzleUtilsSaga.js @@ -10,7 +10,7 @@ function* init() { if(!initFlag) { web3 = yield call(getWeb3); contract = yield call(getContractInstance,{ - web3, + web3: web3, artifact: Forum }); initFlag=true; diff --git a/app/src/utils/drizzleUtils.js b/app/src/utils/drizzleUtils.js index 7514f2e..9a52bdf 100644 --- a/app/src/utils/drizzleUtils.js +++ b/app/src/utils/drizzleUtils.js @@ -1,3 +1,4 @@ +// See also: https://github.com/trufflesuite/drizzle-utils const Web3 = require("web3"); const resolveWeb3 = (resolve, options, isBrowser) => {