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",
"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",

2
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,

19
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');

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

1
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) => {

Loading…
Cancel
Save