-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
executable file
·127 lines (107 loc) · 3.74 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"use strict";
const co = require('co');
const fs = require('fs');
const path = require('path');
const main = require(__dirname + '/lib/main.js');
const indexing = require(__dirname + '/lib/indexing.js');
const initMonitDB = require('./lib/DataFinder').initMonitDB;
/****************************************
* TECHNICAL CONFIGURATION
***************************************/
// Default Duniter node's database
//const DEFAULT_DUNITER_DATA_FOLDER = 'currency-monit-dev';
// host on which UI is available
const DEFAULT_ACTION = 'start';
// host on which UI is available
const DEFAULT_HOST = 'localhost';
// port on which UI is available
const DEFAULT_PORT = 10500;
/****************************************
* SPECIALIZATION
***************************************/
/*const stack = duniter.statics.autoStack([{
name: 'currency-monit',
required: {*/
module.exports = {
duniter: {
config: {
onLoading: (conf, program) => co(function*() {
// Define duniter-currency-monit parameters namespace
const obj = conf['duniter-currency-monit'] = conf['duniter-currency-monit'] || {}
})
},
cliOptions: [
{ value: '--monitor', desc: 'Enable performance monitoring of DB access'},
{ value: '--reset-data', desc: 'Forces Monit to reset its indexed data on startup'},
],
cli: [{
name: 'currency-monit [start|indexing] [host] [port]',
desc: 'Start duniter with module currency-monit or Indexing blockchain history',
preventIfRunning: true,
logs: false,
onDatabaseExecute: (server, conf, program, params, startServices) => co(function*() {
// currency-monit parameters
const ACTION = params[0] || DEFAULT_ACTION;
const SERVER_HOST = params[1] || DEFAULT_HOST;
const SERVER_PORT = parseInt(params[2]) || DEFAULT_PORT;
if (ACTION == "start")
{
// IMPORTANT: release Duniter services from "sleep" mode
yield startServices();
// Main Loop
yield main(server, SERVER_HOST, SERVER_PORT, null, program);
// Wait forever, this is a permanent program
yield new Promise(() => null);
}
else if (ACTION == "indexing")
{
try {
indexing(server, conf, program, params);
} catch (err) {
console.error('Error during blockchain indexing ', err);
}
// Close the DB connection properly
return server && server.disconnect()
}
else
{
console.error('Error unknow action "%s" !', ACTION);
// Close the DB connection properly
return server && server.disconnect()
}
})
}, {
name: 'reindex',
desc: 'Reset indexed Monit data and rebuild index',
preventIfRunning: true,
logs: false,
async onDatabaseExecute(server, conf, program, params, startServices) {
await initMonitDB(server, true);
}
}]
},
duniterUI: {
inject: {
menu: fs.readFileSync(path.join(__dirname, 'injection/menu.js'), 'utf8')
},
route: (app, server, conf, program, params) => {
// Main Loop
//main(server, SERVER_HOST, SERVER_PORT);
main(server, null, null, app, program); // `app` est un serveur HTTP Express
// Wait forever, this is a permanent program
new Promise(() => null);
}
}
}
//}]);
/*co(function*() {
if (!process.argv.includes('--mdb')) {
// We use the default database
process.argv.push('--mdb');
process.argv.push(DEFAULT_DUNITER_DATA_FOLDER);
}
// Execute our program
yield stack.executeStack(process.argv);
// End
process.exit();
});*/