add opts param to getUtxos

This commit is contained in:
Ivan Socolsky 2015-08-13 11:00:27 -03:00
parent a31617446f
commit 4dbcb639fe
3 changed files with 31 additions and 4 deletions

View File

@ -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);
});

View File

@ -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;

View File

@ -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) {