Skip to content

Commit

Permalink
allow 0x prefix for all hex input
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Mar 29, 2024
1 parent 1c96a0c commit 054648e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"encoding/hex"
"strings"

"github.com/ethereum/go-ethereum/common"

Expand Down Expand Up @@ -35,7 +36,7 @@ func (ms *msgServerImpl) Create(ctx context.Context, msg *types.MsgCreate) (*typ
if len(msg.Code) == 0 {
return nil, sdkerrors.ErrInvalidRequest.Wrap("empty code bytes")
}
codeBz, err := hex.DecodeString(msg.Code)
codeBz, err := hex.DecodeString(strings.TrimPrefix(msg.Code, "0x"))
if err != nil {
return nil, types.ErrInvalidHexString.Wrap(err.Error())
}
Expand Down Expand Up @@ -92,7 +93,7 @@ func (ms *msgServerImpl) Call(ctx context.Context, msg *types.MsgCall) (*types.M
if err != nil {
return nil, err
}
inputBz, err := hex.DecodeString(msg.Input)
inputBz, err := hex.DecodeString(strings.TrimPrefix(msg.Input, "0x"))
if err != nil {
return nil, types.ErrInvalidHexString.Wrap(err.Error())
}
Expand Down
9 changes: 7 additions & 2 deletions x/evm/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (qs *queryServerImpl) Call(ctx context.Context, req *types.QueryCallRequest
return nil, err
}

inputBz, err := hex.DecodeString(req.Input)
inputBz, err := hex.DecodeString(strings.TrimPrefix(req.Input, "0x"))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -112,7 +112,12 @@ func (qs *queryServerImpl) State(ctx context.Context, req *types.QueryStateReque
return nil, err
}

state := stateDB.GetState(common.Address(contractAddr.Bytes()), common.HexToHash(req.Key))
keyBz, err := hex.DecodeString(strings.TrimPrefix(req.Key, "0x"))
if err != nil {
return nil, err
}

state := stateDB.GetState(common.Address(contractAddr.Bytes()), common.BytesToHash(keyBz))
return &types.QueryStateResponse{
Value: state.Hex(),
}, nil
Expand Down

0 comments on commit 054648e

Please sign in to comment.