From 80eb012f83997558390efa82511328cb76791658 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Thu, 20 Mar 2014 16:36:45 -0300 Subject: [PATCH 1/4] 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 d2a90b7..370549d 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 aff1611..4bd6e40 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); }); }; From eae1589307acd95425361881ef0d13e4ce3cc81c Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Thu, 20 Mar 2014 16:42:28 -0300 Subject: [PATCH 2/4] Update read me --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3125959..77c167b 100644 --- a/README.md +++ b/README.md @@ -136,8 +136,8 @@ The end-points are: ``` ### Address ``` - /api/addr/[:addr] - /api/addr/mmvP3mTe53qxHdPqXEvdu8WdC7GfQ2vmx5 + /api/addr/[:addr][?getBalance=1] + /api/addr/mmvP3mTe53qxHdPqXEvdu8WdC7GfQ2vmx5?getBalance=1 ``` ### Transactions by Block ``` From 3bd44e12a239ec6f7272080726f45597e87bd966 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Fri, 21 Mar 2014 10:24:44 -0300 Subject: [PATCH 3/4] names more descriptive --- app/controllers/addresses.js | 2 +- app/models/Address.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/addresses.js b/app/controllers/addresses.js index 370549d..257a6bd 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); + }, req.query.noTxList); }; diff --git a/app/models/Address.js b/app/models/Address.js index 4bd6e40..91e47f5 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, balance) { +Address.prototype.update = function(next, notxlist) { var self = this; if (!self.addrStr) return next(); @@ -132,7 +132,7 @@ Address.prototype.update = function(next, balance) { var v = txItem.value_sat; if ( !seen[txItem.txid] ) { - if (!balance) { + if (!notxlist) { txs.push({txid: txItem.txid, ts: txItem.ts}); } seen[txItem.txid]=1; @@ -140,7 +140,7 @@ Address.prototype.update = function(next, balance) { } if (txItem.spentTxId && !seen[txItem.spentTxId] ) { - if (!balance) { + if (!notxlist) { txs.push({txid: txItem.spentTxId, ts: txItem.spentTs}); } seen[txItem.spentTxId]=1; @@ -176,7 +176,7 @@ Address.prototype.update = function(next, balance) { }, ], function (err) { - if (!balance) { + if (!notxlist) { // sort input and outputs togheter txs.sort( function compare(a,b) { From 3bf1ceeb96c3bbf2d1c4e4f52b43ae617fccd5f9 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Sat, 22 Mar 2014 01:58:12 -0300 Subject: [PATCH 4/4] update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77c167b..8fd281c 100644 --- a/README.md +++ b/README.md @@ -136,8 +136,8 @@ The end-points are: ``` ### Address ``` - /api/addr/[:addr][?getBalance=1] - /api/addr/mmvP3mTe53qxHdPqXEvdu8WdC7GfQ2vmx5?getBalance=1 + /api/addr/[:addr][?noTxList=1] + /api/addr/mmvP3mTe53qxHdPqXEvdu8WdC7GfQ2vmx5?noTxList=1 ``` ### Transactions by Block ```