Skip to content

Commit

Permalink
Address Service: Sort mempool txids
Browse files Browse the repository at this point in the history
  • Loading branch information
Braydon Fuller committed Jan 18, 2016
1 parent a166b6a commit 336c316
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/services/address/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,10 @@ AddressService.prototype._setAndSortTxidsFromAppearanceIds = function(result, ca
result.txids.sort(function(a, b) {
return result.appearanceIds[a] - result.appearanceIds[b];
});
result.unconfirmedTxids = Object.keys(result.unconfirmedAppearanceIds);
result.unconfirmedTxids.sort(function(a, b) {
return result.unconfirmedAppearanceIds[a] - result.unconfirmedAppearanceIds[b];
});
callback(null, result);
};

Expand All @@ -1505,8 +1509,6 @@ AddressService.prototype._getAddressMempoolSummary = function(address, options,
var hashBuffer = address.hashBuffer;
var hashTypeBuffer = constants.HASH_TYPES_MAP[address.type];

// TODO: Sort mempool by timestamp?

async.waterfall([
function(next) {
self._getInputsMempool(addressStr, hashBuffer, hashTypeBuffer, function(err, mempoolInputs) {
Expand Down Expand Up @@ -1549,7 +1551,7 @@ AddressService.prototype._getAddressMempoolSummary = function(address, options,
AddressService.prototype._transformAddressSummaryFromResult = function(result, options) {

var confirmedTxids = result.txids;
var unconfirmedTxids = Object.keys(result.unconfirmedAppearanceIds);
var unconfirmedTxids = result.unconfirmedTxids;

var summary = {
totalReceived: result.totalReceived,
Expand All @@ -1560,6 +1562,8 @@ AddressService.prototype._transformAddressSummaryFromResult = function(result, o
unconfirmedAppearances: unconfirmedTxids.length
};

// Sort unconfirmedTxids

if (options.fullTxList) {
summary.appearanceIds = result.appearanceIds;
summary.unconfirmedAppearanceIds = result.unconfirmedAppearanceIds;
Expand Down
18 changes: 16 additions & 2 deletions test/services/address/index.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,13 @@ describe('Address Service', function() {
'22488dbb99aed86e7081ac480e3459fa40ccab7ee18bef98b84b3cdce6bf05be': 200,
'1c413601acbd608240fc635b95886c3c1f76ec8589c3392a58b5715ceb618e93': 100,
'206d3834c010d46a2cf478cb1c5fe252be41f683c8a738e3ebe27f1aae67f505': 101
},
unconfirmedAppearanceIds: {
'ec94d845c603f292a93b7c829811ac624b76e52b351617ca5a758e9d61a11681': 1452898347406,
'ed11a08e3102f9610bda44c80c46781d97936a4290691d87244b1b345b39a693': 1452898331964,
'f71bccef3a8f5609c7f016154922adbfe0194a96fb17a798c24077c18d0a9345': 1452897902377,
'edc080f2084eed362aa488ccc873a24c378dc0979aa29b05767517b70569414a': 1452897971363,
'f35e7e2a2334e845946f3eaca76890d9a68f4393ccc9fe37a0c2fb035f66d2e9': 1452897923107
}
};
as._setAndSortTxidsFromAppearanceIds(result, function(err, result) {
Expand All @@ -2435,6 +2442,11 @@ describe('Address Service', function() {
result.txids[0].should.equal('1c413601acbd608240fc635b95886c3c1f76ec8589c3392a58b5715ceb618e93');
result.txids[1].should.equal('206d3834c010d46a2cf478cb1c5fe252be41f683c8a738e3ebe27f1aae67f505');
result.txids[2].should.equal('22488dbb99aed86e7081ac480e3459fa40ccab7ee18bef98b84b3cdce6bf05be');
result.unconfirmedTxids[0].should.equal('f71bccef3a8f5609c7f016154922adbfe0194a96fb17a798c24077c18d0a9345');
result.unconfirmedTxids[1].should.equal('f35e7e2a2334e845946f3eaca76890d9a68f4393ccc9fe37a0c2fb035f66d2e9');
result.unconfirmedTxids[2].should.equal('edc080f2084eed362aa488ccc873a24c378dc0979aa29b05767517b70569414a');
result.unconfirmedTxids[3].should.equal('ed11a08e3102f9610bda44c80c46781d97936a4290691d87244b1b345b39a693');
result.unconfirmedTxids[4].should.equal('ec94d845c603f292a93b7c829811ac624b76e52b351617ca5a758e9d61a11681');
done();
});
});
Expand Down Expand Up @@ -2546,8 +2558,6 @@ describe('Address Service', function() {
done();
});
});
it.skip('will sort txids by timestamp', function(done) {
});
});

describe('#_transformAddressSummaryFromResult', function() {
Expand All @@ -2566,6 +2576,10 @@ describe('Address Service', function() {
'35fafaf572341798b2ce2858755afa7c8800bb6b1e885d3e030b81255b5e172d': 1452874536321,
'57b7842afc97a2b46575b490839df46e9273524c6ea59ba62e1e86477cf25247': 1452874521466
},
unconfirmedTxids: [
'57b7842afc97a2b46575b490839df46e9273524c6ea59ba62e1e86477cf25247',
'35fafaf572341798b2ce2858755afa7c8800bb6b1e885d3e030b81255b5e172d'
],
unconfirmedBalance: 500000
};
var testnode = {
Expand Down

0 comments on commit 336c316

Please sign in to comment.