Skip to content

Instantly share code, notes, and snippets.

Created February 23, 2018 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/b8eb698e5befe7cf89ff9038f7d0eec1 to your computer and use it in GitHub Desktop.
Save anonymous/b8eb698e5befe7cf89ff9038f7d0eec1 to your computer and use it in GitHub Desktop.
var db = global.db;
var ethBlock = require('ethereumjs-block');
var utils = require('./libs/utils');
var geth = require('./libs/geth');
/**
* For debugging
*/
console.log("For debugging:");
geth.getStateRoot(2596315);
console.log("\n");
/**
* Constants
*/
const prefix = utils.stringToHex('h');
const suffix = utils.stringToHex('n');
/**
* Test leveldb
*/
var blockNumber = 2596315;
var hexBlockNumber = utils.padLeft(utils.decimalToHex(blockNumber), 16);
var keyString = prefix + hexBlockNumber + suffix;
var key = new Buffer(keyString, 'hex');
console.log('Block Number:', key);
db.get(key, function (er, value) {
if (er) throw new Error(er);
console.log('Block Hash:', value);
value = value.toString('hex');
var keyString = prefix + hexBlockNumber + value;
var key = new Buffer(keyString, 'hex');
db.get(key, function (er, value) {
if (er) throw new Error(er);
console.log('Raw Block Data:', value);
var block = new ethBlock.Header(value);
var stateRoot = block.stateRoot;
console.log('State Root:', stateRoot);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment