This commit is contained in:
vahoo5 2023-05-22 16:42:24 +02:00
parent cc7ae16365
commit f73d698469
2 changed files with 8 additions and 11 deletions

View file

@ -161,7 +161,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv) return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv)
} }
func applyTransactionWithResult(msg *Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, msgTx *Message, usedGas *uint64, evm *vm.EVM) (*types.Receipt, *ExecutionResult, error) { func applyTransactionWithResult(msg *Message, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, msgTx *Message, usedGas *uint64, evm *vm.EVM, txHash common.Hash) (*types.Receipt, *ExecutionResult, error) {
// Create a new context to be used in the EVM environment. // Create a new context to be used in the EVM environment.
txContext := NewEVMTxContext(msg) txContext := NewEVMTxContext(msg)
evm.Reset(txContext, statedb) evm.Reset(txContext, statedb)
@ -197,14 +197,15 @@ func applyTransactionWithResult(msg *Message, config *params.ChainConfig, bc Cha
receipt.BlockHash = header.Hash() receipt.BlockHash = header.Hash()
receipt.BlockNumber = header.Number receipt.BlockNumber = header.Number
receipt.TransactionIndex = uint(statedb.TxIndex()) receipt.TransactionIndex = uint(statedb.TxIndex())
receipt.Logs = statedb.GetLogs(txHash, header.Number.Uint64(), header.Hash())
return receipt, result, err return receipt, result, err
} }
func ApplyTransactionWithResult(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, msg *Message, usedGas *uint64, cfg vm.Config) (*types.Receipt, *ExecutionResult, error) { func ApplyTransactionWithResult(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, msg *Message, usedGas *uint64, cfg vm.Config, txHash common.Hash) (*types.Receipt, *ExecutionResult, error) {
// Create a new context to be used in the EVM environment // Create a new context to be used in the EVM environment
blockContext := NewEVMBlockContext(header, bc, author) blockContext := NewEVMBlockContext(header, bc, author)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg) vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg)
receipt, result, err := applyTransactionWithResult(msg, config, bc, author, gp, statedb, header, msg, usedGas, vmenv) receipt, result, err := applyTransactionWithResult(msg, config, bc, author, gp, statedb, header, msg, usedGas, vmenv, txHash)
return receipt, result, err return receipt, result, err
} }

View file

@ -1351,9 +1351,7 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st
var totalGasUsed uint64 var totalGasUsed uint64
gasFees := new(big.Int) gasFees := new(big.Int)
for i, tx := range args.Transactions { for i, tx := range args.Transactions {
fmt.Println("tx", tx)
msg, err := tx.ToMessage(0, header.BaseFee) msg, err := tx.ToMessage(0, header.BaseFee)
fmt.Println("msg", msg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1361,7 +1359,7 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st
randomHash := common.HexToHash("0x" + strconv.Itoa(i)) randomHash := common.HexToHash("0x" + strconv.Itoa(i))
state.SetTxContext(randomHash, i) state.SetTxContext(randomHash, i)
receipt, result, err := core.ApplyTransactionWithResult(s.b.ChainConfig(), s.chain, &coinbase, gp, state, header, msg, &header.GasUsed, vmconfig) receipt, result, err := core.ApplyTransactionWithResult(s.b.ChainConfig(), s.chain, &coinbase, gp, state, header, msg, &header.GasUsed, vmconfig, randomHash)
if err != nil { if err != nil {
return nil, fmt.Errorf("err: %w; txhash %s", err, randomHash) return nil, fmt.Errorf("err: %w; txhash %s", err, randomHash)
} }
@ -1370,7 +1368,6 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st
if err != nil { if err != nil {
return nil, fmt.Errorf("err: %w; txhash %s", err, randomHash) return nil, fmt.Errorf("err: %w; txhash %s", err, randomHash)
} }
to := "0x"
logs := receipt.Logs logs := receipt.Logs
if logs == nil { if logs == nil {
logs = []*types.Log{} logs = []*types.Log{}
@ -1378,7 +1375,6 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st
jsonResult := map[string]interface{}{ jsonResult := map[string]interface{}{
"txHash": txHash, "txHash": txHash,
"gasUsed": receipt.GasUsed, "gasUsed": receipt.GasUsed,
"toAddress": to,
"logs": logs, "logs": logs,
} }
totalGasUsed += receipt.GasUsed totalGasUsed += receipt.GasUsed