Address History: Add getAddressHistoryCount method
This commit is contained in:
parent
87a9163743
commit
b1b40c892e
@ -518,6 +518,20 @@ describe('Node Functionality', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('total transaction count (sending and receiving)', function(done) {
|
||||
var addresses = [
|
||||
address
|
||||
];
|
||||
var options = {};
|
||||
node.services.address.getAddressHistoryCount(addresses, options, function(err, count) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
count.should.equal(6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Pagination', function() {
|
||||
it('from 0 to 1', function(done) {
|
||||
var options = {
|
||||
|
||||
@ -27,6 +27,25 @@ function AddressHistory(args) {
|
||||
|
||||
AddressHistory.MAX_ADDRESS_QUERIES = 20;
|
||||
|
||||
AddressHistory.prototype.getCount = function(callback) {
|
||||
var self = this;
|
||||
|
||||
async.eachLimit(
|
||||
self.addresses,
|
||||
AddressHistory.MAX_ADDRESS_QUERIES,
|
||||
function(address, next) {
|
||||
self.getTransactionInfo(address, next);
|
||||
},
|
||||
function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
self.combineTransactionInfo();
|
||||
callback(null, self.combinedArray.length);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
AddressHistory.prototype.get = function(callback) {
|
||||
var self = this;
|
||||
|
||||
|
||||
@ -731,6 +731,25 @@ AddressService.prototype.isSpent = function(output, queryMempool, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* This will give the total count of transactions for a single or several addresses
|
||||
* limited by a range of block heights.
|
||||
* @param {Array} addresses - An array of addresses
|
||||
* @param {Object} options - The options to limit the query
|
||||
* @param {Number} [options.start] - The beginning block height (e.g. 1500 the most recent block height).
|
||||
* @param {Number} [options.end] - The ending block height (e.g. 0 the older block height, results are inclusive).
|
||||
* @param {Boolean} [options.queryMempool] - Include the mempool in the query
|
||||
* @param {Function} callback
|
||||
*/
|
||||
AddressService.prototype.getAddressHistoryCount = function(addresses, options, callback) {
|
||||
var history = new AddressHistory({
|
||||
node: this.node,
|
||||
options: options,
|
||||
addresses: addresses
|
||||
});
|
||||
history.getCount(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* This will give the history for many addresses limited by a range of block heights (to limit
|
||||
* the database lookup times) and/or paginated to limit the results length.
|
||||
|
||||
@ -37,6 +37,43 @@ describe('Address Service History', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getCount', function() {
|
||||
it('will complete the async each limit series', function(done) {
|
||||
var addresses = [address];
|
||||
var history = new AddressHistory({
|
||||
node: {},
|
||||
options: {},
|
||||
addresses: addresses
|
||||
});
|
||||
history.getTransactionInfo = sinon.stub().callsArg(1);
|
||||
history.combineTransactionInfo = sinon.stub();
|
||||
history.get(function(err, results) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
history.getTransactionInfo.callCount.should.equal(1);
|
||||
history.combineTransactionInfo.callCount.should.equal(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('handle an error from getTransactionInfo', function(done) {
|
||||
var addresses = [address];
|
||||
var history = new AddressHistory({
|
||||
node: {},
|
||||
options: {},
|
||||
addresses: addresses
|
||||
});
|
||||
var expected = [{}];
|
||||
history.sortedArray = expected;
|
||||
history.transactionInfo = [{}];
|
||||
history.getTransactionInfo = sinon.stub().callsArgWith(1, new Error('test'));
|
||||
history.get(function(err) {
|
||||
err.message.should.equal('test');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#get', function() {
|
||||
it('will complete the async each limit series', function(done) {
|
||||
var addresses = [address];
|
||||
|
||||
@ -857,6 +857,25 @@ describe('Address Service', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getAddressHistoryCount', function() {
|
||||
it('will call getCount on address history instance', function(done) {
|
||||
function TestAddressHistory(args) {
|
||||
args.node.should.equal(mocknode);
|
||||
args.addresses.should.deep.equal([]);
|
||||
args.options.should.deep.equal({});
|
||||
}
|
||||
TestAddressHistory.prototype.getCount = sinon.stub().callsArg(0);
|
||||
var TestAddressService = proxyquire('../../../lib/services/address', {
|
||||
'./history': TestAddressHistory
|
||||
});
|
||||
var am = new TestAddressService({node: mocknode});
|
||||
am.getAddressHistoryCount([], {}, function(err, history) {
|
||||
TestAddressHistory.prototype.getCount.callCount.should.equal(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getAddressHistory', function() {
|
||||
it('will call get on address history instance', function(done) {
|
||||
function TestAddressHistory(args) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user