Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Apr 19, 2024
1 parent b1a0bc4 commit 734da9d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion modules/token/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (k Keeper) Balances(c context.Context, req *v1.QueryBalancesRequest) (*v1.Q
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
balances = balances.Add(sdk.NewCoin(token.GetContract(), sdkmath.NewIntFromBigInt(erc20Balance)))
balances = balances.Add(sdk.NewCoin("erc20/"+token.GetContract(), sdkmath.NewIntFromBigInt(erc20Balance)))
}
return &v1.QueryBalancesResponse{Balances: balances}, nil
}
8 changes: 1 addition & 7 deletions modules/token/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"encoding/hex"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -318,12 +317,7 @@ func (m msgServer) SwapToERC20(goCtx context.Context, msg *v1.MsgSwapToERC20) (*
return nil, err
}

bz, err := hex.DecodeString(msg.Receiver)
if err != nil {
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "expecting a hex address of 0x, got %s", msg.Receiver)
}
receiver := common.BytesToAddress(bz)

receiver := common.HexToAddress(msg.Receiver)
if err := m.k.SwapToERC20(ctx, sender, receiver, msg.Amount); err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions modules/token/types/v1/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"

tokentypes "github.com/irisnet/irismod/modules/token/types"
)
Expand Down Expand Up @@ -420,8 +421,8 @@ func (m *MsgSwapToERC20) ValidateBasic() error {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err)
}

if tokentypes.IsValidEthAddress(m.Receiver) {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "expecting a hex address of 0x, got %s", m.Receiver)
if !common.IsHexAddress(m.Receiver) {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "expecting a hex address, got %s", m.Receiver)
}

if !m.Amount.IsValid() {
Expand Down
12 changes: 2 additions & 10 deletions modules/token/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ var (
regexpMinUintFmt = fmt.Sprintf("^[a-z][a-z0-9]{%d,%d}$", MinimumMinUnitLen-1, MaximumMinUnitLen-1)
regexpMinUint = regexp.MustCompile(regexpMinUintFmt).MatchString

regexpEthAddressLowerStr = "^0x[0-9a-f]{40}$"
regexpEthAddressUpperStr = "^0x[0-9A-F]{40}$"
regexpEthAddressLower = regexp.MustCompile(regexpEthAddressLowerStr).MatchString
regexpEthAddressUpper = regexp.MustCompile(regexpEthAddressUpperStr).MatchString
regexpEthAddressStr = "^0x[0-9a-f]{40}$"
regexpEthAddress = regexp.MustCompile(regexpEthAddressStr).MatchString
)

// ValidateInitialSupply verifies whether the initial supply is legal
Expand Down Expand Up @@ -120,9 +118,3 @@ func ValidateCoin(coin sdk.Coin) error {
}
return ValidateMinUnit(coin.Denom)
}

// IsValidEthAddress checks if the given address is valid ethereum address
func IsValidEthAddress(address string) bool {
address = strings.ToLower(address)
return regexpEthAddressLower(address) || regexpEthAddressUpper(address)
}

0 comments on commit 734da9d

Please sign in to comment.