mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
remove unused code in pre api
This commit is contained in:
parent
f924a4e0cb
commit
c6c86f3398
1 changed files with 0 additions and 140 deletions
|
|
@ -3,64 +3,22 @@ package eth
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
txtrace "github.com/DeBankDeFi/etherlib/pkg/txtracev1"
|
|
||||||
txtrace2 "github.com/DeBankDeFi/etherlib/pkg/txtracev2"
|
txtrace2 "github.com/DeBankDeFi/etherlib/pkg/txtracev2"
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"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/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
|
||||||
// "github.com/DeBankDeFi/eth/txtrace"
|
|
||||||
"golang.org/x/crypto/sha3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type helpHash struct {
|
|
||||||
hashed hash.Hash
|
|
||||||
}
|
|
||||||
|
|
||||||
func newHash() *helpHash {
|
|
||||||
|
|
||||||
return &helpHash{hashed: sha3.NewLegacyKeccak256()}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *helpHash) Reset() {
|
|
||||||
h.hashed.Reset()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *helpHash) Update(key, val []byte) error {
|
|
||||||
h.hashed.Write(key)
|
|
||||||
h.hashed.Write(val)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *helpHash) Hash() common.Hash {
|
|
||||||
return common.BytesToHash(h.hashed.Sum(nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
type PreExecTx struct {
|
|
||||||
ChainId *big.Int
|
|
||||||
From, To, Data, Value, Gas, GasPrice, Nonce string
|
|
||||||
}
|
|
||||||
|
|
||||||
type preData struct {
|
|
||||||
block *types.Block
|
|
||||||
tx *types.Transaction
|
|
||||||
msg *core.Message
|
|
||||||
stateDb *state.StateDB
|
|
||||||
header *types.Header
|
|
||||||
}
|
|
||||||
|
|
||||||
// PreExecAPI provides pre exec info for rpc
|
// PreExecAPI provides pre exec info for rpc
|
||||||
type PreExecAPI struct {
|
type PreExecAPI struct {
|
||||||
e *Ethereum
|
e *Ethereum
|
||||||
|
|
@ -70,104 +28,6 @@ func NewPreExecAPI(e *Ethereum) *PreExecAPI {
|
||||||
return &PreExecAPI{e: e}
|
return &PreExecAPI{e: e}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PreExecAPI) getBlockAndMsg(origin *PreExecTx, header *types.Header) (*types.Block, *core.Message) {
|
|
||||||
toAddr := common.HexToAddress(origin.To)
|
|
||||||
|
|
||||||
tx := types.NewTx(&types.LegacyTx{
|
|
||||||
Nonce: hexutil.MustDecodeUint64(origin.Nonce),
|
|
||||||
To: &toAddr,
|
|
||||||
Value: hexutil.MustDecodeBig(origin.Value),
|
|
||||||
Gas: hexutil.MustDecodeUint64(origin.Gas),
|
|
||||||
GasPrice: hexutil.MustDecodeBig(origin.GasPrice),
|
|
||||||
Data: hexutil.MustDecode(origin.Data),
|
|
||||||
})
|
|
||||||
|
|
||||||
number := big.NewInt(header.Number.Int64() + 1)
|
|
||||||
block := types.NewBlock(
|
|
||||||
&types.Header{Number: number},
|
|
||||||
[]*types.Transaction{tx}, nil, nil, newHash())
|
|
||||||
|
|
||||||
msg, _ := core.TransactionToMessage(tx, types.MakeSigner(api.e.APIBackend.ChainConfig(), header.Number), header.BaseFee)
|
|
||||||
msg.IsPre = true
|
|
||||||
return block, msg
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *PreExecAPI) prepareData(ctx context.Context, origin *PreExecTx) (*preData, error) {
|
|
||||||
var (
|
|
||||||
d preData
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
bc := api.e.blockchain
|
|
||||||
d.header, err = api.e.APIBackend.HeaderByNumber(ctx, rpc.LatestBlockNumber)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
latestNumber := d.header.Number
|
|
||||||
parent := api.e.blockchain.GetBlockByNumber(latestNumber.Uint64())
|
|
||||||
d.stateDb, err = state.New(parent.Header().Root, bc.StateCache(), bc.Snapshots())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
d.block, d.msg = api.getBlockAndMsg(origin, d.header)
|
|
||||||
d.tx = d.block.Transactions()[0]
|
|
||||||
return &d, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *PreExecAPI) GetLogs(ctx context.Context, origin *PreExecTx) (*types.Receipt, error) {
|
|
||||||
var (
|
|
||||||
bc = api.e.blockchain
|
|
||||||
)
|
|
||||||
d, err := api.prepareData(ctx, origin)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
gas := d.tx.Gas()
|
|
||||||
gp := new(core.GasPool).AddGas(gas)
|
|
||||||
|
|
||||||
d.stateDb.SetTxContext(d.tx.Hash(), 0)
|
|
||||||
receipt, err := core.ApplyTransactionForPreExec(
|
|
||||||
bc.Config(), bc, nil, gp, d.stateDb, d.header, d.tx, &gas, *bc.GetVMConfig())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return receipt, receipt.Err
|
|
||||||
}
|
|
||||||
|
|
||||||
// TraceTransaction tracing pre-exec transaction object.
|
|
||||||
func (api *PreExecAPI) TraceTransaction(ctx context.Context, origin *PreExecTx) (interface{}, error) {
|
|
||||||
var (
|
|
||||||
bc = api.e.blockchain
|
|
||||||
tracer *txtrace.OeTracer
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
d, err := api.prepareData(ctx, origin)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
txContext := core.NewEVMTxContext(d.msg)
|
|
||||||
txIndex := 0
|
|
||||||
|
|
||||||
tracer = txtrace.NewOeTracer(nil)
|
|
||||||
// Run the transaction with tracing enabled.
|
|
||||||
vmenv := vm.NewEVM(core.NewEVMBlockContext(d.header, bc, nil), txContext, d.stateDb, bc.Config(), vm.Config{Tracer: tracer, PreExec: true})
|
|
||||||
vmenv.Context.BaseFee = big.NewInt(0)
|
|
||||||
vmenv.Context.BlockNumber.Add(vmenv.Context.BlockNumber, big.NewInt(rand.Int63n(6)+6))
|
|
||||||
vmenv.Context.Time += uint64(rand.Int63n(60) + 30)
|
|
||||||
|
|
||||||
// Call Prepare to clear out the statedb access list
|
|
||||||
d.stateDb.SetTxContext(d.tx.Hash(), 0)
|
|
||||||
|
|
||||||
tracer.SetMessage(d.block.Number(), d.block.Hash(), d.tx.Hash(), uint(txIndex), d.msg.From, d.msg.To, *d.msg.Value)
|
|
||||||
|
|
||||||
_, err = core.ApplyMessage(vmenv, d.msg, new(core.GasPool).AddGas(d.msg.GasLimit))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("tracing failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tracer.Finalize()
|
|
||||||
return tracer.GetResult(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UnKnown = 1000
|
UnKnown = 1000
|
||||||
InsufficientBalane = 1001
|
InsufficientBalane = 1001
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue