|
|
@ -1,7 +1,6 @@ |
|
|
|
const fs = require('fs-extra'), |
|
|
|
request = require('request'), |
|
|
|
async = require('async'), |
|
|
|
rimraf = require('rimraf'); |
|
|
|
async = require('async'); |
|
|
|
|
|
|
|
var cache = {}; |
|
|
|
|
|
|
@ -182,7 +181,7 @@ var cacheCallInProgress = false, |
|
|
|
cacheGlobLifetime = 300; // sec
|
|
|
|
|
|
|
|
// TODO: reset calls' states on new /cache call start
|
|
|
|
cache.all = function(req, res, next) { |
|
|
|
/*cache.all = function(req, res, next) { |
|
|
|
if (req.query.pubkey && !fs.existsSync(cache.iguanaDir + '/shepherd/cache-' + req.query.pubkey + '.json')) { |
|
|
|
cacheCallInProgress = false; |
|
|
|
} |
|
|
@ -491,7 +490,7 @@ cache.all = function(req, res, next) { |
|
|
|
'result': 'another call is in progress already' |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
/* |
|
|
|
* type: GET |
|
|
@ -552,8 +551,6 @@ cache.one = function(req, res, next) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
// add timestamp to cache file
|
|
|
|
// writeCache(Date.now());
|
|
|
|
} |
|
|
|
}, |
|
|
|
checkTimestamp = function(dateToCheck) { |
|
|
@ -637,6 +634,7 @@ cache.one = function(req, res, next) { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
function getAddresses(coin) { |
|
|
|
request({ |
|
|
|
url: 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/bitcoinrpc/getaddressesbyaccount?userpass=' + sessionKey + '&coin=' + coin + '&account=*', |
|
|
|
method: 'GET' |
|
|
@ -782,6 +780,61 @@ cache.one = function(req, res, next) { |
|
|
|
// TODO: error
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (coin === 'all') { |
|
|
|
request({ |
|
|
|
url: 'http://' + cache.appConfig.host + ':' + cache.appConfig.iguanaCorePort + '/api/InstantDEX/allcoins?userpass=' + sessionKey, |
|
|
|
method: 'GET' |
|
|
|
}, function (error, response, body) { |
|
|
|
if (response && response.statusCode && response.statusCode === 200) { |
|
|
|
cache.io.emit('messages', { |
|
|
|
'message': { |
|
|
|
'shepherd': { |
|
|
|
'method': 'cache-one', |
|
|
|
'status': 'in progress', |
|
|
|
'iguanaAPI': { |
|
|
|
'method': 'allcoins', |
|
|
|
'status': 'done', |
|
|
|
'resp': body |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
body = JSON.parse(body); |
|
|
|
// basilisk coins
|
|
|
|
if (body.basilisk && body.basilisk.length) { |
|
|
|
// get coin addresses
|
|
|
|
async.each(body.basilisk, function(coin) { |
|
|
|
callStack[coin] = 1; |
|
|
|
}); |
|
|
|
|
|
|
|
async.each(body.basilisk, function(coin) { |
|
|
|
outObj.basilisk[coin] = {}; |
|
|
|
writeCache(); |
|
|
|
|
|
|
|
cache.io.emit('messages', { |
|
|
|
'message': { |
|
|
|
'shepherd': { |
|
|
|
'method': 'cache-one', |
|
|
|
'status': 'in progress', |
|
|
|
'iguanaAPI': { |
|
|
|
'method': 'getaddressesbyaccount', |
|
|
|
'coin': coin, |
|
|
|
'status': 'in progress' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
getAddresses(coin); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
getAddresses(coin); |
|
|
|
} |
|
|
|
} else { |
|
|
|
callStack[coin] = callStack[coin] + (coin === 'BTC' ? callsArray.length : callsArray.length - 2); |
|
|
|
console.log(coin + ' stack len ' + callStack[coin]); |
|
|
|