Skip to content

Commit

Permalink
Decouples technical statistics template from blockchain.info data format
Browse files Browse the repository at this point in the history
  • Loading branch information
selaux committed May 9, 2014
1 parent 4d26c5a commit baced3b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/modules/revenue/solo.js
Expand Up @@ -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'
});
Expand Down
13 changes: 9 additions & 4 deletions lib/modules/technical/blockchainInfo.js
Expand Up @@ -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']
});
});
}

Expand Down
12 changes: 5 additions & 7 deletions templates/technical.hbs
Expand Up @@ -4,23 +4,21 @@
<div class="panel-body row">
<dl class="dl-horizontal col-xs-12 col-md-4">
<dt>Total Hashrate:</dt>
<dd>{{hashrate hash_rate}}</dd>
<dd>{{hashrate networkHashrate}}</dd>
<dt>Difficulty:</dt>
<dd>{{number difficulty precision="2"}}</dd>
</dl>
<dl class="dl-horizontal col-xs-12 col-md-4">
<dt>Blockchain Length:</dt>
<dd>{{number n_blocks_total}}</dd>
<dd>{{number blockChainLength}}</dd>
<dt>Time between Blocks:</dt>
<dd>{{number minutes_between_blocks precision="2"}} Minutes</dd>
<dd>{{number timeBetweenBlocks precision="2"}} Minutes</dd>
</dl>
<dl class="dl-horizontal col-xs-12 col-md-4">
<dt>Number of Transactions:</dt>
<dd>{{number n_tx}}</dd>
<dd>{{number numberOfTransactions}}</dd>
<dt>Total Output Volume:</dt>
<dd>{{number total_btc_sent}} BTC</dd>
<dt>Estimated Transaction Volume:</dt>
<dd>{{number estimated_btc_sent precision="2"}} BTC</dd>
<dd>{{number totalTransactionValue}} BTC</dd>
</dl>
</div>
<footer class="text-muted">Updated: {{time lastUpdated}}</footer>
10 changes: 5 additions & 5 deletions test/specs/lib/modules/revenue/soloSpec.js
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand Down Expand Up @@ -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 () {
Expand Down
21 changes: 14 additions & 7 deletions test/specs/lib/modules/technical/blockchainInfoSpec.js
@@ -1,15 +1,17 @@
'use strict';

var _ = require('lodash'),
chai = require('chai'),
var chai = require('chai'),
sinon = require('sinon'),
sinonChai = require('sinon-chai'),
expect = chai.expect,
SandboxedModule = require('sandboxed-module'),

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
},
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit baced3b

Please sign in to comment.