diff --git a/lib/blockchainexplorers/insight.js b/lib/blockchainexplorers/insight.js index f09022b..34231f6 100644 --- a/lib/blockchainexplorers/insight.js +++ b/lib/blockchainexplorers/insight.js @@ -34,7 +34,8 @@ Insight.prototype.getConnectionInfo = function() { /** * Retrieve a list of unspent outputs associated with an address or set of addresses */ -Insight.prototype.getUnspentUtxos = function(addresses, cb) { +Insight.prototype.getUtxos = function(addresses, cb) { + var url = this.url + this.apiPrefix + '/addrs/utxo'; var args = { method: 'POST', hosts: this.hosts, @@ -73,7 +74,7 @@ Insight.prototype.getTransaction = function(txid, cb) { var args = { method: 'GET', hosts: this.hosts, - path: this.apiPrefix + '/tx/' + txid, + path: this.apiPrefix + '/tx/' + txid, json: true, }; diff --git a/lib/server.js b/lib/server.js index ea2a281..60c0be6 100644 --- a/lib/server.js +++ b/lib/server.js @@ -876,7 +876,7 @@ WalletService.prototype._getUtxos = function(addresses, cb) { var networkName = Bitcore.Address(addresses[0]).toObject().network; var bc = self._getBlockchainExplorer(networkName); - bc.getUnspentUtxos(addresses, function(err, utxos) { + bc.getUtxos(addresses, function(err, utxos) { if (err) return cb(err); var utxos = _.map(utxos, function(utxo) { @@ -1018,7 +1018,7 @@ WalletService.prototype._getBalanceFromAddresses = function(addresses, cb) { // Compute balance by address var byAddress = {}; - _.each(_.indexBy(utxos, 'address'), function(value, key) { + _.each(_.indexBy(_.sortBy(utxos, 'address'), 'address'), function(value, key) { byAddress[key] = { address: key, path: value.path, @@ -1121,7 +1121,6 @@ WalletService.prototype.getBalance = function(opts, cb) { if (nbAddresses < Defaults.TWO_STEP_BALANCE_THRESHOLD) { return self._getBalanceOneStep(opts, cb); } - self._getActiveAddresses(function(err, activeAddresses) { if (err) return cb(err); if (!_.isArray(activeAddresses)) { @@ -1135,7 +1134,7 @@ WalletService.prototype.getBalance = function(opts, cb) { self._getBalanceOneStep(opts, function(err, fullBalance) { if (err) return; if (!_.isEqual(partialBalance, fullBalance)) { - log.debug('Cache miss: balance in active addresses differs from final balance'); + log.info('Balance in active addresses differs from final balance'); self._notify('BalanceUpdated', fullBalance, { isGlobal: true }); diff --git a/test/blockchainexplorer.js b/test/blockchainexplorer.js index 0b5a803..aeee68e 100644 --- a/test/blockchainexplorer.js +++ b/test/blockchainexplorer.js @@ -15,10 +15,9 @@ describe('Blockchain explorer', function() { }); should.exist(exp); exp.should.respondTo('broadcast'); - exp.should.respondTo('getUnspentUtxos'); + exp.should.respondTo('getUtxos'); exp.should.respondTo('getTransactions'); exp.should.respondTo('getAddressActivity'); - exp.should.respondTo('getUnspentUtxos'); exp.should.respondTo('estimateFee'); exp.should.respondTo('initSocket'); var exp = new BlockchainExplorer({ diff --git a/test/integration/helpers.js b/test/integration/helpers.js index e816790..e612662 100644 --- a/test/integration/helpers.js +++ b/test/integration/helpers.js @@ -271,7 +271,7 @@ helpers.stubUtxos = function(server, wallet, amounts, opts, cb) { helpers._utxos = utxos; } - blockchainExplorer.getUnspentUtxos = function(addresses, cb) { + blockchainExplorer.getUtxos = function(addresses, cb) { var selected = _.filter(helpers._utxos, function(utxo) { return _.contains(addresses, utxo.address); }); diff --git a/test/integration/server.js b/test/integration/server.js index 9d9eb07..6dc14a6 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1452,7 +1452,7 @@ describe('Wallet service', function() { }); }); it('should get balance when there are no funds', function(done) { - blockchainExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, []); + blockchainExplorer.getUtxos = sinon.stub().callsArgWith(1, null, []); server.createAddress({}, function(err, address) { should.not.exist(err); server.getBalance({}, function(err, balance) { @@ -1495,7 +1495,7 @@ describe('Wallet service', function() { }); }); it('should fail gracefully when blockchain is unreachable', function(done) { - blockchainExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, 'dummy error'); + blockchainExplorer.getUtxos = sinon.stub().callsArgWith(1, 'dummy error'); server.createAddress({}, function(err, address) { should.not.exist(err); server.getBalance({}, function(err, balance) { @@ -2135,7 +2135,7 @@ describe('Wallet service', function() { }); it('should fail gracefully if unable to reach the blockchain', function(done) { - blockchainExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, 'dummy error'); + blockchainExplorer.getUtxos = sinon.stub().callsArgWith(1, 'dummy error'); server.createAddress({}, function(err, address) { should.not.exist(err); var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, TestData.copayers[0].privKey_1H_0, {