add getActivity(addresses) to blockchain explorer
This commit is contained in:
parent
fe01b8e5a6
commit
33ede5c65e
|
@ -29,6 +29,7 @@ function BlockChainExplorer(opts) {
|
||||||
}
|
}
|
||||||
var explorer = new Explorers.Insight(url, network);
|
var explorer = new Explorers.Insight(url, network);
|
||||||
explorer.getTransactions = _.bind(getTransactionsInsight, explorer, url);
|
explorer.getTransactions = _.bind(getTransactionsInsight, explorer, url);
|
||||||
|
explorer.getActivity = _.bind(getActivityInsight, explorer, url);
|
||||||
explorer.initSocket = _.bind(initSocketInsight, explorer, url);
|
explorer.initSocket = _.bind(initSocketInsight, explorer, url);
|
||||||
return explorer;
|
return explorer;
|
||||||
default:
|
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({
|
request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: url + '/api/addrs/txs',
|
url: url,
|
||||||
json: {
|
json: {
|
||||||
addrs: [].concat(addresses).join(',')
|
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) {
|
function initSocketInsight(url) {
|
||||||
var socket = io.connect(url, {});
|
var socket = io.connect(url, {});
|
||||||
return socket;
|
return socket;
|
||||||
|
|
|
@ -1024,7 +1024,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
bc.getTransactions(addressStrs, function(err, txs) {
|
bc.getTransactions(addressStrs, null, null, function(err, txs) {
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
|
|
||||||
next(null, self._normalizeTxHistory(txs));
|
next(null, self._normalizeTxHistory(txs));
|
||||||
|
|
|
@ -16,6 +16,7 @@ describe('Blockchain explorer', function() {
|
||||||
should.exist(exp);
|
should.exist(exp);
|
||||||
exp.should.respondTo('broadcast');
|
exp.should.respondTo('broadcast');
|
||||||
exp.should.respondTo('getTransactions');
|
exp.should.respondTo('getTransactions');
|
||||||
|
exp.should.respondTo('getActivity');
|
||||||
exp.should.respondTo('getUnspentUtxos');
|
exp.should.respondTo('getUnspentUtxos');
|
||||||
exp.should.respondTo('initSocket');
|
exp.should.respondTo('initSocket');
|
||||||
var exp = BlockchainExplorer({
|
var exp = BlockchainExplorer({
|
||||||
|
|
|
@ -166,7 +166,7 @@ helpers.stubBroadcastFail = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.stubHistory = function(txs) {
|
helpers.stubHistory = function(txs) {
|
||||||
blockchainExplorer.getTransactions = sinon.stub().callsArgWith(1, null, txs);
|
blockchainExplorer.getTransactions = sinon.stub().callsArgWith(3, null, txs);
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.clientSign = WalletUtils.signTxp;
|
helpers.clientSign = WalletUtils.signTxp;
|
||||||
|
|
Loading…
Reference in New Issue