Skip to content

Commit

Permalink
Problem: nil pointer error with legacy tx format (#562)
Browse files Browse the repository at this point in the history
* Problem: nil pointer error with legacy tx format

* Update CHANGELOG.md

Signed-off-by: yihuang <[email protected]>

---------

Signed-off-by: yihuang <[email protected]>
  • Loading branch information
yihuang committed Nov 14, 2024
1 parent f91a53a commit fd71fe2
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 @@ -77,6 +77,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#554](https://github.com/crypto-org-chain/ethermint/pull/554) No trace detail on insufficient balance.
* (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`.
* (rpc) [#562](https://github.com/crypto-org-chain/ethermint/pull/562) 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 fd71fe2

Please sign in to comment.