2020-06-28 06:10:27 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/core/rawdb"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/eth"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/params"
|
2020-08-19 11:46:20 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/turbo/adapter"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/turbo/transactions"
|
2020-06-28 06:10:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TraceTransaction returns the structured logs created during the execution of EVM
|
|
|
|
// and returns them as a JSON object.
|
|
|
|
func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash common.Hash, config *eth.TraceConfig) (interface{}, error) {
|
|
|
|
// Retrieve the transaction and assemble its EVM context
|
|
|
|
tx, blockHash, _, txIndex := rawdb.ReadTransaction(api.dbReader, hash)
|
|
|
|
if tx == nil {
|
|
|
|
return nil, fmt.Errorf("transaction %#x not found", hash)
|
|
|
|
}
|
2020-08-19 11:46:20 +00:00
|
|
|
getter := adapter.NewBlockGetter(api.dbReader)
|
|
|
|
chainContext := adapter.NewChainContext(api.dbReader)
|
|
|
|
msg, vmctx, ibs, _, err := transactions.ComputeTxEnv(ctx, getter, params.MainnetChainConfig, chainContext, api.db, blockHash, txIndex)
|
2020-06-28 06:10:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Trace the transaction and return
|
2020-08-19 11:46:20 +00:00
|
|
|
return transactions.TraceTx(ctx, msg, vmctx, ibs, config)
|
2020-06-28 06:10:27 +00:00
|
|
|
}
|