Skip to content

Commit

Permalink
Speedup one JSON unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Jun 17, 2024
1 parent 3b71637 commit 39ac9d9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions x/ibc-rate-limit/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
Expand Down Expand Up @@ -110,12 +109,17 @@ func (im *IBCModule) OnChanCloseConfirm(
return im.app.OnChanCloseConfirm(ctx, portID, channelID)
}

type receiverParser struct {
Receiver string `protobuf:"bytes,4,opt,name=receiver,proto3" json:"receiver,omitempty"`
}

func ValidateReceiverAddress(packet exported.PacketI) error {
var packetData transfertypes.FungibleTokenPacketData
if err := json.Unmarshal(packet.GetData(), &packetData); err != nil {
var receiverObj receiverParser

if err := json.Unmarshal(packet.GetData(), &receiverObj); err != nil {
return err
}
if len(packetData.Receiver) >= 4096 {
if len(receiverObj.Receiver) >= 4096 {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "IBC Receiver address too long. Max supported length is %d", 4096)
}
return nil
Expand Down

0 comments on commit 39ac9d9

Please sign in to comment.