From 80eb012f83997558390efa82511328cb76791658 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Thu, 20 Mar 2014 16:36:45 -0300 Subject: [PATCH] getting address information in two modes: only balance (without txs list) and complete mode (balance + txs). --- app/controllers/addresses.js | 2 +- app/models/Address.js | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/controllers/addresses.js b/app/controllers/addresses.js index d2a90b79..370549d7 100644 --- a/app/controllers/addresses.js +++ b/app/controllers/addresses.js @@ -31,7 +31,7 @@ exports.show = function(req, res, next) { else { return res.jsonp(a); } - }); + }, req.query.getBalance); }; diff --git a/app/models/Address.js b/app/models/Address.js index aff16114..4bd6e406 100644 --- a/app/models/Address.js +++ b/app/models/Address.js @@ -116,7 +116,7 @@ Address.prototype.getUtxo = function(next) { }); }; -Address.prototype.update = function(next) { +Address.prototype.update = function(next, balance) { var self = this; if (!self.addrStr) return next(); @@ -132,13 +132,17 @@ Address.prototype.update = function(next) { var v = txItem.value_sat; if ( !seen[txItem.txid] ) { - txs.push({txid: txItem.txid, ts: txItem.ts}); + if (!balance) { + txs.push({txid: txItem.txid, ts: txItem.ts}); + } seen[txItem.txid]=1; add=1; } if (txItem.spentTxId && !seen[txItem.spentTxId] ) { - txs.push({txid: txItem.spentTxId, ts: txItem.spentTs}); + if (!balance) { + txs.push({txid: txItem.spentTxId, ts: txItem.spentTs}); + } seen[txItem.spentTxId]=1; addSpend=1; } @@ -172,15 +176,17 @@ Address.prototype.update = function(next) { }, ], function (err) { - // sort input and outputs togheter - txs.sort( - function compare(a,b) { - if (a.ts < b.ts) return 1; - if (a.ts > b.ts) return -1; - return 0; - }); + if (!balance) { + // sort input and outputs togheter + txs.sort( + function compare(a,b) { + if (a.ts < b.ts) return 1; + if (a.ts > b.ts) return -1; + return 0; + }); - self.transactions = txs.map(function(i) { return i.txid; } ); + self.transactions = txs.map(function(i) { return i.txid; } ); + } return next(err); }); };