Skip to content

Instantly share code, notes, and snippets.

@braydonf
Created June 25, 2015 23:14
Show Gist options
  • Save braydonf/103da488d14f88545798 to your computer and use it in GitHub Desktop.
Save braydonf/103da488d14f88545798 to your computer and use it in GitHub Desktop.
Latest Bitcoin Block Versions
var RpcClient = require('bitcoind-rpc');
var async = require('async');
var config = {
protocol: 'http',
user: 'bitcoin',
pass: 'local321',
host: '127.0.0.1',
port: '8332'
};
var rpc = new RpcClient(config);
rpc.getBlockCount(function(err, data) {
if (err) {
throw err;
}
var versionThrees = [];
var otherVersions = [];
var count = data.result;
var c = 0;
async.whilst(
function() {
return c < 1000;
},
function(callback) {
var height = count - c;
rpc.getBlockHash(count, function(err, data) {
if (err) {
throw err;
}
var hash = data.result;
rpc.getBlock(hash, function(err, data) {
if (err) {
throw err;
}
var block = data.result;
var version = block.version;
if (version === 3) {
versionThrees.push(version);
} else {
otherVersions.push(version);
}
c++;
callback();
});
});
},
function(err) {
if (err) {
throw err;
}
console.log('Block Version = 3:', versionThrees.length);
console.log('Block Version != 3:', otherVersions.length);
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment