rpc: fix nil pointer exception when parameters are nil (#180)
* fix nil pointer exception when parameters are nil * Update ethereum/rpc/types/types.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
1c06553746
commit
b7f00d5a07
@ -347,7 +347,7 @@ func (e *PublicAPI) Sign(address common.Address, data hexutil.Bytes) (hexutil.By
|
||||
|
||||
// SendTransaction sends an Ethereum transaction.
|
||||
func (e *PublicAPI) SendTransaction(args rpctypes.SendTxArgs) (common.Hash, error) {
|
||||
e.logger.Debugln("eth_sendTransaction", "args", args)
|
||||
e.logger.Debugln("eth_sendTransaction", "args", args.String())
|
||||
|
||||
// Look up the wallet containing the requested signer
|
||||
_, err := e.clientCtx.Keyring.KeyByAddress(sdk.AccAddress(args.From.Bytes()))
|
||||
@ -493,7 +493,7 @@ func (e *PublicAPI) SendRawTransaction(data hexutil.Bytes) (common.Hash, error)
|
||||
|
||||
// Call performs a raw contract call.
|
||||
func (e *PublicAPI) Call(args rpctypes.CallArgs, blockNr rpctypes.BlockNumber, _ *rpctypes.StateOverride) (hexutil.Bytes, error) {
|
||||
e.logger.Debugln("eth_call", "args", args, "block number", blockNr)
|
||||
e.logger.Debugln("eth_call", "args", args.String(), "block number", blockNr)
|
||||
simRes, err := e.doCall(args, blockNr, big.NewInt(ethermint.DefaultRPCGasLimit))
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
|
@ -1,6 +1,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
@ -68,6 +70,20 @@ type SendTxArgs struct {
|
||||
ChainID *hexutil.Big `json:"chainId,omitempty"`
|
||||
}
|
||||
|
||||
// String return the struct in a string format
|
||||
func (args *SendTxArgs) String() string {
|
||||
// Todo: There is currently a bug with hexutil.Big when the value its nil, printing would trigger an exception
|
||||
return fmt.Sprintf("SendTxArgs{From:%v, To:%v, Gas:%v,"+
|
||||
" Nonce:%v, Data:%v, Input:%v, AccessList:%v}",
|
||||
args.From,
|
||||
args.To,
|
||||
args.Gas,
|
||||
args.Nonce,
|
||||
args.Data,
|
||||
args.Input,
|
||||
args.AccessList)
|
||||
}
|
||||
|
||||
// ToTransaction converts the arguments to an ethereum transaction.
|
||||
// This assumes that setTxDefaults has been called.
|
||||
func (args *SendTxArgs) ToTransaction() *evmtypes.MsgEthereumTx {
|
||||
@ -79,16 +95,34 @@ func (args *SendTxArgs) ToTransaction() *evmtypes.MsgEthereumTx {
|
||||
}
|
||||
|
||||
data := &evmtypes.TxData{
|
||||
To: args.To.Hex(),
|
||||
ChainID: args.ChainID.ToInt().Bytes(),
|
||||
Nonce: uint64(*args.Nonce),
|
||||
GasLimit: uint64(*args.Gas),
|
||||
GasPrice: args.GasPrice.ToInt().Bytes(),
|
||||
Amount: args.Value.ToInt().Bytes(),
|
||||
Input: input,
|
||||
Accesses: evmtypes.NewAccessList(args.AccessList),
|
||||
}
|
||||
|
||||
if args.ChainID != nil {
|
||||
data.ChainID = args.ChainID.ToInt().Bytes()
|
||||
}
|
||||
|
||||
if args.Nonce != nil {
|
||||
data.Nonce = uint64(*args.Nonce)
|
||||
}
|
||||
|
||||
if args.Gas != nil {
|
||||
data.GasLimit = uint64(*args.Gas)
|
||||
}
|
||||
|
||||
if args.GasPrice != nil {
|
||||
data.GasPrice = args.GasPrice.ToInt().Bytes()
|
||||
}
|
||||
|
||||
if args.Value != nil {
|
||||
data.Amount = args.Value.ToInt().Bytes()
|
||||
}
|
||||
|
||||
if args.To != nil {
|
||||
data.To = args.To.Hex()
|
||||
}
|
||||
|
||||
return &evmtypes.MsgEthereumTx{
|
||||
Data: data,
|
||||
From: args.From.String(),
|
||||
@ -106,6 +140,18 @@ type CallArgs struct {
|
||||
AccessList *ethtypes.AccessList `json:"accessList"`
|
||||
}
|
||||
|
||||
// String return the struct in a string format
|
||||
func (args *CallArgs) String() string {
|
||||
// Todo: There is currently a bug with hexutil.Big when the value its nil, printing would trigger an exception
|
||||
return fmt.Sprintf("SendTxArgs{From:%v, To:%v, Gas:%v,"+
|
||||
" Data:%v, AccessList:%v}",
|
||||
args.From,
|
||||
args.To,
|
||||
args.Gas,
|
||||
args.Data,
|
||||
args.AccessList)
|
||||
}
|
||||
|
||||
// StateOverride is the collection of overridden accounts.
|
||||
type StateOverride map[common.Address]OverrideAccount
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user