Skip to content

Instantly share code, notes, and snippets.

@enriquefynn
Created May 14, 2022 18:04
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 enriquefynn/7db8fed4fac13f087210226318cc9d99 to your computer and use it in GitHub Desktop.
Save enriquefynn/7db8fed4fac13f087210226318cc9d99 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"os"
"strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
)
var (
cache, _ = strconv.Atoi(os.Args[1])
ethDb, _ = ethdb.NewLDBDatabase(os.Args[1], cache, 256)
// executeDb, _ = ethdb.NewMemDatabase()
engine = ethash.NewFullFaker()
config = params.MainnetChainConfig
vmConfig = vm.Config{}
)
func main() {
blockchain, err := core.NewBlockChain(ethDb, nil, config, engine, vmConfig, func(block *types.Block) bool { return false })
st, err := blockchain.State()
if err != nil {
log.Fatalf("State bad: %v", err)
}
it := state.NewNodeIterator(st)
for it.Next() {
addr := common.BytesToAddress(it.Parent.Bytes())
code := st.GetCode(addr)
fmt.Printf("CODE[%x]: %v\n", addr, code)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment