2015-07-15 15:13:41 -07:00
|
|
|
'use strict';
|
|
|
|
|
2015-07-16 12:26:02 -07:00
|
|
|
var BitcoindJS = require('..');
|
|
|
|
var BitcoinNode = BitcoindJS.Node;
|
2015-07-15 15:13:41 -07:00
|
|
|
var chainlib = require('chainlib');
|
|
|
|
var log = chainlib.log;
|
2015-07-16 12:26:02 -07:00
|
|
|
//log.debug = function() {};
|
2015-07-15 15:13:41 -07:00
|
|
|
|
|
|
|
var configuration = {
|
2015-07-21 06:09:59 -07:00
|
|
|
datadir: process.env.BITCOINDJS_DIR || '~/.bitcoin',
|
|
|
|
testnet: true
|
2015-07-15 15:13:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
var node = new BitcoinNode(configuration);
|
|
|
|
|
|
|
|
var startHeight;
|
|
|
|
var count = 100;
|
2015-07-21 06:09:59 -07:00
|
|
|
var times = new Array(count);
|
2015-07-15 15:13:41 -07:00
|
|
|
|
|
|
|
node.on('ready', function() {
|
|
|
|
times[node.chain.tip.__height % count] = Date.now();
|
|
|
|
startHeight = node.chain.tip.__height;
|
|
|
|
});
|
|
|
|
|
|
|
|
node.on('error', function(err) {
|
|
|
|
log.error(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
node.chain.on('addblock', function(block) {
|
|
|
|
console.log('New Best Tip:', block.hash);
|
|
|
|
var startTime = times[node.chain.tip.__height % count];
|
|
|
|
|
|
|
|
if(startTime) {
|
|
|
|
var timeElapsed = (Date.now() - startTime) / 1000;
|
|
|
|
console.log(Math.round(count / timeElapsed) + ' blocks per second');
|
|
|
|
}
|
|
|
|
|
|
|
|
times[node.chain.tip.__height % count] = Date.now();
|
2015-07-21 06:09:59 -07:00
|
|
|
});
|