diff --git a/rpc/eth_api.go b/rpc/eth_api.go index 8f4a4335..7f812ac3 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -605,8 +605,14 @@ func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]inter var logs types.QueryETHLogs e.cliCtx.Codec.MustUnmarshalJSON(res, &logs) - // TODO: change hard coded indexing of bytes - bloomFilter := ethtypes.BytesToBloom(tx.TxResult.GetData()[20:]) + txData := tx.TxResult.GetData() + var bloomFilter ethtypes.Bloom + var contractAddress common.Address + if len(txData) >= 20 { + // TODO: change hard coded indexing of bytes + bloomFilter = ethtypes.BytesToBloom(txData[20:]) + contractAddress = common.BytesToAddress(txData[:20]) + } fields := map[string]interface{}{ "blockHash": blockHash, @@ -623,7 +629,6 @@ func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]inter "status": status, } - contractAddress := common.BytesToAddress(tx.TxResult.GetData()[:20]) if contractAddress != (common.Address{}) { // TODO: change hard coded indexing of first 20 bytes fields["contractAddress"] = contractAddress diff --git a/x/evm/types/state_transition.go b/x/evm/types/state_transition.go index 4edb3a57..408e8cbe 100644 --- a/x/evm/types/state_transition.go +++ b/x/evm/types/state_transition.go @@ -74,19 +74,6 @@ func (st StateTransition) TransitionCSDB(ctx sdk.Context) (sdk.Result, *big.Int) _, leftOverGas, vmerr = vmenv.Call(senderRef, *st.Recipient, st.Payload, gasLimit, st.Amount) } - // handle errors - if vmerr != nil { - return emint.ErrVMExecution(vmerr.Error()).Result(), nil - } - - // Refunds would happen here, if intended in future - - st.Csdb.Finalise(true) // Change to depend on config - - // Consume gas from evm execution - // Out of gas check does not need to be done here since it is done within the EVM execution - ctx.GasMeter().ConsumeGas(gasLimit-leftOverGas, "EVM execution consumption") - // Generate bloom filter to be saved in tx receipt data bloomInt := big.NewInt(0) var bloomFilter ethtypes.Bloom @@ -99,6 +86,21 @@ func (st StateTransition) TransitionCSDB(ctx sdk.Context) (sdk.Result, *big.Int) // TODO: coniditionally add either/ both of these to return data returnData := append(addr.Bytes(), bloomFilter.Bytes()...) + // handle errors + if vmerr != nil { + res := emint.ErrVMExecution(vmerr.Error()).Result() + res.Data = returnData + return res, nil + } + + // TODO: Refund unused gas here, if intended in future + + st.Csdb.Finalise(true) // Change to depend on config + + // Consume gas from evm execution + // Out of gas check does not need to be done here since it is done within the EVM execution + ctx.GasMeter().ConsumeGas(gasLimit-leftOverGas, "EVM execution consumption") + return sdk.Result{Data: returnData, GasUsed: st.GasLimit - leftOverGas}, bloomInt }