add getActivity(addresses) to blockchain explorer

This commit is contained in:
Ivan Socolsky 2015-03-31 16:26:46 -03:00
parent fe01b8e5a6
commit 33ede5c65e
4 changed files with 19 additions and 4 deletions

View File

@ -29,6 +29,7 @@ function BlockChainExplorer(opts) {
}
var explorer = new Explorers.Insight(url, network);
explorer.getTransactions = _.bind(getTransactionsInsight, explorer, url);
explorer.getActivity = _.bind(getActivityInsight, explorer, url);
explorer.initSocket = _.bind(initSocketInsight, explorer, url);
return explorer;
default:
@ -36,10 +37,16 @@ function BlockChainExplorer(opts) {
};
};
function getTransactionsInsight(url, addresses, cb) {
function getTransactionsInsight(url, addresses, from, to, cb) {
var qs = [];
if (_.isNumber(from)) qs.push('from=' + from);
if (_.isNumber(to)) qs.push('to=' + to);
var url = url + '/api/addrs/txs' + (qs.length > 0 ? '?' + qs.join('&') : '');
request({
method: "POST",
url: url + '/api/addrs/txs',
url: url,
json: {
addrs: [].concat(addresses).join(',')
}
@ -49,6 +56,13 @@ function getTransactionsInsight(url, addresses, cb) {
});
};
function getActivityInsight(url, addresses, cb) {
getTransactionsInsight(url, addresses, 0, 0, function(err, result) {
if (err) return cb(err);
return cb(null, result.items > 0);
});
};
function initSocketInsight(url) {
var socket = io.connect(url, {});
return socket;

View File

@ -1024,7 +1024,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
});
},
function(next) {
bc.getTransactions(addressStrs, function(err, txs) {
bc.getTransactions(addressStrs, null, null, function(err, txs) {
if (err) return next(err);
next(null, self._normalizeTxHistory(txs));

View File

@ -16,6 +16,7 @@ describe('Blockchain explorer', function() {
should.exist(exp);
exp.should.respondTo('broadcast');
exp.should.respondTo('getTransactions');
exp.should.respondTo('getActivity');
exp.should.respondTo('getUnspentUtxos');
exp.should.respondTo('initSocket');
var exp = BlockchainExplorer({

View File

@ -166,7 +166,7 @@ helpers.stubBroadcastFail = function() {
};
helpers.stubHistory = function(txs) {
blockchainExplorer.getTransactions = sinon.stub().callsArgWith(1, null, txs);
blockchainExplorer.getTransactions = sinon.stub().callsArgWith(3, null, txs);
};
helpers.clientSign = WalletUtils.signTxp;