2020-06-28 06:10:27 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-08-29 15:50:24 +00:00
|
|
|
|
2020-06-28 06:10:27 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/core/rawdb"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/eth"
|
2020-10-24 08:09:20 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
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
|
|
|
)
|
|
|
|
|
2020-10-24 17:03:52 +00:00
|
|
|
// TraceTransaction implements debug_traceTransaction. Returns Geth style transaction traces.
|
2020-06-28 06:10:27 +00:00
|
|
|
func (api *PrivateDebugAPIImpl) TraceTransaction(ctx context.Context, hash common.Hash, config *eth.TraceConfig) (interface{}, error) {
|
2020-10-25 08:38:55 +00:00
|
|
|
tx, err := api.dbReader.Begin(ctx, ethdb.RO)
|
2020-10-10 12:24:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
2020-06-28 06:10:27 +00:00
|
|
|
// Retrieve the transaction and assemble its EVM context
|
2020-10-10 12:24:56 +00:00
|
|
|
txn, blockHash, _, txIndex := rawdb.ReadTransaction(tx, hash)
|
|
|
|
if txn == nil {
|
2020-06-28 06:10:27 +00:00
|
|
|
return nil, fmt.Errorf("transaction %#x not found", hash)
|
|
|
|
}
|
2020-10-10 12:24:56 +00:00
|
|
|
getter := adapter.NewBlockGetter(tx)
|
|
|
|
chainContext := adapter.NewChainContext(tx)
|
2020-11-08 05:46:53 +00:00
|
|
|
|
2021-01-02 19:28:22 +00:00
|
|
|
chainConfig, err := api.chainConfig(tx)
|
2020-11-08 05:46:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
msg, vmctx, ibs, _, err := transactions.ComputeTxEnv(ctx, getter, chainConfig, chainContext, tx.(ethdb.HasTx).Tx(), blockHash, txIndex)
|
2020-06-28 06:10:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Trace the transaction and return
|
2020-11-08 05:46:53 +00:00
|
|
|
return transactions.TraceTx(ctx, msg, vmctx, ibs, config, chainConfig)
|
2020-06-28 06:10:27 +00:00
|
|
|
}
|