Browse Source

Merge pull request #299 from isocolsky/fee_levels

Improve fee levels
activeAddress
Gustavo Maximiliano Cortez 10 years ago
parent
commit
3aa39c0857
  1. 41
      lib/server.js
  2. 4
      package.json
  3. 43
      test/integration/server.js

41
lib/server.js

@ -792,42 +792,21 @@ WalletService.prototype.getFeeLevels = function(opts, cb) {
if (network != 'livenet' && network != 'testnet') if (network != 'livenet' && network != 'testnet')
return cb(new ClientError('Invalid network')); return cb(new ClientError('Invalid network'));
var levels = [{ var levels = WalletUtils.FEE_LEVELS;
name: 'emergency',
nbBlocks: 1,
modifier: 1.5,
defaultValue: 50000
}, {
name: 'priority',
nbBlocks: 1,
modifier: 1,
defaultValue: 20000
}, {
name: 'normal',
nbBlocks: 3,
modifier: 1,
defaultValue: 10000
}, {
name: 'economy',
nbBlocks: 10,
modifier: 1,
defaultValue: 5000
}, ];
var samplePoints = _.uniq(_.pluck(levels, 'nbBlocks')); var samplePoints = _.uniq(_.pluck(levels, 'nbBlocks'));
self._sampleFeeLevels(network, samplePoints, function(err, feeSamples) { self._sampleFeeLevels(network, samplePoints, function(err, feeSamples) {
var values = _.map(levels, function(level) { var values = _.map(levels, function(level) {
var feePerKB; var result = {
if (err) {
feePerKB = level.defaultValue;
} else {
var sample = feeSamples[level.nbBlocks];
feePerKB = (sample < 0) ? level.defaultValue : sample * level.modifier;
}
return {
level: level.name, level: level.name,
feePerKB: feePerKB,
}; };
if (err || feeSamples[level.nbBlocks] < 0) {
result.feePerKB = level.defaultValue;
result.nbBlocks = null;
} else {
result.feePerKB = feeSamples[level.nbBlocks];
result.nbBlocks = level.nbBlocks;
}
return result;
}); });
return cb(null, values); return cb(null, values);

4
package.json

@ -2,7 +2,7 @@
"name": "bitcore-wallet-service", "name": "bitcore-wallet-service",
"description": "A service for Mutisig HD Bitcoin Wallets", "description": "A service for Mutisig HD Bitcoin Wallets",
"author": "BitPay Inc", "author": "BitPay Inc",
"version": "0.0.45", "version": "0.0.46",
"keywords": [ "keywords": [
"bitcoin", "bitcoin",
"copay", "copay",
@ -20,7 +20,7 @@
"dependencies": { "dependencies": {
"async": "^0.9.0", "async": "^0.9.0",
"bitcore": "^0.12.9", "bitcore": "^0.12.9",
"bitcore-wallet-utils": "^0.0.21", "bitcore-wallet-utils": "^0.0.22",
"body-parser": "^1.11.0", "body-parser": "^1.11.0",
"coveralls": "^2.11.2", "coveralls": "^2.11.2",
"email-validator": "^1.0.1", "email-validator": "^1.0.1",

43
test/integration/server.js

@ -1471,18 +1471,22 @@ describe('Wallet service', function() {
it('should get current fee levels', function(done) { it('should get current fee levels', function(done) {
helpers.stubFeeLevels({ helpers.stubFeeLevels({
1: 40000, 1: 40000,
3: 20000, 4: 20000,
10: 18000, 12: 18000,
}); });
server.getFeeLevels({}, function(err, fees) { server.getFeeLevels({}, function(err, fees) {
should.not.exist(err); should.not.exist(err);
fees = _.zipObject(_.map(fees, function(item) { fees = _.zipObject(_.map(fees, function(item) {
return [item.level, item.feePerKB]; return [item.level, item];
})); }));
fees.emergency.should.equal(60000); fees.priority.feePerKB.should.equal(40000);
fees.priority.should.equal(40000); fees.priority.nbBlocks.should.equal(1);
fees.normal.should.equal(20000);
fees.economy.should.equal(18000); fees.normal.feePerKB.should.equal(20000);
fees.normal.nbBlocks.should.equal(4);
fees.economy.feePerKB.should.equal(18000);
fees.economy.nbBlocks.should.equal(12);
done(); done();
}); });
}); });
@ -1493,28 +1497,31 @@ describe('Wallet service', function() {
fees = _.zipObject(_.map(fees, function(item) { fees = _.zipObject(_.map(fees, function(item) {
return [item.level, item.feePerKB]; return [item.level, item.feePerKB];
})); }));
fees.emergency.should.equal(50000); fees.priority.should.equal(50000);
fees.priority.should.equal(20000); fees.normal.should.equal(20000);
fees.normal.should.equal(10000); fees.economy.should.equal(10000);
fees.economy.should.equal(5000);
done(); done();
}); });
}); });
it('should get default fees if network cannot estimate (returns -1)', function(done) { it('should get default fees if network cannot estimate (returns -1)', function(done) {
helpers.stubFeeLevels({ helpers.stubFeeLevels({
1: -1, 1: -1,
3: 18000, 4: 18000,
10: 0, 12: 0,
}); });
server.getFeeLevels({}, function(err, fees) { server.getFeeLevels({}, function(err, fees) {
should.not.exist(err); should.not.exist(err);
fees = _.zipObject(_.map(fees, function(item) { fees = _.zipObject(_.map(fees, function(item) {
return [item.level, item.feePerKB]; return [item.level, item];
})); }));
fees.emergency.should.equal(50000); fees.priority.feePerKB.should.equal(50000);
fees.priority.should.equal(20000); should.not.exist(fees.priority.nbBlocks);
fees.normal.should.equal(18000);
fees.economy.should.equal(0); fees.normal.feePerKB.should.equal(18000);
fees.normal.nbBlocks.should.equal(4);
fees.economy.feePerKB.should.equal(0);
fees.economy.nbBlocks.should.equal(12);
done(); done();
}); });
}); });

Loading…
Cancel
Save