-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
36 lines (33 loc) · 971 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const ChildChain = require('./childchain');
const Listener = require('./listener/lib');
const Rpc = require('./rpc/lib');
const MongoDown = ChildChain.MongoDown;
const leveldown = require('leveldown');
function getOption() {
const mongoOptions = {
blockdb: new MongoDown('blockdb'),
metadb: new MongoDown('metadb'),
snapshotdb: new MongoDown('snapshotdb')
}
const fsOptions = {
blockdb: leveldown('.db/blockdb'),
metadb: leveldown('.db/metadb'),
snapshotdb: leveldown('.db/snapshotdb')
}
const storage = process.env.STORAGE || 'leveldown';
if(storage == 'leveldown') {
return fsOptions;
}else if(storage == 'mongodb') {
return mongoOptions
}
}
async function main(){
let childChain = await ChildChain.run(getOption());
Listener.run(childChain);
Rpc.run(childChain);
childChain.emit('Ready', {});
return true;
}
main()
.then(() => console.log('Chain running. RPC running.') )
.catch(e=> console.error(e) );