|
@ -1,32 +1,26 @@ |
|
|
import IPFS from 'ipfs'; |
|
|
|
|
|
import OrbitDB from 'orbit-db'; |
|
|
import OrbitDB from 'orbit-db'; |
|
|
import Keystore from 'orbit-db-keystore'; |
|
|
import Keystore from 'orbit-db-keystore'; |
|
|
import path from 'path'; |
|
|
import path from 'path'; |
|
|
import store from './redux/store'; |
|
|
import store from '../redux/store'; |
|
|
import ipfsOptions from './config/ipfsOptions' |
|
|
import { DATABASES_CREATED, DATABASES_LOADED, IPFS_INITIALIZED, updateDatabases } from '../redux/actions/orbitActions'; |
|
|
import { IPFS_INITIALIZED, DATABASES_CREATED, DATABASES_LOADED } from './redux/actions/orbitActions'; |
|
|
import IPFS from "ipfs"; |
|
|
|
|
|
import ipfsOptions from "../config/ipfsOptions"; |
|
|
let ipfs; |
|
|
|
|
|
|
|
|
|
|
|
function initIPFS(){ |
|
|
function initIPFS(){ |
|
|
ipfs = new IPFS(ipfsOptions); |
|
|
const ipfs = new IPFS(ipfsOptions); |
|
|
ipfs.on('ready', async () => { |
|
|
ipfs.on('ready', async () => { |
|
|
store.dispatch({type: IPFS_INITIALIZED}); |
|
|
store.dispatch({type: IPFS_INITIALIZED, ipfs}); |
|
|
|
|
|
console.log("IPFS initialized."); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function createDatabases() { |
|
|
async function createDatabases() { |
|
|
console.log("Creating databases..."); |
|
|
console.log("Creating databases..."); |
|
|
|
|
|
const ipfs = getIPFS(); |
|
|
const orbitdb = await new OrbitDB(ipfs); |
|
|
const orbitdb = await new OrbitDB(ipfs); |
|
|
const topicsDB = await orbitdb.keyvalue('topics'); |
|
|
const topicsDB = await orbitdb.keyvalue('topics'); |
|
|
const postsDB = await orbitdb.keyvalue('posts'); |
|
|
const postsDB = await orbitdb.keyvalue('posts'); |
|
|
store.dispatch({ |
|
|
store.dispatch(updateDatabases(DATABASES_CREATED, orbitdb, topicsDB, postsDB)); |
|
|
type: DATABASES_CREATED, |
|
|
|
|
|
orbitdb: orbitdb, |
|
|
|
|
|
topicsDB: topicsDB, |
|
|
|
|
|
postsDB: postsDB, |
|
|
|
|
|
id: orbitdb.id |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const orbitKey = orbitdb.keystore.getKey(orbitdb.id); |
|
|
const orbitKey = orbitdb.keystore.getKey(orbitdb.id); |
|
|
|
|
|
|
|
@ -53,6 +47,7 @@ async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, |
|
|
privateKey: orbitPrivateKey |
|
|
privateKey: orbitPrivateKey |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
const ipfs = getIPFS(); |
|
|
const orbitdb = await new OrbitDB(ipfs, directory, { peerId:orbitId, keystore:keystore}); |
|
|
const orbitdb = await new OrbitDB(ipfs, directory, { peerId:orbitId, keystore:keystore}); |
|
|
const topicsDB = await orbitdb.keyvalue('/orbitdb/' + topicsDBId +'/topics'); |
|
|
const topicsDB = await orbitdb.keyvalue('/orbitdb/' + topicsDBId +'/topics'); |
|
|
const postsDB = await orbitdb.keyvalue('/orbitdb/' + postsDBId +'/posts'); |
|
|
const postsDB = await orbitdb.keyvalue('/orbitdb/' + postsDBId +'/posts'); |
|
@ -60,13 +55,13 @@ async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, |
|
|
await topicsDB.load(); |
|
|
await topicsDB.load(); |
|
|
await postsDB.load(); |
|
|
await postsDB.load(); |
|
|
|
|
|
|
|
|
store.dispatch({ |
|
|
updateDatabases(DATABASES_LOADED, orbitdb, topicsDB, postsDB); |
|
|
type: DATABASES_LOADED, |
|
|
|
|
|
orbitdb: orbitdb, |
|
|
return { orbitdb, topicsDB, postsDB }; |
|
|
topicsDB: topicsDB, |
|
|
} |
|
|
postsDB: postsDB, |
|
|
|
|
|
id: orbitdb.id |
|
|
function getIPFS(){ |
|
|
}); |
|
|
return store.getState().orbit.ipfs; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function orbitSagaPut(db, key, value) { |
|
|
async function orbitSagaPut(db, key, value) { |