Browse Source

refactored cache dex calls

all-modes
pbca26 8 years ago
parent
commit
bf40139b37
  1. 48
      routes/shepherd.js

48
routes/shepherd.js

@ -117,7 +117,8 @@ shepherd.get('/allcoins', function(req, res, next) {
'result': 'call is initiated'
}));
/*console.time('allcoins');
console.log('allcoins call started');
console.time('allcoins');
request({
url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/SuperNET/activehandle?userpass=' + sessionKey,
method: 'GET'
@ -148,51 +149,32 @@ shepherd.get('/allcoins', function(req, res, next) {
writeCache();
async.each(outObj.basilisk[coin].addresses, function(address) {
var dexUrls = {
'listunspent': 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listunspent' + (coin !== 'BTC' ? '2' : '') + '?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address,
'listtransactions': 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listtransactions' + (coin !== 'BTC' ? '2' : '') + '?userpass=' + sessionKey + '&count=100&skip=0&symbol=' + coin + '&address=' + address,
'refresh': 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/basilisk/refresh?userpass=' + sessionKey + '&timeout=600000&symbol=' + coin + '&address=' + address
};
if (coin === 'BTC') {
delete dexUrls.refresh;
}
console.log('KMD address ' + address);
outObj.basilisk[coin][address] = {};
writeCache();
// get listunspent
console.log('http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listunspent' + (coin !== 'BTC' ? '2' : '') + '?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address);
request({
url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listunspent' + (coin !== 'BTC' ? '2' : '') + '?userpass=' + sessionKey + '&symbol=' + coin + '&address=' + address,
method: 'GET'
}, function (error, response, body) {
if (response.statusCode && response.statusCode === 200) {
outObj.basilisk[coin][address].listunspent = JSON.parse(body);
console.log(body);
writeCache();
}
});
// get listtransactions
async.forEachOf(dexUrls, function(dexUrl, key) {
request({
url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/dex/listtransactions' + (coin !== 'BTC' ? '2' : '') + '?userpass=' + sessionKey + '&count=100&skip=0&symbol=' + coin + '&address=' + address,
url: dexUrl,
method: 'GET'
}, function (error, response, body) {
if (response.statusCode && response.statusCode === 200) {
outObj.basilisk[coin][address].listtransactions = JSON.parse(body);
outObj.basilisk[coin][address][key] = JSON.parse(body);
console.log(dexUrl);
console.log(body);
writeCache();
}
});
if (coin !== 'BTC') {
// get refresh
request({
url: 'http://' + shepherd.appConfig.host + ':' + shepherd.appConfig.iguanaCorePort + '/api/basilisk/refresh?userpass=' + sessionKey + '&timeout=600000&symbol=' + coin + '&address=' + address,
method: 'GET'
}, function (error, response, body) {
if (response.statusCode && response.statusCode === 200) {
outObj.basilisk[coin][address].refresh = JSON.parse(body);
console.log(body);
writeCache();
}
});
}
});
console.timeEnd('allcoins'); // !not an actual time taken by the call!
@ -211,7 +193,7 @@ shepherd.get('/allcoins', function(req, res, next) {
} else {
// TODO: error
}
});*/
});
} else {
res.end(JSON.stringify({
'msg': 'error',

Loading…
Cancel
Save