Skip to content

Commit fa59000

Browse files
committed
Merge pull request #251 from braydonf/bug/tx-count
Fix bug with address summary transaction count.
2 parents 8a2a0ab + 80fadc7 commit fa59000

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

integration/regtest-node.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,23 @@ describe('Node Functionality', function() {
570570
});
571571
});
572572

573+
it('summary for an address (sending and receiving)', function(done) {
574+
node.services.address.getAddressSummary(address, {}, function(err, results) {
575+
if (err) {
576+
throw err;
577+
}
578+
results.totalReceived.should.equal(2000000000);
579+
results.totalSpent.should.equal(1999990000);
580+
results.balance.should.equal(10000);
581+
results.unconfirmedBalance.should.equal(10000);
582+
results.appearances.should.equal(6);
583+
results.unconfirmedAppearances.should.equal(0);
584+
results.txids.length.should.equal(6);
585+
done();
586+
});
587+
});
588+
589+
573590
it('total transaction count (sending and receiving)', function(done) {
574591
var addresses = [
575592
address

lib/services/address/index.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -906,19 +906,14 @@ AddressService.prototype.getAddressSummary = function(address, options, callback
906906

907907
var outputs;
908908
var inputs;
909-
var mempoolInputs;
910909

911910
async.parallel(
912911
[
913912
function(next) {
914-
if(options.noTxList) {
915-
setImmediate(next);
916-
} else {
917-
self.getInputs(address, opt, function(err, ins) {
918-
inputs = ins;
919-
next(err);
920-
});
921-
}
913+
self.getInputs(address, opt, function(err, ins) {
914+
inputs = ins;
915+
next(err);
916+
});
922917
},
923918
function(next) {
924919
self.getOutputs(address, opt, function(err, outs) {
@@ -936,8 +931,8 @@ AddressService.prototype.getAddressSummary = function(address, options, callback
936931
var totalSpent = 0;
937932
var balance = 0;
938933
var unconfirmedBalance = 0;
939-
var appearances = 0;
940-
var unconfirmedAppearances = 0;
934+
var appearanceIds = {};
935+
var unconfirmedAppearanceIds = {};
941936
var txids = [];
942937

943938
for(var i = 0; i < outputs.length; i++) {
@@ -951,33 +946,38 @@ AddressService.prototype.getAddressSummary = function(address, options, callback
951946
if(outputs[i].confirmations) {
952947
totalReceived += outputs[i].satoshis;
953948
balance += outputs[i].satoshis;
954-
appearances++;
949+
appearanceIds[outputs[i].txid] = true;
955950
} else {
956-
unconfirmedAppearances++;
951+
unconfirmedAppearanceIds[outputs[i].txid] = true;
957952
}
958953

959954
if(spentDB || spentMempool) {
960955
unconfirmedBalance -= outputs[i].satoshis;
961956
if(spentDB) {
962957
totalSpent += outputs[i].satoshis;
963958
balance -= outputs[i].satoshis;
964-
appearances++;
965-
} else {
966-
unconfirmedAppearances++;
967959
}
968960
}
969961
}
970962

963+
for(var j = 0; j < inputs.length; j++) {
964+
if (inputs[j].confirmations) {
965+
appearanceIds[inputs[j].txid] = true;
966+
} else {
967+
unconfirmedAppearanceIds[outputs[j].txid] = true;
968+
}
969+
}
970+
971971
var summary = {
972972
totalReceived: totalReceived,
973973
totalSpent: totalSpent,
974974
balance: balance,
975975
unconfirmedBalance: unconfirmedBalance,
976-
appearances: appearances,
977-
unconfirmedAppearances: unconfirmedAppearances
976+
appearances: Object.keys(appearanceIds).length,
977+
unconfirmedAppearances: Object.keys(unconfirmedAppearanceIds).length
978978
};
979979

980-
if(inputs) {
980+
if(!options.noTxList) {
981981
for(var i = 0; i < inputs.length; i++) {
982982
txids.push(inputs[i]);
983983
}

0 commit comments

Comments
 (0)