Skip to content

Commit

Permalink
Register eibc and delayedack message in amino codec (#1401)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Tsitrin <[email protected]>
  • Loading branch information
ItzhakBokris and mtsitrin authored Nov 5, 2024
1 parent d081ce7 commit 7850af9
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 11 deletions.
2 changes: 1 addition & 1 deletion x/delayedack/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (w IBCMiddleware) OnAcknowledgementPacket(
l := w.logger(ctx, packet, "OnAcknowledgementPacket")

var ack channeltypes.Acknowledgement
if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
if err := w.Keeper.Cdc().UnmarshalJSON(acknowledgement, &ack); err != nil {
l.Error("Unmarshal acknowledgement.", "err", err)
return errorsmod.Wrapf(types.ErrUnknownRequest, "unmarshal ICS-20 transfer packet acknowledgement: %v", err)
}
Expand Down
9 changes: 7 additions & 2 deletions x/delayedack/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

type Keeper struct {
cdc codec.BinaryCodec
cdc codec.Codec
storeKey storetypes.StoreKey
hooks types.MultiDelayedAckHooks
paramstore paramtypes.Subspace
Expand All @@ -37,7 +37,7 @@ type Keeper struct {
}

func NewKeeper(
cdc codec.BinaryCodec,
cdc codec.Codec,
storeKey storetypes.StoreKey,
ps paramtypes.Subspace,
rollappKeeper types.RollappKeeper,
Expand Down Expand Up @@ -70,6 +70,11 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

// expose codec to be used by the delayedack middleware
func (k Keeper) Cdc() codec.Codec {
return k.cdc
}

func (k Keeper) getRollappFinalizedHeight(ctx sdk.Context, chainID string) (uint64, error) {
// GetLatestFinalizedStateIndex
latestFinalizedStateIndex, found := k.rollappKeeper.GetLatestFinalizedStateIndex(ctx, chainID)
Expand Down
21 changes: 16 additions & 5 deletions x/delayedack/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(types.NewInterfaceRegistry())
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
)

// RegisterCodec registers the necessary x/delayedack interfaces and concrete types on the provided
Expand All @@ -28,3 +24,18 @@ func RegisterInterfaces(reg types.InterfaceRegistry) {
)
msgservice.RegisterMsgServiceDesc(reg, &_Msg_serviceDesc)
}

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewAminoCodec(Amino)
)

func init() {
RegisterCodec(Amino)
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
sdk.RegisterLegacyAminoCodec(Amino)
RegisterCodec(authzcodec.Amino)

Amino.Seal()
}
38 changes: 38 additions & 0 deletions x/delayedack/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"errors"
"fmt"

"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -12,6 +14,16 @@ import (
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
)

const (
TypeMsgFinalizedPacket = "finalized_packet"
TypeMsgFinalizedPacketByPacketKey = "finalized_packet_by_packet_key"
)

var (
_ legacytx.LegacyMsg = &MsgFinalizePacket{}
_ legacytx.LegacyMsg = &MsgFinalizePacketByPacketKey{}
)

func (m MsgFinalizePacket) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Sender)
if err != nil {
Expand Down Expand Up @@ -75,3 +87,29 @@ func (m MsgFinalizePacketByPacketKey) MustDecodePacketKey() []byte {
}
return packetKey
}

func (m *MsgFinalizePacket) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(m)
return sdk.MustSortJSON(bz)
}

func (m *MsgFinalizePacket) Route() string {
return RouterKey
}

func (m *MsgFinalizePacket) Type() string {
return TypeMsgFinalizedPacket
}

func (m *MsgFinalizePacketByPacketKey) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(m)
return sdk.MustSortJSON(bz)
}

func (m *MsgFinalizePacketByPacketKey) Route() string {
return RouterKey
}

func (m *MsgFinalizePacketByPacketKey) Type() string {
return TypeMsgFinalizedPacketByPacketKey
}
16 changes: 13 additions & 3 deletions x/eibc/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"

"github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/cosmos-sdk/x/authz"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
)

func RegisterCodec(cdc *codec.LegacyAmino) {
Expand All @@ -30,5 +30,15 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
ModuleCdc = codec.NewAminoCodec(Amino)
)

func init() {
RegisterCodec(Amino)
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
sdk.RegisterLegacyAminoCodec(Amino)
RegisterCodec(authzcodec.Amino)

Amino.Seal()
}
5 changes: 5 additions & 0 deletions x/eibc/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/hex"
"fmt"

"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"

errorsmod "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand All @@ -13,6 +15,9 @@ import (
var (
_ = sdk.Msg(&MsgFulfillOrder{})
_ = sdk.Msg(&MsgUpdateDemandOrder{})

_ legacytx.LegacyMsg = &MsgFulfillOrder{}
_ legacytx.LegacyMsg = &MsgFulfillOrderAuthorized{}
)

func NewMsgFulfillOrder(fulfillerAddress, orderId, expectedFee string) *MsgFulfillOrder {
Expand Down

0 comments on commit 7850af9

Please sign in to comment.