Browse Source

IPFS/ Orbit fix

develop
Ezerous 6 years ago
parent
commit
fb911b76da
  1. 4
      app/package.json
  2. 2
      app/src/config/drizzleOptions.js
  3. 19
      app/src/orbit.js
  4. 2
      app/src/redux/sagas/drizzleUtilsSaga.js
  5. 1
      app/src/utils/drizzleUtils.js

4
app/package.json

@ -10,8 +10,8 @@
"connected-react-router": "^6.3.1", "connected-react-router": "^6.3.1",
"drizzle": "^1.3.3", "drizzle": "^1.3.3",
"history": "^4.7.2", "history": "^4.7.2",
"ipfs": "~0.34.4", "ipfs": "github:ipfs/js-ipfs#e849dbcab4a313f7ffc1532a389097ee76344067",
"orbit-db": "github:mistakia/orbit-db#proto/read-from-disk", "orbit-db": "~0.19.9",
"orbit-db-keystore": "^0.1.0", "orbit-db-keystore": "^0.1.0",
"prop-types": "^15.7.2", "prop-types": "^15.7.2",
"react": "^16.8.3", "react": "^16.8.3",

2
app/src/config/drizzleOptions.js

@ -9,7 +9,7 @@ const drizzleOptions = {
}, },
contracts: [Forum], contracts: [Forum],
events: { events: {
Forum: ['UserSignedUp', 'UsernameUpdated'] Forum: ['UserSignedUp', 'UsernameUpdated', 'TopicCreated', 'PostCreated']
}, },
polls: { polls: {
accounts: 2000, accounts: 2000,

19
app/src/orbit.js

@ -15,7 +15,8 @@ function initIPFS(){
} }
async function createDatabases() { async function createDatabases() {
orbitdb = await OrbitDB.createInstance(ipfs); console.log("Creating databases...");
orbitdb = await new OrbitDB(ipfs);
topicsDB = await orbitdb.keyvalue('topics'); topicsDB = await orbitdb.keyvalue('topics');
postsDB = await orbitdb.keyvalue('posts'); postsDB = await orbitdb.keyvalue('posts');
store.dispatch({ store.dispatch({
@ -26,13 +27,12 @@ async function createDatabases() {
id: orbitdb.id id: orbitdb.id
}); });
const identityKey = orbitdb.keystore.getKey(orbitdb.identity.id);
const orbitKey = orbitdb.keystore.getKey(orbitdb.id); const orbitKey = orbitdb.keystore.getKey(orbitdb.id);
const returnValue = { const returnValue = {
identityId: orbitdb.identity.id, identityId: "Tempus",
identityPublicKey: identityKey.getPublic('hex'), identityPublicKey: "edax",
identityPrivateKey: identityKey.getPrivate('hex'), identityPrivateKey: "rerum",
orbitId: orbitdb.id, orbitId: orbitdb.id,
orbitPublicKey: orbitKey.getPublic('hex'), orbitPublicKey: orbitKey.getPublic('hex'),
orbitPrivateKey: orbitKey.getPrivate('hex'), orbitPrivateKey: orbitKey.getPrivate('hex'),
@ -46,19 +46,16 @@ async function createDatabases() {
async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, async function loadDatabases(identityId, identityPublicKey, identityPrivateKey,
orbitId, orbitPublicKey, orbitPrivateKey, topicsDB, postsDB) { orbitId, orbitPublicKey, orbitPrivateKey, topicsDB, postsDB) {
console.log("Loading databases...");
let directory = "./orbitdb"; let directory = "./orbitdb";
let keystore = Keystore.create(path.join(directory, identityId, '/keystore')); let keystore = Keystore.create(path.join(directory, orbitId, '/keystore'));
keystore._storage.setItem(identityId, JSON.stringify({
publicKey: identityPublicKey,
privateKey: identityPrivateKey
}));
keystore._storage.setItem(orbitId, JSON.stringify({ keystore._storage.setItem(orbitId, JSON.stringify({
publicKey: orbitPublicKey, publicKey: orbitPublicKey,
privateKey: orbitPrivateKey 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'); topicsDB = await orbitdb.keyvalue('/orbitdb/' + topicsDB +'/topics');
postsDB = await orbitdb.keyvalue('/orbitdb/' + postsDB +'/posts'); postsDB = await orbitdb.keyvalue('/orbitdb/' + postsDB +'/posts');

2
app/src/redux/sagas/drizzleUtilsSaga.js

@ -10,7 +10,7 @@ function* init() {
if(!initFlag) { if(!initFlag) {
web3 = yield call(getWeb3); web3 = yield call(getWeb3);
contract = yield call(getContractInstance,{ contract = yield call(getContractInstance,{
web3, web3: web3,
artifact: Forum artifact: Forum
}); });
initFlag=true; initFlag=true;

1
app/src/utils/drizzleUtils.js

@ -1,3 +1,4 @@
// See also: https://github.com/trufflesuite/drizzle-utils
const Web3 = require("web3"); const Web3 = require("web3");
const resolveWeb3 = (resolve, options, isBrowser) => { const resolveWeb3 = (resolve, options, isBrowser) => {

Loading…
Cancel
Save