mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
FIX: Added receipt in ApplyMessage
This commit is contained in:
parent
bba7177261
commit
43c0685ac6
1 changed files with 29 additions and 26 deletions
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"github.com/ethereum/go-ethereum/core/tracing"
|
"github.com/ethereum/go-ethereum/core/tracing"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
|
@ -74,25 +75,6 @@ func ApplyMessage(
|
||||||
tracer *tracing.Hooks,
|
tracer *tracing.Hooks,
|
||||||
) (uint64, error) {
|
) (uint64, error) {
|
||||||
|
|
||||||
initialGas := msg.Gas()
|
|
||||||
|
|
||||||
blockContext := core.NewEVMBlockContext(header, chainContext, &header.Coinbase)
|
|
||||||
|
|
||||||
// Create a new environment which holds all relevant information
|
|
||||||
// about the transaction and calling mechanisms.
|
|
||||||
msgForCtx := core.Message{
|
|
||||||
To: msg.To(),
|
|
||||||
From: msg.From(),
|
|
||||||
Nonce: msg.Nonce(),
|
|
||||||
Value: msg.Value(),
|
|
||||||
GasLimit: msg.Gas(),
|
|
||||||
GasPrice: msg.GasPrice(),
|
|
||||||
SkipNonceChecks: false,
|
|
||||||
SkipFromEOACheck: false,
|
|
||||||
}
|
|
||||||
txContext := core.NewEVMTxContext(&msgForCtx)
|
|
||||||
vmenv := vm.NewEVM(blockContext, txContext, state, chainConfig, vm.Config{Tracer: tracer})
|
|
||||||
|
|
||||||
tx := types.NewTx(&types.LegacyTx{
|
tx := types.NewTx(&types.LegacyTx{
|
||||||
Nonce: msg.Nonce(),
|
Nonce: msg.Nonce(),
|
||||||
GasPrice: msg.GasPrice(),
|
GasPrice: msg.GasPrice(),
|
||||||
|
|
@ -103,19 +85,20 @@ func ApplyMessage(
|
||||||
})
|
})
|
||||||
state.SetTxContext(tx.Hash(), 0)
|
state.SetTxContext(tx.Hash(), 0)
|
||||||
|
|
||||||
// Notify tracers about transaction start (system call is already started at Bor level)
|
initialGas := msg.Gas()
|
||||||
|
|
||||||
|
blockContext := core.NewEVMBlockContext(header, chainContext, &header.Coinbase)
|
||||||
|
|
||||||
|
// Create a new environment which holds all relevant information
|
||||||
|
// about the transaction and calling mechanisms.
|
||||||
|
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, state, chainConfig, vm.Config{Tracer: tracer})
|
||||||
|
|
||||||
if tracer != nil {
|
if tracer != nil {
|
||||||
if tracer.OnTxStart != nil {
|
if tracer.OnTxStart != nil {
|
||||||
tracer.OnTxStart(vmenv.GetVMContext(), tx, msg.From())
|
tracer.OnTxStart(vmenv.GetVMContext(), tx, msg.From())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if tracer != nil && tracer.OnTxEnd != nil {
|
|
||||||
tracer.OnTxEnd(nil, nil)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// nolint : contextcheck
|
// nolint : contextcheck
|
||||||
// Apply the transaction to the current state (included in the env)
|
// Apply the transaction to the current state (included in the env)
|
||||||
ret, gasLeft, err := vmenv.Call(
|
ret, gasLeft, err := vmenv.Call(
|
||||||
|
|
@ -149,6 +132,26 @@ func ApplyMessage(
|
||||||
|
|
||||||
gasUsed := initialGas - gasLeft
|
gasUsed := initialGas - gasLeft
|
||||||
|
|
||||||
|
if tracer != nil {
|
||||||
|
blockHash := header.Hash()
|
||||||
|
cumulativeGasUsed := gasUsed
|
||||||
|
|
||||||
|
receipt := types.NewReceipt(nil, err != nil, cumulativeGasUsed)
|
||||||
|
receipt.TxHash = tx.Hash()
|
||||||
|
receipt.GasUsed = gasUsed
|
||||||
|
|
||||||
|
if msg.To() == nil {
|
||||||
|
receipt.ContractAddress = crypto.CreateAddress(vmenv.TxContext.Origin, tx.Nonce())
|
||||||
|
}
|
||||||
|
|
||||||
|
receipt.Logs = state.GetLogs(tx.Hash(), header.Number.Uint64(), blockHash)
|
||||||
|
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
||||||
|
receipt.BlockHash = blockHash
|
||||||
|
receipt.BlockNumber = header.Number
|
||||||
|
receipt.TransactionIndex = 0
|
||||||
|
tracer.OnTxEnd(receipt, nil)
|
||||||
|
}
|
||||||
|
|
||||||
return gasUsed, nil
|
return gasUsed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue