Created
February 27, 2018 02:50
-
-
Save sontuphan/59b30e183f20c99562415f8b42693577 to your computer and use it in GitHub Desktop.
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
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); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wonder where could I find your utils module.