return both totalSize & confirmedSize

This commit is contained in:
Ivan Socolsky 2015-12-22 16:53:25 -03:00
parent 84e061521e
commit a002ff0cfc
2 changed files with 15 additions and 8 deletions

View File

@ -614,8 +614,8 @@ WalletService.prototype.joinWallet = function(opts, cb) {
}
if (_.find(wallet.copayers, {
xPubKey: opts.xPubKey
})) return cb(Errors.COPAYER_IN_WALLET);
xPubKey: opts.xPubKey
})) return cb(Errors.COPAYER_IN_WALLET);
if (wallet.copayers.length == wallet.n) return cb(Errors.WALLET_FULL);
@ -708,8 +708,8 @@ WalletService.prototype._canCreateAddress = function(ignoreMaxGap, cb) {
isChange: true
}), Defaults.MAX_MAIN_ADDRESS_GAP);
if (latestAddresses.length < Defaults.MAX_MAIN_ADDRESS_GAP || _.any(latestAddresses, {
hasActivity: true
})) return cb(null, true);
hasActivity: true
})) return cb(null, true);
var bc = self._getBlockchainExplorer(latestAddresses[0].network);
var activityFound = false;
@ -956,9 +956,14 @@ WalletService.prototype._computeBytesToSendMax = function(utxos, cb) {
requiredSignatures: wallet.m,
walletN: wallet.n,
});
txp.inputs = unlockedUtxos;
var size = txp.getEstimatedSize();
var size = {};
txp.inputs = unlockedUtxos;
size.all = txp.getEstimatedSize();
txp.inputs = _.filter(unlockedUtxos, 'confirmations');
size.confirmed = txp.getEstimatedSize();
return cb(null, size);
});
@ -992,7 +997,8 @@ WalletService.prototype._getBalanceFromAddresses = function(addresses, cb) {
if (err) {
log.error('Could not compute size of send max transaction', err);
}
balance.totalBytesToSendMax = _.isNumber(size) ? size : null;
balance.totalBytesToSendMax = _.isNumber(size.all) ? size.all : null;
balance.totalBytesToSendConfirmedMax = _.isNumber(size.confirmed) ? size.confirmed : null;
return cb(null, balance);
});
});

View File

@ -2555,7 +2555,7 @@ describe('Wallet service', function() {
});
});
it('should be able to send max amount', function(done) {
it.only('should be able to send max amount', function(done) {
helpers.stubUtxos(server, wallet, _.range(1, 10, 0), function() {
server.getBalance({}, function(err, balance) {
should.not.exist(err);
@ -2563,6 +2563,7 @@ describe('Wallet service', function() {
balance.lockedAmount.should.equal(0);
balance.availableAmount.should.equal(helpers.toSatoshi(9));
balance.totalBytesToSendMax.should.equal(2896);
balance.totalBytesToSendConfirmedMax.should.equal(2896);
var fee = parseInt((balance.totalBytesToSendMax * 10000 / 1000).toFixed(0));
var max = balance.availableAmount - fee;
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', max / 1e8, TestData.copayers[0].privKey_1H_0);