diff --git a/lib/common/defaults.js b/lib/common/defaults.js index 130237b..b1361e1 100644 --- a/lib/common/defaults.js +++ b/lib/common/defaults.js @@ -60,6 +60,9 @@ Defaults.FEE_LEVELS_FALLBACK = 2; // Minimum nb of addresses a wallet must have to start using 2-step balance optimization Defaults.TWO_STEP_BALANCE_THRESHOLD = 100; +// Age Limit for addresses to be considered 'active' always +Defaults.TWO_STEP_CREATION_HOURS = 24; + Defaults.FIAT_RATE_PROVIDER = 'BitPay'; Defaults.FIAT_RATE_FETCH_INTERVAL = 10; // In minutes Defaults.FIAT_RATE_MAX_LOOK_BACK_TIME = 120; // In minutes diff --git a/lib/server.js b/lib/server.js index bd03c67..9f5d521 100644 --- a/lib/server.js +++ b/lib/server.js @@ -463,7 +463,7 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) { bc.getTransaction(opts.identifier, function(err, tx) { if (err || !tx) return nextCoinNetwork(false); var outputs = _.first(self._normalizeTxHistory(tx)).outputs; - var toAddresses = _.pluck(outputs, 'address'); + var toAddresses = _.map(outputs, 'address'); async.detect(toAddresses, function(addressStr, nextAddress) { self.storage.fetchAddressByCoin(coinNetwork.coin, addressStr, function(err, address) { if (err || !address) return nextAddress(false); @@ -873,7 +873,7 @@ WalletService.prototype.savePreferences = function(opts, cb) { }, }]; - opts = _.pick(opts, _.pluck(preferences, 'name')); + opts = _.pick(opts, _.map(preferences, 'name')); try { _.each(preferences, function(preference) { var value = opts[preference.name]; @@ -1131,7 +1131,7 @@ WalletService.prototype._getUtxosForCurrentWallet = function(opts, cb) { }); }, function(next) { - addressStrs = _.pluck(allAddresses, 'address'); + addressStrs = _.map(allAddresses, 'address'); if (!opts.coin) return next(); coin = opts.coin; @@ -1155,7 +1155,7 @@ WalletService.prototype._getUtxosForCurrentWallet = function(opts, cb) { self.getPendingTxs({}, function(err, txps) { if (err) return next(err); - var lockedInputs = _.map(_.flatten(_.pluck(txps, 'inputs')), utxoKey); + var lockedInputs = _.map(_.flatten(_.map(txps, 'inputs')), utxoKey); _.each(lockedInputs, function(input) { if (utxoIndex[input]) { utxoIndex[input].locked = true; @@ -1175,7 +1175,7 @@ WalletService.prototype._getUtxosForCurrentWallet = function(opts, cb) { limit: 100 }, function(err, txs) { if (err) return next(err); - var spentInputs = _.map(_.flatten(_.pluck(txs, 'inputs')), utxoKey); + var spentInputs = _.map(_.flatten(_.map(txs, 'inputs')), utxoKey); _.each(spentInputs, function(input) { if (utxoIndex[input]) { utxoIndex[input].spent = true; @@ -1293,7 +1293,7 @@ WalletService.prototype._getBalanceOneStep = function(opts, cb) { self.storage.cleanActiveAddresses(self.walletId, next); }, function(next) { - var active = _.pluck(balance.byAddress, 'address') + var active = _.map(balance.byAddress, 'address') self.storage.storeActiveAddresses(self.walletId, active, next); }, ], function(err) { @@ -1322,8 +1322,8 @@ WalletService.prototype._getActiveAddresses = function(cb) { if (err) return cb(err); var now = Math.floor(Date.now() / 1000); - var recent = _.pluck(_.filter(allAddresses, function(address) { - return address.createdOn > (now - 24 * 3600); + var recent = _.map(_.filter(allAddresses, function(address) { + return address.createdOn > (now - Defaults.TWO_STEP_CREATION_HOURS * 3600); }), 'address'); var result = _.union(active, recent); @@ -1424,7 +1424,7 @@ WalletService.prototype.getSendMaxInfo = function(opts, cb) { if (!_.any(feeLevels, { name: opts.feeLevel })) - return cb(new ClientError('Invalid fee level. Valid values are ' + _.pluck(feeLevels, 'name').join(', '))); + return cb(new ClientError('Invalid fee level. Valid values are ' + _.map(feeLevels, 'name').join(', '))); } if (_.isNumber(opts.feePerKb)) { @@ -1567,7 +1567,7 @@ WalletService.prototype.getFeeLevels = function(opts, cb) { var feeLevels = Defaults.FEE_LEVELS[opts.coin]; function samplePoints() { - var definedPoints = _.uniq(_.pluck(feeLevels, 'nbBlocks')); + var definedPoints = _.uniq(_.map(feeLevels, 'nbBlocks')); return _.uniq(_.flatten(_.map(definedPoints, function(p) { return _.range(p, p + Defaults.FEE_LEVELS_FALLBACK + 1); }))); @@ -1986,7 +1986,7 @@ WalletService.prototype._validateAndSanitizeTxOpts = function(wallet, opts, cb) if (!_.any(feeLevels, { name: opts.feeLevel })) - return next(new ClientError('Invalid fee level. Valid values are ' + _.pluck(feeLevels, 'name').join(', '))); + return next(new ClientError('Invalid fee level. Valid values are ' + _.map(feeLevels, 'name').join(', '))); } if (_.isNumber(opts.feePerKb)) { @@ -2642,7 +2642,7 @@ WalletService.prototype.rejectTx = function(opts, cb) { }, function(next) { if (txp.status == 'rejected') { - var rejectedBy = _.pluck(_.filter(txp.actions, { + var rejectedBy = _.map(_.filter(txp.actions, { type: 'reject' }), 'copayerId'); @@ -3005,7 +3005,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) { function(next) { if (txs) return next(); - var addressStrs = _.pluck(addresses, 'address'); + var addressStrs = _.map(addresses, 'address'); var bc = self._getBlockchainExplorer(wallet.coin, wallet.network); if (!bc) return next(new Error('Could not get blockchain explorer instance')); bc.getTransactions(addressStrs, from, to, function(err, rawTxs, total) { diff --git a/test/integration/server.js b/test/integration/server.js index 918988a..8391ea2 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1973,7 +1973,7 @@ describe('Wallet service', function() { }); }); - describe('#getBalance 2 steps', function() { + describe.only('#getBalance 2 steps', function() { var server, wallet, clock; var _threshold = Defaults.TWO_STEP_BALANCE_THRESHOLD; beforeEach(function(done) { @@ -2027,7 +2027,7 @@ describe('Wallet service', function() { }); }, function(next) { - clock.tick(7 * 24 * 3600 * 1000); + clock.tick(7 * Defaults.TWO_STEP_CREATION_HOURS * 3600 * 1000); helpers.createAddresses(server, wallet, 2, 0, function(addrs) { newAddrs = addrs; server._getActiveAddresses(function(err, active) { @@ -2111,7 +2111,7 @@ describe('Wallet service', function() { }); }, function(next) { - clock.tick(7 * 24 * 3600 * 1000); + clock.tick(7 * Defaults.TWO_STEP_CREATION_HOURS * 3600 * 1000); helpers.createAddresses(server, wallet, 2, 0, function(addrs) { newAddrs = addrs; helpers.stubUtxos(server, wallet, [1, 2], { @@ -2244,7 +2244,7 @@ describe('Wallet service', function() { }); }, function(next) { - clock.tick(7 * 24 * 3600 * 1000); + clock.tick(7 * Defaults.TWO_STEP_CREATION_HOURS * 3600 * 1000); helpers.createAddresses(server, wallet, 2, 0, function(addrs) { newAddrs = addrs; helpers.stubUtxos(server, wallet, [1, 2], {