Browse Source

switched foreach with async, parse sessionkey param from url

all-modes
pbca26 8 years ago
parent
commit
a269897610
  1. 47
      routes/shepherd.js

47
routes/shepherd.js

@ -12,7 +12,8 @@ const electron = require('electron'),
md5 = require('md5'), md5 = require('md5'),
pm2 = require('pm2'), pm2 = require('pm2'),
readLastLines = require('read-last-lines'), readLastLines = require('read-last-lines'),
request = require('request'); request = require('request'),
async = require('async');
Promise = require('bluebird'); Promise = require('bluebird');
@ -86,8 +87,13 @@ shepherd.get('/appconf', function(req, res, next) {
res.send(obj); res.send(obj);
}); });
shepherd.post('/allcoins', function(req, res, next) { var allcoinsInProgress = false;
var sessionKey = req.body.sessionKey,
shepherd.get('/allcoins', function(req, res, next) {
if (!allcoinsInProgress) {
allcoinsInProgress = true;
var sessionKey = req.query.userpass,
_obj = { _obj = {
'msg': 'error', 'msg': 'error',
'result': 'error' 'result': 'error'
@ -111,7 +117,7 @@ shepherd.post('/allcoins', function(req, res, next) {
'result': 'call is initiated' 'result': 'call is initiated'
})); }));
console.time('allcoins'); /*console.time('allcoins');
request({ request({
url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/SuperNET/activehandle?userpass=' + sessionKey, url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/SuperNET/activehandle?userpass=' + sessionKey,
method: 'GET' method: 'GET'
@ -124,11 +130,12 @@ shepherd.post('/allcoins', function(req, res, next) {
method: 'GET' method: 'GET'
}, function (error, response, body) { }, function (error, response, body) {
if (response.statusCode && response.statusCode === 200) { if (response.statusCode && response.statusCode === 200) {
var callStack = [];
body = JSON.parse(body); body = JSON.parse(body);
// basilisk coins // basilisk coins
if (body.basilisk.length) { if (body.basilisk.length) {
// get coin addresses // get coin addresses
body.basilisk.forEach(function(coin) { async.each(body.basilisk, function(coin) {
outObj.basilisk[coin] = {}; outObj.basilisk[coin] = {};
writeCache(); writeCache();
@ -140,14 +147,15 @@ shepherd.post('/allcoins', function(req, res, next) {
outObj.basilisk[coin].addresses = JSON.parse(body).result; outObj.basilisk[coin].addresses = JSON.parse(body).result;
writeCache(); writeCache();
outObj.basilisk[coin].addresses.forEach(function(address) { async.each(outObj.basilisk[coin].addresses, function(address) {
console.log('KMD address ' + address); console.log('KMD address ' + address);
outObj.basilisk[coin][address] = {}; outObj.basilisk[coin][address] = {};
writeCache(); writeCache();
// get listunspent // get listunspent
console.log('http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listunspent' + (coin !== 'BTC' ? '2' : '') + '?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address);
request({ request({
url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listunspent?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address, url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listunspent' + (coin !== 'BTC' ? '2' : '') + '?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address,
method: 'GET' method: 'GET'
}, function (error, response, body) { }, function (error, response, body) {
if (response.statusCode && response.statusCode === 200) { if (response.statusCode && response.statusCode === 200) {
@ -160,7 +168,7 @@ shepherd.post('/allcoins', function(req, res, next) {
// get listtransactions // get listtransactions
request({ request({
url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listtransactions?userpass=' + sessionKey + '&count=100&skip=0&symbol=' + coin + '&address=' + address, url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listtransactions' + (coin !== 'BTC' ? '2' : '') + '?userpass=' + sessionKey + '&count=100&skip=0&symbol=' + coin + '&address=' + address,
method: 'GET' method: 'GET'
}, function (error, response, body) { }, function (error, response, body) {
if (response.statusCode && response.statusCode === 200) { if (response.statusCode && response.statusCode === 200) {
@ -171,19 +179,7 @@ shepherd.post('/allcoins', function(req, res, next) {
} }
}); });
// get listtransactions2 if (coin !== 'BTC') {
request({
url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listtransactions2?userpass=' + sessionKey + '&count=100&skip=0&symbol=' + coin + '&address=' + address,
method: 'GET'
}, function (error, response, body) {
if (response.statusCode && response.statusCode === 200) {
outObj.basilisk[coin][address].listtransactions2 = JSON.parse(body);
console.log(body);
writeCache();
}
});
// get refresh // get refresh
request({ request({
url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/basilisk/refresh?userpass=' + sessionKey + '&timeout=600000&symbol=' + coin + '&address=' + address, url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/basilisk/refresh?userpass=' + sessionKey + '&timeout=600000&symbol=' + coin + '&address=' + address,
@ -196,6 +192,7 @@ shepherd.post('/allcoins', function(req, res, next) {
writeCache(); writeCache();
} }
}); });
}
}); });
console.timeEnd('allcoins'); // !not an actual time taken by the call! console.timeEnd('allcoins'); // !not an actual time taken by the call!
@ -214,7 +211,13 @@ shepherd.post('/allcoins', function(req, res, next) {
} else { } else {
// TODO: error // TODO: error
} }
}); });*/
} else {
res.end(JSON.stringify({
'msg': 'error',
'result': 'another call is in progress already'
}));
}
}); });
shepherd.post('/debuglog', function(req, res) { shepherd.post('/debuglog', function(req, res) {

Loading…
Cancel
Save