Skip to content

Commit

Permalink
Problem: nil pointer error with legacy tx format
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Nov 14, 2024
1 parent 4fb45a3 commit 60a80b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#558](https://github.com/crypto-org-chain/ethermint/pull/558) New tracer in predecessors to trace balance correctly when `debug_traceTransaction`.
* (rpc) [#559](https://github.com/crypto-org-chain/ethermint/pull/559) Use basefee of transaction height instead of minus one height when `debug_traceTransaction`.
* (ante) [#560](https://github.com/crypto-org-chain/ethermint/pull/560) Check gasWanted only in checkTx mode.
* (rpc) [#]() Fix nil pointer panic with legacy transaction format.

### Improvements

Expand Down
8 changes: 8 additions & 0 deletions x/evm/types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"

errorsmod "cosmossdk.io/errors"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/evmos/ethermint/types"
Expand Down Expand Up @@ -60,6 +61,9 @@ func (tx *EthereumTx) UnmarshalJSON(bz []byte) error {
}

func (tx EthereumTx) MarshalJSON() ([]byte, error) {
if tx.Transaction == nil {
return []byte("null"), nil
}
bz, err := tx.MarshalBinary()
if err != nil {
return nil, err
Expand All @@ -68,6 +72,10 @@ func (tx EthereumTx) MarshalJSON() ([]byte, error) {
}

func (tx EthereumTx) Validate() error {
if tx.Transaction == nil {
return errorsmod.Wrapf(errortypes.ErrInvalidRequest, "raw tx is missing")
}

// prevent txs with 0 gas to fill up the mempool
if tx.Gas() == 0 {
return errorsmod.Wrap(ErrInvalidGasLimit, "gas limit must not be zero")
Expand Down

0 comments on commit 60a80b7

Please sign in to comment.