Skip to content

Instantly share code, notes, and snippets.

@sontuphan
Created February 27, 2018 02:50
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 sontuphan/59b30e183f20c99562415f8b42693577 to your computer and use it in GitHub Desktop.
Save sontuphan/59b30e183f20c99562415f8b42693577 to your computer and use it in GitHub Desktop.
var db = global.db;
var ethBlock = require('ethereumjs-block');
var rlp = require('rlp');
var utils = require('./libs/utils');
var geth = require('./libs/geth');
var trie = require('./libs/trie');
/**
* 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);
// Check state root in db
trie.checkRoot(stateRoot);
var address = '0x6512b9E5ed91DbA434E19DBdeC4229bEBEa3e350';
var hash = utils.sha3(address).toString('hex');
console.log('Hash key:', hash, hash.length);
var keyAddress = utils.getNaked(hash);
trie.getInfoByAddress(stateRoot, keyAddress);
});
});
@CebuOPT
Copy link

CebuOPT commented Jun 20, 2018

I wonder where could I find your utils module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment