Browse Source

Merge pull request #722 from matiu/feat/logs2

better logs
master
Matias Alejo Garcia 7 years ago
committed by GitHub
parent
commit
a7cd4e6171
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      lib/blockchainexplorers/insight.js
  2. 4
      lib/expressapp.js
  3. 154
      lib/server.js

17
lib/blockchainexplorers/insight.js

@ -42,15 +42,10 @@ Insight.prototype._doRequest = function(args, cb) {
} }
}; };
if (log.level == 'verbose') { var s = JSON.stringify(args);
var s = JSON.stringify(args); if ( s.length > 100 )
s= s.substr(0,100) + '...';
if ( s.length > 100 ) log.debug('', 'Insight Q: %s', s);
s= s.substr(0,100) + '...';
log.debug('', 'Insight Q: %s', s);
}
requestList(_.defaults(args, opts), cb); requestList(_.defaults(args, opts), cb);
}; };
@ -71,8 +66,6 @@ Insight.prototype.getUtxos = function(addresses, cb) {
}, },
}; };
log.info('','Querying utxos: %s addrs', addresses.length);
this._doRequest(args, function(err, res, unspent) { this._doRequest(args, function(err, res, unspent) {
if (err || res.statusCode !== 200) return cb(_parseErr(err, res)); if (err || res.statusCode !== 200) return cb(_parseErr(err, res));
return cb(null, unspent); return cb(null, unspent);
@ -134,8 +127,6 @@ Insight.prototype.getTransactions = function(addresses, from, to, cb) {
}; };
log.info('','Querying addresses: %s addrs', addresses.length);
this._doRequest(args, function(err, res, txs) { this._doRequest(args, function(err, res, txs) {
if (err || res.statusCode !== 200) return cb(_parseErr(err, res)); if (err || res.statusCode !== 200) return cb(_parseErr(err, res));

4
lib/expressapp.js

@ -137,7 +137,6 @@ ExpressApp.prototype.start = function(opts, cb) {
}; };
function getServer(req, res) { function getServer(req, res) {
log.heading = '<>';
var opts = { var opts = {
clientVersion: req.header('x-client-version'), clientVersion: req.header('x-client-version'),
}; };
@ -179,9 +178,6 @@ ExpressApp.prototype.start = function(opts, cb) {
// For logging // For logging
req.walletId = server.walletId; req.walletId = server.walletId;
req.copayerId = server.copayerId; req.copayerId = server.copayerId;
log.heading = '<' + req.walletId + '>';
return cb(server); return cb(server);
}); });
}; };

154
lib/server.js

@ -8,6 +8,7 @@ var config = require('../config');
log.debug = log.verbose; log.debug = log.verbose;
log.disableColor(); log.disableColor();
var EmailValidator = require('email-validator'); var EmailValidator = require('email-validator');
var Stringify = require('json-stable-stringify'); var Stringify = require('json-stable-stringify');
@ -272,6 +273,28 @@ WalletService.prototype._runLocked = function(cb, task) {
this.lock.runLocked(this.walletId, cb, task); this.lock.runLocked(this.walletId, cb, task);
}; };
WalletService.prototype.logi = function() {
if (!this) return log.info.apply(this, arguments);
if (!this.walletId) return log.info.apply(this, arguments);
var args = [].slice.call(arguments);
args.unshift('<' + this.walletId + '>');
log.info.apply(this, args);
};
WalletService.prototype.logw = function() {
if (!this) return log.info.apply(this, arguments);
if (!this.walletId) return log.info.apply(this, arguments);
var args = [].slice.call(arguments);
args.unshift('<' + this.walletId + '>');
log.warn.apply(this, args);
};
WalletService.prototype.login = function(opts, cb) { WalletService.prototype.login = function(opts, cb) {
var self = this; var self = this;
@ -381,7 +404,7 @@ WalletService.prototype.createWallet = function(opts, cb) {
addressType: addressType, addressType: addressType,
}); });
self.storage.storeWallet(wallet, function(err) { self.storage.storeWallet(wallet, function(err) {
log.debug('Wallet created', wallet.id, opts.network); self.logi('Wallet created', wallet.id, opts.network);
newWallet = wallet; newWallet = wallet;
return acb(err); return acb(err);
}); });
@ -597,7 +620,7 @@ WalletService.prototype._notify = function(type, data, opts, cb) {
} }
opts = opts || {}; opts = opts || {};
log.debug('Notification', type, data); //self.logi('Notification', type);
cb = cb || function() {}; cb = cb || function() {};
@ -1068,7 +1091,7 @@ WalletService.prototype._getBlockchainExplorer = function(coin, network) {
try { try {
bc = new BlockchainExplorer(opts); bc = new BlockchainExplorer(opts);
} catch (ex) { } catch (ex) {
log.warn('Could not instantiate blockchain explorer', ex); this.logw('Could not instantiate blockchain explorer', ex);
} }
return bc; return bc;
}; };
@ -1082,6 +1105,9 @@ WalletService.prototype._getUtxos = function(coin, addresses, cb) {
var bc = self._getBlockchainExplorer(coin, networkName); var bc = self._getBlockchainExplorer(coin, networkName);
if (!bc) return cb(new Error('Could not get blockchain explorer instance')); if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
self.logi('','Querying utxos: %s addrs', addresses.length);
bc.getUtxos(addresses, function(err, utxos) { bc.getUtxos(addresses, function(err, utxos) {
if (err) return cb(err); if (err) return cb(err);
@ -1260,7 +1286,7 @@ WalletService.prototype._getBalanceFromAddresses = function(opts, cb, i) {
self.storage.storeBalanceCache(self.walletId, opts.addresses, balance, function(err) { self.storage.storeBalanceCache(self.walletId, opts.addresses, balance, function(err) {
if (err) if (err)
log.warn('Could not save cache:',err); self.logw('Could not save cache:',err);
return cb(null, balance); return cb(null, balance);
}); });
@ -1272,7 +1298,7 @@ WalletService.prototype._getBalanceFromAddresses = function(opts, cb, i) {
if (err) return cb(err); if (err) return cb(err);
if (cache) { if (cache) {
log.info('Using UTXO Cache'); self.logi('Using UTXO Cache');
return cb(null, cache, true); return cb(null, cache, true);
} }
@ -1313,7 +1339,7 @@ WalletService.prototype._getBalanceOneStep = function(opts, cb) {
if (err) return cb(err); if (err) return cb(err);
if (addresses.length == opts.alreadyQueriedLength) { if (addresses.length == opts.alreadyQueriedLength) {
log.info('Query Skipped, all active addresses'); self.logi('Query Skipped, all active addresses');
return cb(null,null, true); return cb(null,null, true);
} }
@ -1328,7 +1354,7 @@ WalletService.prototype._getBalanceOneStep = function(opts, cb) {
var withBalance = _.map(balance.byAddress, 'address') var withBalance = _.map(balance.byAddress, 'address')
self.storage.storeAddressesWithBalance(self.walletId, withBalance, function(err) { self.storage.storeAddressesWithBalance(self.walletId, withBalance, function(err) {
if (err) { if (err) {
log.warn('Could not update wallet cache', err); self.logw('Could not update wallet cache', err);
} }
return cb(null, balance, cacheUsed); return cb(null, balance, cacheUsed);
}); });
@ -1342,7 +1368,7 @@ WalletService.prototype._getActiveAddresses = function(cb) {
self.storage.fetchAddressesWithBalance(self.walletId, function(err, addressesWB) { self.storage.fetchAddressesWithBalance(self.walletId, function(err, addressesWB) {
if (err) { if (err) {
log.warn('Could not fetch active addresses from cache', err); self.logw('Could not fetch active addresses from cache', err);
return cb(); return cb();
} }
if (!_.isArray(addressesWB)) if (!_.isArray(addressesWB))
@ -1364,7 +1390,7 @@ WalletService.prototype._checkAndUpdateAddressCount = function(twoStepCache, cb)
var self = this; var self = this;
if (twoStepCache.addressCount > Defaults.TWO_STEP_BALANCE_THRESHOLD) { if (twoStepCache.addressCount > Defaults.TWO_STEP_BALANCE_THRESHOLD) {
log.info('Not counting addresses for '+ self.walletId); self.logi('Not counting addresses');
return cb(null, true); return cb(null, true);
} }
@ -1424,7 +1450,7 @@ WalletService.prototype.getBalance = function(opts, cb, i) {
if (!_.isArray(activeAddresses)) { if (!_.isArray(activeAddresses)) {
return self._getBalanceOneStep(opts, cb); return self._getBalanceOneStep(opts, cb);
} else { } else {
log.debug('Requesting partial balance for ' + activeAddresses.length + ' addresses'); self.logi('Requesting partial balance for ' + activeAddresses.length + ' addresses');
self._getBalanceFromAddresses({ self._getBalanceFromAddresses({
coin: opts.coin, coin: opts.coin,
@ -1436,13 +1462,13 @@ WalletService.prototype.getBalance = function(opts, cb, i) {
var now = Math.floor(Date.now() / 1000); var now = Math.floor(Date.now() / 1000);
if (twoStepCache.lastEmpty > now - Defaults.TWO_STEP_INACTIVE_CLEAN_DURATION_MIN * 60 ) { if (twoStepCache.lastEmpty > now - Defaults.TWO_STEP_INACTIVE_CLEAN_DURATION_MIN * 60 ) {
log.debug('Not running the FULL balance query due to TWO_STEP_INACTIVE_CLEAN_DURATION_MIN '); self.logi('Not running the FULL balance query due to TWO_STEP_INACTIVE_CLEAN_DURATION_MIN ');
return; return;
} }
setTimeout(function() { setTimeout(function() {
log.debug('Running full balance query'); self.logi('Running full balance query');
opts.alreadyQueriedLength = activeAddresses.length; opts.alreadyQueriedLength = activeAddresses.length;
opts.fastCache = Defaults.BALANCE_CACHE_DURATION; opts.fastCache = Defaults.BALANCE_CACHE_DURATION;
@ -1450,7 +1476,7 @@ WalletService.prototype.getBalance = function(opts, cb, i) {
self._getBalanceOneStep(opts, function(err, fullBalance, skipped) { self._getBalanceOneStep(opts, function(err, fullBalance, skipped) {
if (err) return; if (err) return;
if (!skipped && !_.isEqual(partialBalance, fullBalance)) { if (!skipped && !_.isEqual(partialBalance, fullBalance)) {
log.info('Balance in active addresses differs from final balance'); self.logi('Balance in active addresses differs from final balance');
self._notify('BalanceUpdated', fullBalance, { self._notify('BalanceUpdated', fullBalance, {
isGlobal: true isGlobal: true
}); });
@ -1499,7 +1525,6 @@ WalletService.prototype.getSendMaxInfo = function(opts, cb) {
return cb(new ClientError('Only one of feeLevel/feePerKb can be specified')); return cb(new ClientError('Only one of feeLevel/feePerKb can be specified'));
if (feeArgs == 0) { if (feeArgs == 0) {
log.debug('No fee provided, using "normal" fee level');
opts.feeLevel = 'normal'; opts.feeLevel = 'normal';
} }
@ -1606,7 +1631,7 @@ WalletService.prototype._sampleFeeLevels = function(coin, network, points, cb) {
if (!bc) return cb(new Error('Could not get blockchain explorer instance')); if (!bc) return cb(new Error('Could not get blockchain explorer instance'));
bc.estimateFee(points, function(err, result) { bc.estimateFee(points, function(err, result) {
if (err) { if (err) {
log.error('Error estimating fee', err); self.logw('Error estimating fee', err);
return cb(err); return cb(err);
} }
@ -1620,7 +1645,7 @@ WalletService.prototype._sampleFeeLevels = function(coin, network, points, cb) {
})); }));
if (failed.length) { if (failed.length) {
var logger = network == 'livenet' ? log.warn : log.debug; var logger = network == 'livenet' ? self.logw : self.logi;
logger('Could not compute fee estimation in ' + network + ': ' + failed.join(', ') + ' blocks.'); logger('Could not compute fee estimation in ' + network + ': ' + failed.join(', ') + ' blocks.');
} }
@ -1708,6 +1733,7 @@ WalletService.prototype._estimateFee = function(txp) {
}; };
WalletService.prototype._checkTx = function(txp) { WalletService.prototype._checkTx = function(txp) {
var self = this;
var bitcoreError; var bitcoreError;
var serializationOpts = { var serializationOpts = {
@ -1726,7 +1752,7 @@ WalletService.prototype._checkTx = function(txp) {
txp.fee = bitcoreTx.getFee(); txp.fee = bitcoreTx.getFee();
} }
} catch (ex) { } catch (ex) {
log.error('Error building Bitcore transaction', ex); self.logw('Error building Bitcore transaction', ex);
return ex; return ex;
} }
@ -1782,16 +1808,16 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
var netValueInUtxos = totalValueInUtxos - baseTxpFee - (utxos.length * feePerInput); var netValueInUtxos = totalValueInUtxos - baseTxpFee - (utxos.length * feePerInput);
if (totalValueInUtxos < txpAmount) { if (totalValueInUtxos < txpAmount) {
log.debug('Total value in all utxos (' + Utils.formatAmountInBtc(totalValueInUtxos) + ') is insufficient to cover for txp amount (' + Utils.formatAmountInBtc(txpAmount) + ')'); self.logi('Total value in all utxos (' + Utils.formatAmountInBtc(totalValueInUtxos) + ') is insufficient to cover for txp amount (' + Utils.formatAmountInBtc(txpAmount) + ')');
return cb(Errors.INSUFFICIENT_FUNDS); return cb(Errors.INSUFFICIENT_FUNDS);
} }
if (netValueInUtxos < txpAmount) { if (netValueInUtxos < txpAmount) {
log.debug('Value after fees in all utxos (' + Utils.formatAmountInBtc(netValueInUtxos) + ') is insufficient to cover for txp amount (' + Utils.formatAmountInBtc(txpAmount) + ')'); self.logi('Value after fees in all utxos (' + Utils.formatAmountInBtc(netValueInUtxos) + ') is insufficient to cover for txp amount (' + Utils.formatAmountInBtc(txpAmount) + ')');
return cb(Errors.INSUFFICIENT_FUNDS_FOR_FEE); return cb(Errors.INSUFFICIENT_FUNDS_FOR_FEE);
} }
var bigInputThreshold = txpAmount * Defaults.UTXO_SELECTION_MAX_SINGLE_UTXO_FACTOR + (baseTxpFee + feePerInput); var bigInputThreshold = txpAmount * Defaults.UTXO_SELECTION_MAX_SINGLE_UTXO_FACTOR + (baseTxpFee + feePerInput);
log.debug('Big input threshold ' + Utils.formatAmountInBtc(bigInputThreshold)); self.logi('Big input threshold ' + Utils.formatAmountInBtc(bigInputThreshold));
var partitions = _.partition(utxos, function(utxo) { var partitions = _.partition(utxos, function(utxo) {
return utxo.satoshis > bigInputThreshold; return utxo.satoshis > bigInputThreshold;
@ -1802,8 +1828,8 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
return -utxo.satoshis; return -utxo.satoshis;
}); });
log.debug('Considering ' + bigInputs.length + ' big inputs (' + Utils.formatUtxos(bigInputs) + ')'); //log.debug('Considering ' + bigInputs.length + ' big inputs (' + Utils.formatUtxos(bigInputs) + ')');
log.debug('Considering ' + smallInputs.length + ' small inputs (' + Utils.formatUtxos(smallInputs) + ')'); //log.debug('Considering ' + smallInputs.length + ' small inputs (' + Utils.formatUtxos(smallInputs) + ')');
var total = 0; var total = 0;
var netTotal = -baseTxpFee; var netTotal = -baseTxpFee;
@ -1812,11 +1838,11 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
var error; var error;
_.each(smallInputs, function(input, i) { _.each(smallInputs, function(input, i) {
log.debug('Input #' + i + ': ' + Utils.formatUtxos(input)); //log.debug('Input #' + i + ': ' + Utils.formatUtxos(input));
var netInputAmount = input.satoshis - feePerInput; var netInputAmount = input.satoshis - feePerInput;
log.debug('The input contributes ' + Utils.formatAmountInBtc(netInputAmount)); //log.debug('The input contributes ' + Utils.formatAmountInBtc(netInputAmount));
selected.push(input); selected.push(input);
@ -1826,45 +1852,45 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
var txpSize = baseTxpSize + selected.length * sizePerInput; var txpSize = baseTxpSize + selected.length * sizePerInput;
fee = Math.round(baseTxpFee + selected.length * feePerInput); fee = Math.round(baseTxpFee + selected.length * feePerInput);
log.debug('Tx size: ' + Utils.formatSize(txpSize) + ', Tx fee: ' + Utils.formatAmountInBtc(fee)); //log.debug('Tx size: ' + Utils.formatSize(txpSize) + ', Tx fee: ' + Utils.formatAmountInBtc(fee));
var feeVsAmountRatio = fee / txpAmount; var feeVsAmountRatio = fee / txpAmount;
var amountVsUtxoRatio = netInputAmount / txpAmount; var amountVsUtxoRatio = netInputAmount / txpAmount;
log.debug('Fee/Tx amount: ' + Utils.formatRatio(feeVsAmountRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR) + ')'); //log.debug('Fee/Tx amount: ' + Utils.formatRatio(feeVsAmountRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR) + ')');
log.debug('Tx amount/Input amount:' + Utils.formatRatio(amountVsUtxoRatio) + ' (min: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) + ')'); //log.debug('Tx amount/Input amount:' + Utils.formatRatio(amountVsUtxoRatio) + ' (min: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) + ')');
if (txpSize / 1000. > Defaults.MAX_TX_SIZE_IN_KB) { if (txpSize / 1000. > Defaults.MAX_TX_SIZE_IN_KB) {
log.debug('Breaking because tx size (' + Utils.formatSize(txpSize) + ') is too big (max: ' + Utils.formatSize(Defaults.MAX_TX_SIZE_IN_KB * 1000.) + ')'); //log.debug('Breaking because tx size (' + Utils.formatSize(txpSize) + ') is too big (max: ' + Utils.formatSize(Defaults.MAX_TX_SIZE_IN_KB * 1000.) + ')');
error = Errors.TX_MAX_SIZE_EXCEEDED; error = Errors.TX_MAX_SIZE_EXCEEDED;
return false; return false;
} }
if (!_.isEmpty(bigInputs)) { if (!_.isEmpty(bigInputs)) {
if (amountVsUtxoRatio < Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) { if (amountVsUtxoRatio < Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) {
log.debug('Breaking because utxo is too small compared to tx amount'); //log.debug('Breaking because utxo is too small compared to tx amount');
return false; return false;
} }
if (feeVsAmountRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR) { if (feeVsAmountRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR) {
var feeVsSingleInputFeeRatio = fee / (baseTxpFee + feePerInput); var feeVsSingleInputFeeRatio = fee / (baseTxpFee + feePerInput);
log.debug('Fee/Single-input fee: ' + Utils.formatRatio(feeVsSingleInputFeeRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR) + ')' + ' loses wrt single-input tx: ' + Utils.formatAmountInBtc((selected.length - 1) * feePerInput)); //log.debug('Fee/Single-input fee: ' + Utils.formatRatio(feeVsSingleInputFeeRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR) + ')' + ' loses wrt single-input tx: ' + Utils.formatAmountInBtc((selected.length - 1) * feePerInput));
if (feeVsSingleInputFeeRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR) { if (feeVsSingleInputFeeRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR) {
log.debug('Breaking because fee is too significant compared to tx amount and it is too expensive compared to using single input'); //log.debug('Breaking because fee is too significant compared to tx amount and it is too expensive compared to using single input');
return false; return false;
} }
} }
} }
log.debug('Cumuled total so far: ' + Utils.formatAmountInBtc(total) + ', Net total so far: ' + Utils.formatAmountInBtc(netTotal)); //log.debug('Cumuled total so far: ' + Utils.formatAmountInBtc(total) + ', Net total so far: ' + Utils.formatAmountInBtc(netTotal));
if (netTotal >= txpAmount) { if (netTotal >= txpAmount) {
var changeAmount = Math.round(total - txpAmount - fee); var changeAmount = Math.round(total - txpAmount - fee);
log.debug('Tx change: ', Utils.formatAmountInBtc(changeAmount)); //log.debug('Tx change: ', Utils.formatAmountInBtc(changeAmount));
var dustThreshold = Math.max(Defaults.MIN_OUTPUT_AMOUNT, Bitcore_[txp.coin].Transaction.DUST_AMOUNT); var dustThreshold = Math.max(Defaults.MIN_OUTPUT_AMOUNT, Bitcore_[txp.coin].Transaction.DUST_AMOUNT);
if (changeAmount > 0 && changeAmount <= dustThreshold) { if (changeAmount > 0 && changeAmount <= dustThreshold) {
log.debug('Change below dust threshold (' + Utils.formatAmountInBtc(dustThreshold) + '). Incrementing fee to remove change.'); //log.debug('Change below dust threshold (' + Utils.formatAmountInBtc(dustThreshold) + '). Incrementing fee to remove change.');
// Remove dust change by incrementing fee // Remove dust change by incrementing fee
fee += changeAmount; fee += changeAmount;
} }
@ -1874,12 +1900,12 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
}); });
if (netTotal < txpAmount) { if (netTotal < txpAmount) {
log.debug('Could not reach Txp total (' + Utils.formatAmountInBtc(txpAmount) + '), still missing: ' + Utils.formatAmountInBtc(txpAmount - netTotal)); //log.debug('Could not reach Txp total (' + Utils.formatAmountInBtc(txpAmount) + '), still missing: ' + Utils.formatAmountInBtc(txpAmount - netTotal));
selected = []; selected = [];
if (!_.isEmpty(bigInputs)) { if (!_.isEmpty(bigInputs)) {
var input = _.first(bigInputs); var input = _.first(bigInputs);
log.debug('Using big input: ', Utils.formatUtxos(input)); //log.debug('Using big input: ', Utils.formatUtxos(input));
total = input.satoshis; total = input.satoshis;
fee = Math.round(baseTxpFee + feePerInput); fee = Math.round(baseTxpFee + feePerInput);
netTotal = total - fee; netTotal = total - fee;
@ -1888,14 +1914,14 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
} }
if (_.isEmpty(selected)) { if (_.isEmpty(selected)) {
log.debug('Could not find enough funds within this utxo subset'); //log.debug('Could not find enough funds within this utxo subset');
return cb(error || Errors.INSUFFICIENT_FUNDS_FOR_FEE); return cb(error || Errors.INSUFFICIENT_FUNDS_FOR_FEE);
} }
return cb(null, selected, fee); return cb(null, selected, fee);
}; };
log.debug('Selecting inputs for a ' + Utils.formatAmountInBtc(txp.getTotalAmount()) + ' txp'); //log.debug('Selecting inputs for a ' + Utils.formatAmountInBtc(txp.getTotalAmount()) + ' txp');
self._getUtxosForCurrentWallet({}, function(err, utxos) { self._getUtxosForCurrentWallet({}, function(err, utxos) {
if (err) return cb(err); if (err) return cb(err);
@ -1917,7 +1943,7 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
utxos = sanitizeUtxos(utxos); utxos = sanitizeUtxos(utxos);
log.debug('Considering ' + utxos.length + ' utxos (' + Utils.formatUtxos(utxos) + ')'); //log.debug('Considering ' + utxos.length + ' utxos (' + Utils.formatUtxos(utxos) + ')');
var groups = [6, 1]; var groups = [6, 1];
if (!txp.excludeUnconfirmedUtxos) groups.push(0); if (!txp.excludeUnconfirmedUtxos) groups.push(0);
@ -1936,21 +1962,21 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
return utxo.confirmations >= group; return utxo.confirmations >= group;
}); });
log.debug('Group >= ' + group); //log.debug('Group >= ' + group);
// If this group does not have any new elements, skip it // If this group does not have any new elements, skip it
if (lastGroupLength === candidateUtxos.length) { if (lastGroupLength === candidateUtxos.length) {
log.debug('This group is identical to the one already explored'); //log.debug('This group is identical to the one already explored');
return next(); return next();
} }
log.debug('Candidate utxos: ' + Utils.formatUtxos(candidateUtxos)); //log.debug('Candidate utxos: ' + Utils.formatUtxos(candidateUtxos));
lastGroupLength = candidateUtxos.length; lastGroupLength = candidateUtxos.length;
select(candidateUtxos, function(err, selectedInputs, selectedFee) { select(candidateUtxos, function(err, selectedInputs, selectedFee) {
if (err) { if (err) {
log.debug('No inputs selected on this group: ', err); //log.debug('No inputs selected on this group: ', err);
selectionError = err; selectionError = err;
return next(); return next();
} }
@ -1959,8 +1985,8 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
inputs = selectedInputs; inputs = selectedInputs;
fee = selectedFee; fee = selectedFee;
log.debug('Selected inputs from this group: ' + Utils.formatUtxos(inputs)); //log.debug('Selected inputs from this group: ' + Utils.formatUtxos(inputs));
log.debug('Fee for this selection: ' + Utils.formatAmountInBtc(fee)); //log.debug('Fee for this selection: ' + Utils.formatAmountInBtc(fee));
return next(); return next();
}); });
@ -1975,9 +2001,9 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
if (!err) { if (!err) {
var change = _.sum(txp.inputs, 'satoshis') - _.sum(txp.outputs, 'amount') - txp.fee; var change = _.sum(txp.inputs, 'satoshis') - _.sum(txp.outputs, 'amount') - txp.fee;
log.debug('Successfully built transaction. Total fees: ' + Utils.formatAmountInBtc(txp.fee) + ', total change: ' + Utils.formatAmountInBtc(change)); self.logi('Successfully built transaction. Total fees: ' + Utils.formatAmountInBtc(txp.fee) + ', total change: ' + Utils.formatAmountInBtc(change));
} else { } else {
log.warn('Error building transaction', err); self.logw('Error building transaction', err);
} }
return cb(err); return cb(err);
@ -2008,7 +2034,7 @@ WalletService.prototype._canCreateTx = function(cb) {
var backoffTime = Defaults.BACKOFF_TIME; var backoffTime = Defaults.BACKOFF_TIME;
if (timeSinceLastRejection <= backoffTime) if (timeSinceLastRejection <= backoffTime)
log.debug('Not allowing to create TX: timeSinceLastRejection/backoffTime', timeSinceLastRejection, backoffTime); self.logi('Not allowing to create TX: timeSinceLastRejection/backoffTime', timeSinceLastRejection, backoffTime);
return cb(null, timeSinceLastRejection > backoffTime); return cb(null, timeSinceLastRejection > backoffTime);
}); });
@ -2061,7 +2087,6 @@ WalletService.prototype._validateAndSanitizeTxOpts = function(wallet, opts, cb)
return next(new ClientError('Only one of feeLevel/feePerKb/fee can be specified')); return next(new ClientError('Only one of feeLevel/feePerKb/fee can be specified'));
if (feeArgs == 0) { if (feeArgs == 0) {
log.debug('No fee provided, using "normal" fee level');
opts.feeLevel = 'normal'; opts.feeLevel = 'normal';
} }
@ -2133,7 +2158,7 @@ WalletService.prototype._getFeePerKb = function(wallet, opts, cb) {
}); });
if (!level) { if (!level) {
var msg = 'Could not compute fee for "' + opts.feeLevel + '" level'; var msg = 'Could not compute fee for "' + opts.feeLevel + '" level';
log.error(msg); self.logw(msg);
return cb(new ClientError(msg)); return cb(new ClientError(msg));
} }
return cb(null, level.feePerKb); return cb(null, level.feePerKb);
@ -2369,7 +2394,7 @@ WalletService.prototype.getTx = function(opts, cb) {
self.storage.fetchTxNote(self.walletId, txp.txid, function(err, note) { self.storage.fetchTxNote(self.walletId, txp.txid, function(err, note) {
if (err) { if (err) {
log.warn('Error fetching tx note for ' + txp.txid); self.logw('Error fetching tx note for ' + txp.txid);
} }
txp.note = note; txp.note = note;
return cb(null, txp); return cb(null, txp);
@ -2572,18 +2597,16 @@ WalletService.prototype.signTx = function(opts, cb) {
try { try {
if (!txp.sign(self.copayerId, opts.signatures, copayer.xPubKey)) { if (!txp.sign(self.copayerId, opts.signatures, copayer.xPubKey)) {
log.warn('Error signing transaction (BAD_SIGNATURES)'); self.logw('Error signing transaction (BAD_SIGNATURES)');
log.warn('Wallet id:', self.walletId); self.logw('Client version:', self.clientVersion);
log.warn('Copayer id:', self.copayerId); self.logw('Arguments:', JSON.stringify(opts));
log.warn('Client version:', self.clientVersion); self.logw('Transaction proposal:', JSON.stringify(txp));
log.warn('Arguments:', JSON.stringify(opts));
log.warn('Transaction proposal:', JSON.stringify(txp));
var raw = txp.getBitcoreTx().uncheckedSerialize(); var raw = txp.getBitcoreTx().uncheckedSerialize();
log.warn('Raw tx:', raw); self.logw('Raw tx:', raw);
return cb(Errors.BAD_SIGNATURES); return cb(Errors.BAD_SIGNATURES);
} }
} catch (ex) { } catch (ex) {
log.error('Error signing transaction proposal', ex); self.logw('Error signing transaction proposal', ex);
return cb(ex); return cb(ex);
} }
@ -3092,6 +3115,9 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
var addressStrs = _.map(addresses, 'address'); var addressStrs = _.map(addresses, 'address');
var bc = self._getBlockchainExplorer(wallet.coin, wallet.network); var bc = self._getBlockchainExplorer(wallet.coin, wallet.network);
if (!bc) return next(new Error('Could not get blockchain explorer instance')); if (!bc) return next(new Error('Could not get blockchain explorer instance'));
self.logi('','Querying tx for: %s addrs', addresses.length);
bc.getTransactions(addressStrs, from, to, function(err, rawTxs, total) { bc.getTransactions(addressStrs, from, to, function(err, rawTxs, total) {
if (err) return next(err); if (err) return next(err);
@ -3149,13 +3175,13 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
network: wallet.network network: wallet.network
}, function(err, levels) { }, function(err, levels) {
if (err) { if (err) {
log.warn('Could not fetch fee levels', err); self.logw('Could not fetch fee levels', err);
} else { } else {
var level = _.find(levels, { var level = _.find(levels, {
level: 'superEconomy' level: 'superEconomy'
}); });
if (!level || !level.nbBlocks) { if (!level || !level.nbBlocks) {
log.debug('Cannot compute super economy fee level from blockchain'); self.logi('Cannot compute super economy fee level from blockchain');
} else { } else {
var minFeePerKb = level.feePerKb; var minFeePerKb = level.feePerKb;
_.each(unconfirmed, function(tx) { _.each(unconfirmed, function(tx) {
@ -3217,10 +3243,10 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
tagLowFees(wallet, finalTxs, function(err) { tagLowFees(wallet, finalTxs, function(err) {
if (err) if (err)
log.warn('Failed to tag unconfirmed with low fee'); self.logw('Failed to tag unconfirmed with low fee');
if (res.txs.fromCache) if (res.txs.fromCache)
log.debug("History from cache for:", self.walletId, from, to); self.logi("History from cache for:", self.walletId, from, to);
return cb(null, finalTxs, !!res.txs.fromCache); return cb(null, finalTxs, !!res.txs.fromCache);
}); });
@ -3253,7 +3279,7 @@ WalletService.prototype.scan = function(opts, cb) {
var gap = Defaults.SCAN_ADDRESS_GAP; var gap = Defaults.SCAN_ADDRESS_GAP;
async.whilst(function() { async.whilst(function() {
log.debug('Scanning addr gap:'+ inactiveCounter); self.logi('Scanning addr gap:'+ inactiveCounter);
return inactiveCounter < gap; return inactiveCounter < gap;
}, function(next) { }, function(next) {
var address = derivator.derive(); var address = derivator.derive();

Loading…
Cancel
Save