change fee rounding strategy

This commit is contained in:
Ivan Socolsky 2015-08-11 16:52:10 -03:00
parent 48bfa24859
commit 3533b60e6b
2 changed files with 4 additions and 9 deletions

View File

@ -188,12 +188,9 @@ TxProposal.prototype.getEstimatedSize = function() {
}; };
TxProposal.prototype.estimateFee = function() { TxProposal.prototype.estimateFee = function() {
var fee = this.feePerKb * this.getEstimatedSize() / 1000;
var size = this.getEstimatedSize(); this.fee = parseInt(fee.toFixed(0));
var fee = this.feePerKb * size / 1000;
// Round up to nearest bit
this.fee = parseInt((Math.ceil(fee / 100) * 100).toFixed(0));
}; };
/** /**

View File

@ -2092,8 +2092,7 @@ describe('Wallet service', function() {
balance.lockedAmount.should.equal(0); balance.lockedAmount.should.equal(0);
balance.availableAmount.should.equal(helpers.toSatoshi(9)); balance.availableAmount.should.equal(helpers.toSatoshi(9));
balance.totalBytesToSendMax.should.equal(2896); balance.totalBytesToSendMax.should.equal(2896);
var sizeInKB = balance.totalBytesToSendMax / 1000; var fee = parseInt((balance.totalBytesToSendMax * 10000 / 1000).toFixed(0));
var fee = parseInt((Math.ceil(sizeInKB * 10000 / 100) * 100).toFixed(0));
var max = balance.availableAmount - fee; var max = balance.availableAmount - fee;
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', max / 1e8, null, TestData.copayers[0].privKey_1H_0); var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', max / 1e8, null, TestData.copayers[0].privKey_1H_0);
server.createTx(txOpts, function(err, tx) { server.createTx(txOpts, function(err, tx) {
@ -2123,8 +2122,7 @@ describe('Wallet service', function() {
balance.lockedAmount.should.equal(helpers.toSatoshi(4)); balance.lockedAmount.should.equal(helpers.toSatoshi(4));
balance.availableAmount.should.equal(helpers.toSatoshi(5)); balance.availableAmount.should.equal(helpers.toSatoshi(5));
balance.totalBytesToSendMax.should.equal(1653); balance.totalBytesToSendMax.should.equal(1653);
var sizeInKB = balance.totalBytesToSendMax / 1000; var fee = parseInt((balance.totalBytesToSendMax * 2000 / 1000).toFixed(0));
var fee = parseInt((Math.ceil(sizeInKB * 2000 / 100) * 100).toFixed(0));
var max = balance.availableAmount - fee; var max = balance.availableAmount - fee;
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', max / 1e8, null, TestData.copayers[0].privKey_1H_0, 2000); var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', max / 1e8, null, TestData.copayers[0].privKey_1H_0, 2000);
server.createTx(txOpts, function(err, tx) { server.createTx(txOpts, function(err, tx) {