diff --git a/routes/cache.js b/routes/cache.js index c1b7b41..0453f5a 100644 --- a/routes/cache.js +++ b/routes/cache.js @@ -233,6 +233,8 @@ cache.one = function(req, res, next) { total =+ callStack[coin]; } + delete callStack.all; + if (total / Object.keys(callStack).length === 1) { cacheCallInProgress = false; cache.io.emit('messages', { @@ -466,7 +468,7 @@ cache.one = function(req, res, next) { console.log(JSON.parse(body).result); writeCache(); var addrCount = outObj.basilisk[coin].addresses ? outObj.basilisk[coin].addresses.length : 0; - var callsArrayBTC = callsArray.length; + var callsArrayBTC = callsArray.length; // restrict BTC and SYS only to listunspent and listtransactions calls if (callsArray.indexOf('getbalance') > - 1) { callsArrayBTC--; } @@ -476,11 +478,19 @@ cache.one = function(req, res, next) { callStack[coin] = callStack[coin] + addrCount * (coin === 'BTC' || coin === 'SYS' ? callsArrayBTC : callsArray.length); console.log(coin + ' stack len ' + callStack[coin]); - async.each(outObj.basilisk[coin].addresses, function(address) { - execDEXRequests(address, coin); - }); + if (body.indexOf('need to unlock wallet') > -1) { + callStack[coin] = 1; + checkCallStack(); + console.log('error wallet is locked'); + } else { + async.each(outObj.basilisk[coin].addresses, function(address) { + execDEXRequests(address, coin); + }); + } } else { - // TODO: error + callStack[coin] = 1; + checkCallStack(); + console.log('error getting ' + coin + ' addrs'); } }); } @@ -503,6 +513,7 @@ cache.one = function(req, res, next) { if (coin === 'all') { var tempUrl = 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/InstantDEX/allcoins?userpass=' + sessionKey; + console.log(tempUrl); request({ url: mock ? 'http://localhost:17777/shepherd/mock?url=' + tempUrl : tempUrl, method: 'GET' @@ -550,11 +561,16 @@ cache.one = function(req, res, next) { getAddresses(coin); }); + } else { + console.log('no coin is running in basilisk'); + callStack[coin] = 1; + checkCallStack(); } } if (error) { // stop further requests on failure, exit callStack[coin] = 1; checkCallStack(); + console.log('error getting allcoins'); } }); } else { diff --git a/routes/mock.js b/routes/mock.js index 39e4156..fd3fcd6 100644 --- a/routes/mock.js +++ b/routes/mock.js @@ -12,7 +12,7 @@ mock.setVar = function(variable, value) { mock.get = function(req, res, next) { var _url = req.query.url; - if (_url.indexOf('/InstantDEX/allcoins') > -1) { + if (_url.indexOf('/api/InstantDEX/allcoins') > -1) { res.end(JSON.stringify({ 'native': [], 'basilisk': [ 'KMD', 'BTC'], @@ -28,8 +28,8 @@ mock.get = function(req, res, next) { } if (_url.indexOf('/api/dex/listunspent') > -1 || _url.indexOf('/api/dex/listtransactions') > -1 || - _url.indexOf('/api/ss/getbalance') > -1 || - _url.indexOf('/api/ww/refresh') > -1) { + _url.indexOf('/api/dex/getbalance') > -1 || + _url.indexOf('/api/basilisk/refresh') > -1) { res.end(JSON.stringify({ 'some key': 'some value' }));