From baced3b88629b057063ef5d6a244cedfa6b97a76 Mon Sep 17 00:00:00 2001 From: Stefan Lau Date: Fri, 9 May 2014 22:21:35 +0200 Subject: [PATCH] Decouples technical statistics template from blockchain.info data format --- lib/modules/revenue/solo.js | 2 +- lib/modules/technical/blockchainInfo.js | 13 ++++++++---- templates/technical.hbs | 12 +++++------ test/specs/lib/modules/revenue/soloSpec.js | 10 ++++----- .../modules/technical/blockchainInfoSpec.js | 21 ++++++++++++------- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/lib/modules/revenue/solo.js b/lib/modules/revenue/solo.js index 08d09bd..4ca3ef8 100644 --- a/lib/modules/revenue/solo.js +++ b/lib/modules/revenue/solo.js @@ -64,7 +64,7 @@ module.exports = Module.extend({ currency = this.config.market ? this.marketData.currency : 'BTC'; this.set({ - value: this.technicalData.btcPerBlock * (24 * 60 * 60) * totalHashrate * 1e6 * this.technicalData.probability * ask, + value: this.technicalData.blockReward * (24 * 60 * 60) * totalHashrate * 1e6 * this.technicalData.probability * ask, currency: currency, interval: 'Day' }); diff --git a/lib/modules/technical/blockchainInfo.js b/lib/modules/technical/blockchainInfo.js index 92a4f65..403013f 100644 --- a/lib/modules/technical/blockchainInfo.js +++ b/lib/modules/technical/blockchainInfo.js @@ -64,11 +64,16 @@ module.exports = Module.extend({ } difficulty = responses[0].body.difficulty; - self.set(_.extend({}, responses[0].body, { - btcPerBlock: responses[1].body / 1e8, + self.set({ + blockReward: responses[1].body / 1e8, probability: 1 / (4295032833 * difficulty), - 'hash_rate': responses[0].body['hash_rate'] * 1e3 - })); + difficulty: difficulty, + networkHashrate: responses[0].body['hash_rate'] * 1e3, + blockChainLength: responses[0].body['n_blocks_total'], + timeBetweenBlocks: responses[0].body['minutes_between_blocks'], + numberOfTransactions: responses[0].body['n_tx'], + totalTransactionValue: responses[0].body['total_btc_sent'] + }); }); } diff --git a/templates/technical.hbs b/templates/technical.hbs index c9aa194..cd75224 100644 --- a/templates/technical.hbs +++ b/templates/technical.hbs @@ -4,23 +4,21 @@
Total Hashrate:
-
{{hashrate hash_rate}}
+
{{hashrate networkHashrate}}
Difficulty:
{{number difficulty precision="2"}}
Blockchain Length:
-
{{number n_blocks_total}}
+
{{number blockChainLength}}
Time between Blocks:
-
{{number minutes_between_blocks precision="2"}} Minutes
+
{{number timeBetweenBlocks precision="2"}} Minutes
Number of Transactions:
-
{{number n_tx}}
+
{{number numberOfTransactions}}
Total Output Volume:
-
{{number total_btc_sent}} BTC
-
Estimated Transaction Volume:
-
{{number estimated_btc_sent precision="2"}} BTC
+
{{number totalTransactionValue}} BTC
\ No newline at end of file diff --git a/test/specs/lib/modules/revenue/soloSpec.js b/test/specs/lib/modules/revenue/soloSpec.js index d79b333..0f0e083 100644 --- a/test/specs/lib/modules/revenue/soloSpec.js +++ b/test/specs/lib/modules/revenue/soloSpec.js @@ -31,7 +31,7 @@ describe('modules/revenue/solo', function () { minerId1: { averageHashrate: 0.5 * 1e-6 } }; solo.marketData = { ask: 100, currency: 'NMC' }; - solo.technicalData = { btcPerBlock: 10, probability: 0.0001 }; + solo.technicalData = { blockReward: 10, probability: 0.0001 }; solo.on('change', function () { expect(_.omit(solo.toJSON(), 'historicalData')).to.deep.equal({ @@ -49,7 +49,7 @@ describe('modules/revenue/solo', function () { var solo = new Solo(this.app, defaultConfig); solo.marketData = { ask: 100, currency: 'NMC' }; - solo.technicalData = { btcPerBlock: 10, probability: 0.0001 }; + solo.technicalData = { blockReward: 10, probability: 0.0001 }; solo.on('change', function () { expect(_.omit(solo.toJSON(), 'historicalData')).to.deep.equal({ @@ -67,7 +67,7 @@ describe('modules/revenue/solo', function () { var solo = new Solo(this.app, defaultConfig); solo.minerData = { minerId: { averageHashrate: 1e-6 } }; - solo.technicalData = { btcPerBlock: 10, probability: 0.0001 }; + solo.technicalData = { blockReward: 10, probability: 0.0001 }; solo.on('change', function () { expect(_.omit(solo.toJSON(), 'historicalData')).to.deep.equal({ @@ -87,7 +87,7 @@ describe('modules/revenue/solo', function () { technical: 'technicalId' }); - solo.technicalData = { btcPerBlock: 10, probability: 0.0001 }; + solo.technicalData = { blockReward: 10, probability: 0.0001 }; solo.on('change', function () { expect(_.omit(solo.toJSON(), 'historicalData')).to.deep.equal({ @@ -116,7 +116,7 @@ describe('modules/revenue/solo', function () { done(); }); - this.app.emit('update:data:technicalId', { btcPerBlock: 10, probability: 0.0001 }); + this.app.emit('update:data:technicalId', { blockReward: 10, probability: 0.0001 }); }); it('should set the title to "Revenue" when no title is set in config', function () { diff --git a/test/specs/lib/modules/technical/blockchainInfoSpec.js b/test/specs/lib/modules/technical/blockchainInfoSpec.js index f952ab0..221850c 100644 --- a/test/specs/lib/modules/technical/blockchainInfoSpec.js +++ b/test/specs/lib/modules/technical/blockchainInfoSpec.js @@ -1,7 +1,6 @@ 'use strict'; -var _ = require('lodash'), - chai = require('chai'), +var chai = require('chai'), sinon = require('sinon'), sinonChai = require('sinon-chai'), expect = chai.expect, @@ -9,7 +8,10 @@ var _ = require('lodash'), responses = {}, statsAnswer = { - some: 'stats', + 'n_blocks_total': 123, + 'minutes_between_blocks': 12, + 'n_tx': 10, + 'total_btc_sent': 1, difficulty: 100 * (1 / 4295032833), 'hash_rate': 123 }, @@ -41,11 +43,16 @@ describe('modules/technical/blockchainInfo', function () { var blockchainInfo = new BlockchainInfo(app); blockchainInfo.on('change', function () { - expect(blockchainInfo.toJSON()).to.deep.equal(_.extend({}, statsAnswer, { - btcPerBlock: 25, + expect(blockchainInfo.toJSON()).to.deep.equal({ + blockReward: 25, probability: 0.01, - 'hash_rate': 123000 - })); + difficulty: 100 * (1 / 4295032833), + networkHashrate: 123000, + blockChainLength: 123, + timeBetweenBlocks: 12, + numberOfTransactions: 10, + totalTransactionValue: 1 + }); expect(app.logger.debug).to.have.been.calledOnce; expect(app.logger.debug).to.have.been.calledWith( '%s - fetched data from blockchain.info',