From 4dbcb639fe4bd50956fba03af5c3357e48ed8683 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 13 Aug 2015 11:00:27 -0300 Subject: [PATCH] add opts param to getUtxos --- lib/expressapp.js | 2 +- lib/server.js | 10 +++++++--- test/integration/server.js | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/expressapp.js b/lib/expressapp.js index 7642079..85534ff 100644 --- a/lib/expressapp.js +++ b/lib/expressapp.js @@ -278,7 +278,7 @@ ExpressApp.prototype.start = function(opts, cb) { router.get('/v1/utxos/', function(req, res) { getServerWithAuth(req, res, function(server) { - server.getUtxos(function(err, utxos) { + server.getUtxos({}, function(err, utxos) { if (err) return returnError(err, res, req); res.json(utxos); }); diff --git a/lib/server.js b/lib/server.js index 7c19bf9..bf21404 100644 --- a/lib/server.js +++ b/lib/server.js @@ -620,10 +620,14 @@ WalletService.prototype._getBlockchainExplorer = function(network) { /** * Returns list of UTXOs + * @param {Object} opts + * @returns {Array} utxos - List of UTXOs. */ -WalletService.prototype.getUtxos = function(cb) { +WalletService.prototype.getUtxos = function(opts, cb) { var self = this; + opts = opts || {}; + function utxoKey(utxo) { return utxo.txid + '|' + utxo.vout }; @@ -718,7 +722,7 @@ WalletService.prototype._computeBytesToSendMax = function(utxos, cb) { WalletService.prototype.getBalance = function(opts, cb) { var self = this; - self.getUtxos(function(err, utxos) { + self.getUtxos({}, function(err, utxos) { if (err) return cb(err); var balance = self._totalizeUtxos(utxos); @@ -828,7 +832,7 @@ WalletService.prototype._selectTxInputs = function(txp, cb) { return _.pluck(_.sortBy(list, 'order'), 'utxo'); }; - self.getUtxos(function(err, utxos) { + self.getUtxos({}, function(err, utxos) { if (err) return cb(err); var totalAmount; diff --git a/test/integration/server.js b/test/integration/server.js index da43d8b..9f3aa59 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1350,6 +1350,29 @@ describe('Wallet service', function() { }); }); + describe('#getUtxos', function() { + var server, wallet; + beforeEach(function(done) { + helpers.createAndJoinWallet(1, 1, function(s, w) { + server = s; + wallet = w; + done(); + }); + }); + + it('should get UTXOs for wallet addresses', function(done) { + helpers.stubUtxos(server, wallet, [1, 2], function() { + server.getUtxos({}, function(err, utxos) { + should.not.exist(err); + should.exist(utxos); + utxos.length.should.equal(2); + _.sum(utxos, 'satoshis').should.equal(3 * 1e8); + done(); + }); + }); + }); + }); + describe('#getBalance', function() { var server, wallet; beforeEach(function(done) {