Skip to content

Instantly share code, notes, and snippets.

View sontuphan's full-sized avatar

Phan Sơn Tự sontuphan

  • Ho Chi Minh City University of Technology (Bach Khoa)
  • Ho Chi Minh City
View GitHub Profile
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');
var merklePatriciaTree = require('merkle-patricia-tree');
var rlp = require('rlp');
var db = global.db;
var Trie = function () {}
Trie.getInfoByAddress = function (root, address) {
var root = new Buffer(root, 'hex');
var address = new Buffer(address, 'hex');
var trie = new merklePatriciaTree(db, root);
var path = require('path');
var levelup = require('levelup');
var leveldown = require('leveldown');
/**
* Level DB
*/
var levelDBPath = path.relative('./', '/Users/User/Library/Ethereum/ropsten/geth/chaindata');
var db = levelup(leveldown(levelDBPath));
@sontuphan
sontuphan / geth.js
Last active February 23, 2018 08:33
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
console.log("\n===========================================");
console.log("========== Geth connected:", web3.isConnected(), "===========");
console.log("===========================================\n");
var Geth = function () {}
Geth.getStateRoot = function (blockNumber) {
{
'cab8': 'dog',
'cabe': 'cat',
'39': 'chicken',
'395': 'duck',
'56f0': 'horse'
}
{
do: 0,
dog: 1,
dax: 2,
dogu: 3,
dodo: 4,
house: 5,
houses: 6
}
> [ 1, 2, 3, 4, 5]
'11 23 45'
> [ 0, 1, 2, 3, 4, 5]
'00 01 23 45'
> [ 0, f, 1, c, b, 8, 16]
'20 0f 1c b8'
> [ f, 1, c, b, 8, 16]
'3f 1c b8'
node type path length | prefix hexchar
--------------------------------------------------
extension even | 0000 0x0
extension odd | 0001 0x1
leaf even | 0010 0x2
leaf odd | 0011 0x3
Root: {1: 'Dog', 2: B, 3: A}
A: {1: C, 2: D, 3: 'Cat'}
B: {1: 'Goat', 2: 'Bear', 3: 'Rat'}
C: {1: 'Eagle', 2: 'Parrot', 3: E}
D: {1: 'Shark', 2: 'Dolphin', 3: 'Whale'}
E: {1: 'Duck', 2: 'Chinken', 3: 'Pig'}
// Hash algorithm is Keccak256
var s = Math.floor((Math.random() * 1000000000) + 1); // s = 830178382
var selection = ‘rock’;
var combination = selection + s; // combination = ‘rock830178382’
var hashOfCombination = keccak256(combination);
// hashOfCombination = 4d49bb261ecb887e152051da601d028e070635d24da07da2828fca8fecedee50