0

I want to write a program that will do:

  • for the given txhash debug TraceTransaction and return that

What can i do in Go ?

Do you have any materials, a tutorial or can you give me tips on how to start?

I just want to have output like here: https://rinkeby.etherscan.io/vmtrace?txhash=0xbb7323b02276aeed76b22fa50e2eefb76d5647560b8c15f23541ec5990d0e855 but i want to do this in go and run this from "code" (for example "go run x.go txhash" ).

0

You should copy cmd/geth sources and create your own binary that would be your own node. To check an example look at this: https://github.com/Arachnid/etherquery but it is an old code and won't compile with current version of geth, however you will have an idea how to add Services to the Stack.

Once you have your node binary fully working, you write a function to process block transactions, something like this:

blockchain := ethereum.BlockChain()
block:=blockchain.GetBlockByNumber(uint64(383838))
statedb, err := blockchain.StateAt( blockchain.GetBlock( block.ParentHash(), block.NumberU64()-1).Root() )
if err != nil {
    return err
}

lcfg:=&vm.LogConfig{
    DisableMemory: false,
    DisableStack: false,
    DisableStorage: false,
    FullStorage: false,
}
vm_cfg:=&vm.Config{
    Debug: true,
    EnableJit: false,
    ForceJit: false,
}
gaspool:=new(core.GasPool).AddGas(block.GasLimit())
bconf:=blockchain.Config()
if bconf.DAOForkSupport && bconf.DAOForkBlock != nil && bconf.DAOForkBlock.Cmp(block.Number()) == 0 {
    misc.ApplyDAOHardFork(statedb)
}
for i, tx := range block.Transactions() {
    structLogger := vm.NewStructLogger(lcfg)
    vm_cfg.Tracer=structLogger
    statedb.Prepare(tx.Hash(), block.Hash(), i)

    receipt, gas, err := core.ApplyTransaction(bconf, blockchain, nil, gaspool, statedb, block.Header(), tx, totalUsedGas, *vm_cfg)
    if err != nil {
        return err
    }
    dump_StructLogs(statedb, tx, structLogger.StructLogs(), receipt)
}

where dump_StructLogs() is your output function which should print all instructions.

the code above was built from the Ethereum source code itself, so if you dig into it, you are going to find out how to do this.

  • But you build applications in your case. If I want to run it from the code. Is not it enough for me to write a wrapper in my case? (just import package from github ?) – EricEnticman Mar 4 '18 at 10:37
  • @EricEnticman transactions are inserted every 14 second, so you have to have a node running to receive new transactions. You could avoid running the node if you open the database yourself and read the blockchain data from it, this way you won't depend on the node functionality but someone must be feeding new transactions to this DB. Also, LevelDB locks the database so only one process can open it, you have to work around locking mechanism to be able to do what you want. But it is possible to do what you want, just more difficult to code – Nulik Mar 7 '18 at 3:58
  • state_processor.go and blockchain.go are the files that contain the functions that you need to do what you want, so try to include these files in your code, and then, as compile errors show up, copy the functions those files are asking, this way you could build the minimal code that would be needed to do what you want. but again, something must be inserting new transaction in the Level DB and I have no idea how are you going to fix that – Nulik Mar 7 '18 at 4:04
  • Okay, but if I want to run transaction trace on my local private blockchain, for example testrpc, Do I have to run my node then? There is a chance to write in js some function who return execute opcode ? for now I want to do something small, which I will be able to locally test. – EricEnticman Mar 12 '18 at 23:27
  • geth does have functions to trace transactions, check the API of the debug module, but by executing geth you are starting a node, unless you use --nodiscover – Nulik Mar 13 '18 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.