Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Stats DB and route #4

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions app/controllers/pqstats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var common = require('./common');
var StatsDb = require('../../lib/StatsDb');

var checkSync = function(req, res) {
if (req.historicSync) {
var i = req.historicSync.info()
if (i.status !== 'finished') {
common.notReady(req, res, i.syncPercentage);
return false;
}
}
return true;
};

module.exports.getPqStats = function (req, res, next) {
if (!checkSync(req, res)){
return;
};
StatsDb.getPqStats(function (error, stats) {
console.log("STATS", stats);
if (error) {
console.log("err", error);
return common.handleErrors(error, res);
} else {
return res.jsonp(stats);
}
});
}
4 changes: 4 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ module.exports = function(app) {
app.get(apiPrefix + '/txs', transactions.list);
app.post(apiPrefix + '/tx/send', transactions.send);

//PQ Stats routes
var pqStats = require('../app/controllers/pqstats');
app.get(apiPrefix + '/pqstats', pqStats.getPqStats);

// Raw Routes
app.get(apiPrefix + '/rawtx/:txid', transactions.showRaw);
app.param('txid', transactions.rawTransaction);
Expand Down
94 changes: 50 additions & 44 deletions insight.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var fs = require('fs');
var PeerSync = require('./lib/PeerSync');
var HistoricSync = require('./lib/HistoricSync');
var StatsDb = require('./lib/StatsDb');

var http = require('http');
var https = require('https');
Expand All @@ -28,7 +29,7 @@ console.log(
/___/_/ /_/____/_/\\__, /_/ /_/\\__/ /_/ |_/ .___/_/ \n\
/____/ /_/ \n\
\n\t\t\t\t\t\tv%s\n', config.version);
program.on('--help', function() {
program.on('--help', function () {
logger.info('\n# Configuration:\n\
\tINSIGHT_NETWORK (Network): %s\n\
\tINSIGHT_DB (Database Path): %s\n\
Expand Down Expand Up @@ -78,8 +79,8 @@ if (config.enableHTTPS) {

// Bootstrap models
var models_path = __dirname + '/app/models';
var walk = function(path) {
fs.readdirSync(path).forEach(function(file) {
var walk = function (path) {
fs.readdirSync(path).forEach(function (file) {
var newPath = path + '/' + file;
var stat = fs.statSync(newPath);
if (stat.isFile()) {
Expand All @@ -94,59 +95,64 @@ var walk = function(path) {

walk(models_path);

// p2pSync process
var peerSync = new PeerSync({
shouldBroadcast: true
});
StatsDb.init(function (err) {
if (err) {
console.error(err);
process.exit(1);
}

if (!config.disableP2pSync) {
peerSync.run();
}
// p2pSync process
var peerSync = new PeerSync({
shouldBroadcast: true
});

// historic_sync process
var historicSync = new HistoricSync({
shouldBroadcastSync: true
});
peerSync.historicSync = historicSync;
if (!config.disableP2pSync) {
peerSync.run();
}

if (!config.disableHistoricSync) {
historicSync.start({}, function(err) {
if (err) {
var txt = 'ABORTED with error: ' + err.message;
console.log('[historic_sync] ' + txt);
}
if (peerSync) peerSync.allowReorgs = true;
// historic_sync process
var historicSync = new HistoricSync({
shouldBroadcastSync: true
});
} else
if (peerSync) peerSync.allowReorgs = true;

peerSync.historicSync = historicSync;

if (!config.disableHistoricSync) {
historicSync.start({}, function (err) {
if (err) {
var txt = 'ABORTED with error: ' + err.message;
console.log('[historic_sync] ' + txt);
}
if (peerSync) peerSync.allowReorgs = true;
});
} else
if (peerSync) peerSync.allowReorgs = true;

// socket.io
var ios = require('socket.io')(server, config);
require('./app/controllers/socket.js').init(ios);
// socket.io
var ios = require('socket.io')(server, config);
require('./app/controllers/socket.js').init(ios);

// plugins
if (config.enableRatelimiter) {
require('./plugins/ratelimiter').init(expressApp, config.ratelimiter);
}
// plugins
if (config.enableRatelimiter) {
require('./plugins/ratelimiter').init(expressApp, config.ratelimiter);
}

if (config.enableEmailstore) {
require('./plugins/emailstore').init(config.emailstore);
}
if (config.enableEmailstore) {
require('./plugins/emailstore').init(config.emailstore);
}

if (config.enableCurrencyRates) {
require('./plugins/currencyrates').init(config.currencyrates);
}
if (config.enableCurrencyRates) {
require('./plugins/currencyrates').init(config.currencyrates);
}

// express settings
require('./config/express')(expressApp, historicSync, peerSync);
require('./config/routes')(expressApp);
// express settings
require('./config/express')(expressApp, historicSync, peerSync);
require('./config/routes')(expressApp);


//Start the app by listening on <port>
server.listen(config.port, function() {
logger.info('insight server listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
//Start the app by listening on <port>
server.listen(config.port, function () {
logger.info('insight server listening on port %d in %s mode', server.address().port, process.env.NODE_ENV);
});
});

//expose app
Expand Down
Loading