Created
June 28, 2014 20:43
-
-
Save wanderer/dc9d384bb01430f8cf8c to your computer and use it in GitHub Desktop.
dumps ethereum cpp block db in json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//npm install rlp | |
//npm install levelup | |
//usage | |
//node ./dumpBlocks.js > blocks.json | |
var rlp = require('rlp'); | |
var levelup = require('levelup'); | |
var db = levelup('/path/to/home/.ethereum/blocks'); | |
var blocks = []; | |
db.createReadStream({ | |
keyEncoding: 'binary', | |
valueEncoding: 'binary' | |
}).on('data', function (data) { | |
var block = rlp.decode(data.value); | |
block = buffersToStrings(block); | |
blocks.push({ | |
hash: data.key.toString('hex'), | |
serialized: data.value.toString('hex'), | |
block: block | |
}); | |
//console.log(data.key.toString('hex')); | |
}).on('error', function (err) { | |
console.log('Oh my!', err); | |
}).on('end', function(){ | |
console.log(JSON.stringify(blocks)); | |
}); | |
var buffersToStrings = function (ba) { | |
//ba = buffer array | |
if (Buffer.isBuffer(ba)) { | |
return ba.toString('hex'); | |
} else if (ba instanceof Array) { | |
var array = []; | |
for (var i = 0; i < ba.length; i++) { | |
array.push(buffersToStrings(ba[i])); | |
} | |
return array; | |
} else { | |
console.error('WTF: ' + ba); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment