From c85111c5b2a983fdb09f89ddd3b7c74ad34e21f0 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 23 Jul 2015 09:23:31 -0300 Subject: [PATCH 1/3] remove emergency level --- lib/server.js | 20 ++++++-------------- test/integration/server.js | 21 +++++++++------------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/server.js b/lib/server.js index a5070ae..6998dec 100644 --- a/lib/server.js +++ b/lib/server.js @@ -793,25 +793,17 @@ WalletService.prototype.getFeeLevels = function(opts, cb) { return cb(new ClientError('Invalid network')); var levels = [{ - name: 'emergency', - nbBlocks: 1, - modifier: 1.5, - defaultValue: 50000 - }, { name: 'priority', nbBlocks: 1, - modifier: 1, - defaultValue: 20000 + defaultValue: 50000 }, { name: 'normal', - nbBlocks: 3, - modifier: 1, - defaultValue: 10000 + nbBlocks: 4, + defaultValue: 20000 }, { name: 'economy', - nbBlocks: 10, - modifier: 1, - defaultValue: 5000 + nbBlocks: 12, + defaultValue: 10000 }, ]; var samplePoints = _.uniq(_.pluck(levels, 'nbBlocks')); @@ -822,7 +814,7 @@ WalletService.prototype.getFeeLevels = function(opts, cb) { feePerKB = level.defaultValue; } else { var sample = feeSamples[level.nbBlocks]; - feePerKB = (sample < 0) ? level.defaultValue : sample * level.modifier; + feePerKB = (sample < 0) ? level.defaultValue : sample; } return { level: level.name, diff --git a/test/integration/server.js b/test/integration/server.js index c0f1b9e..e48e647 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1458,7 +1458,7 @@ describe('Wallet service', function() { }); }); - describe('#getFeeLevels', function() { + describe.only('#getFeeLevels', function() { var server, wallet; beforeEach(function(done) { helpers.createAndJoinWallet(1, 1, function(s, w) { @@ -1471,15 +1471,14 @@ describe('Wallet service', function() { it('should get current fee levels', function(done) { helpers.stubFeeLevels({ 1: 40000, - 3: 20000, - 10: 18000, + 4: 20000, + 12: 18000, }); server.getFeeLevels({}, function(err, fees) { should.not.exist(err); fees = _.zipObject(_.map(fees, function(item) { return [item.level, item.feePerKB]; })); - fees.emergency.should.equal(60000); fees.priority.should.equal(40000); fees.normal.should.equal(20000); fees.economy.should.equal(18000); @@ -1493,26 +1492,24 @@ describe('Wallet service', function() { fees = _.zipObject(_.map(fees, function(item) { return [item.level, item.feePerKB]; })); - fees.emergency.should.equal(50000); - fees.priority.should.equal(20000); - fees.normal.should.equal(10000); - fees.economy.should.equal(5000); + fees.priority.should.equal(50000); + fees.normal.should.equal(20000); + fees.economy.should.equal(10000); done(); }); }); it('should get default fees if network cannot estimate (returns -1)', function(done) { helpers.stubFeeLevels({ 1: -1, - 3: 18000, - 10: 0, + 4: 18000, + 12: 0, }); server.getFeeLevels({}, function(err, fees) { should.not.exist(err); fees = _.zipObject(_.map(fees, function(item) { return [item.level, item.feePerKB]; })); - fees.emergency.should.equal(50000); - fees.priority.should.equal(20000); + fees.priority.should.equal(50000); fees.normal.should.equal(18000); fees.economy.should.equal(0); done(); From 86d1818940eb9943929de07f4d4330dd2f4f78b5 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 23 Jul 2015 09:25:52 -0300 Subject: [PATCH 2/3] send back nbBlocks for each level --- lib/server.js | 1 + test/integration/server.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/server.js b/lib/server.js index 6998dec..8ed97d2 100644 --- a/lib/server.js +++ b/lib/server.js @@ -819,6 +819,7 @@ WalletService.prototype.getFeeLevels = function(opts, cb) { return { level: level.name, feePerKB: feePerKB, + nbBlocks: level.nbBlocks, }; }); diff --git a/test/integration/server.js b/test/integration/server.js index e48e647..45e851b 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1458,7 +1458,7 @@ describe('Wallet service', function() { }); }); - describe.only('#getFeeLevels', function() { + describe('#getFeeLevels', function() { var server, wallet; beforeEach(function(done) { helpers.createAndJoinWallet(1, 1, function(s, w) { @@ -1477,11 +1477,16 @@ describe('Wallet service', function() { server.getFeeLevels({}, function(err, fees) { should.not.exist(err); fees = _.zipObject(_.map(fees, function(item) { - return [item.level, item.feePerKB]; + return [item.level, item]; })); - fees.priority.should.equal(40000); - fees.normal.should.equal(20000); - fees.economy.should.equal(18000); + fees.priority.feePerKB.should.equal(40000); + fees.priority.nbBlocks.should.equal(1); + + 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(); }); }); From fc94c2e0cf640d9f3f2e75cdc1be9b37832d962e Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 23 Jul 2015 11:02:34 -0300 Subject: [PATCH 3/3] return nbBlocks = null when fee level is unavailable --- lib/server.js | 34 ++++++++++------------------------ package.json | 4 ++-- test/integration/server.js | 13 +++++++++---- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/lib/server.js b/lib/server.js index 8ed97d2..49dd387 100644 --- a/lib/server.js +++ b/lib/server.js @@ -792,35 +792,21 @@ WalletService.prototype.getFeeLevels = function(opts, cb) { if (network != 'livenet' && network != 'testnet') return cb(new ClientError('Invalid network')); - var levels = [{ - name: 'priority', - nbBlocks: 1, - defaultValue: 50000 - }, { - name: 'normal', - nbBlocks: 4, - defaultValue: 20000 - }, { - name: 'economy', - nbBlocks: 12, - defaultValue: 10000 - }, ]; - + var levels = WalletUtils.FEE_LEVELS; var samplePoints = _.uniq(_.pluck(levels, 'nbBlocks')); self._sampleFeeLevels(network, samplePoints, function(err, feeSamples) { var values = _.map(levels, function(level) { - var feePerKB; - if (err) { - feePerKB = level.defaultValue; - } else { - var sample = feeSamples[level.nbBlocks]; - feePerKB = (sample < 0) ? level.defaultValue : sample; - } - return { + var result = { level: level.name, - feePerKB: feePerKB, - nbBlocks: level.nbBlocks, }; + 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); diff --git a/package.json b/package.json index 12c0032..4e837c3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "bitcore-wallet-service", "description": "A service for Mutisig HD Bitcoin Wallets", "author": "BitPay Inc", - "version": "0.0.45", + "version": "0.0.46", "keywords": [ "bitcoin", "copay", @@ -20,7 +20,7 @@ "dependencies": { "async": "^0.9.0", "bitcore": "^0.12.9", - "bitcore-wallet-utils": "^0.0.21", + "bitcore-wallet-utils": "^0.0.22", "body-parser": "^1.11.0", "coveralls": "^2.11.2", "email-validator": "^1.0.1", diff --git a/test/integration/server.js b/test/integration/server.js index 45e851b..9109053 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1512,11 +1512,16 @@ describe('Wallet service', function() { server.getFeeLevels({}, function(err, fees) { should.not.exist(err); fees = _.zipObject(_.map(fees, function(item) { - return [item.level, item.feePerKB]; + return [item.level, item]; })); - fees.priority.should.equal(50000); - fees.normal.should.equal(18000); - fees.economy.should.equal(0); + fees.priority.feePerKB.should.equal(50000); + should.not.exist(fees.priority.nbBlocks); + + 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(); }); });