From 3bc4d18005c3669e025c8091cbb4bf3b43f7104f Mon Sep 17 00:00:00 2001 From: Sarin Madarasmi Date: Sat, 3 Jul 2021 16:53:29 +0800 Subject: [PATCH] Remove sdk.Result from application callbacks #215 --- modules/apps/transfer/module.go | 22 +++++++++------------- modules/core/05-port/types/module.go | 4 ++-- modules/core/keeper/msg_server.go | 6 +++--- testing/mock/mock.go | 8 ++++---- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/modules/apps/transfer/module.go b/modules/apps/transfer/module.go index 1c9afbe9f46..a9a1aa4f875 100644 --- a/modules/apps/transfer/module.go +++ b/modules/apps/transfer/module.go @@ -362,18 +362,18 @@ func (am AppModule) OnAcknowledgementPacket( packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress, -) (*sdk.Result, error) { +) error { var ack channeltypes.Acknowledgement if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) + return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err) } var data types.FungibleTokenPacketData if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) + return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } if err := am.keeper.OnAcknowledgementPacket(ctx, packet, data, ack); err != nil { - return nil, err + return err } ctx.EventManager().EmitEvent( @@ -404,9 +404,7 @@ func (am AppModule) OnAcknowledgementPacket( ) } - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, nil + return nil } // OnTimeoutPacket implements the IBCModule interface @@ -414,14 +412,14 @@ func (am AppModule) OnTimeoutPacket( ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress, -) (*sdk.Result, error) { +) error { var data types.FungibleTokenPacketData if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) + return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } // refund tokens if err := am.keeper.OnTimeoutPacket(ctx, packet, data); err != nil { - return nil, err + return err } ctx.EventManager().EmitEvent( @@ -434,7 +432,5 @@ func (am AppModule) OnTimeoutPacket( ), ) - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, nil + return nil } diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index 4a1c2596b81..9c0885c0cf1 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -75,11 +75,11 @@ type IBCModule interface { packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress, - ) (*sdk.Result, error) + ) error OnTimeoutPacket( ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress, - ) (*sdk.Result, error) + ) error } diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 3aeeffdb457..fe410471d63 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -557,7 +557,7 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c } // Perform application logic callback - _, err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer) + err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer) if err != nil { return nil, sdkerrors.Wrap(err, "timeout packet callback failed") } @@ -613,7 +613,7 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo // Perform application logic callback // NOTE: MsgTimeout and MsgTimeoutOnClose use the same "OnTimeoutPacket" // application logic callback. - _, err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer) + err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer) if err != nil { return nil, sdkerrors.Wrap(err, "timeout packet callback failed") } @@ -667,7 +667,7 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn } // Perform application logic callback - _, err = cbs.OnAcknowledgementPacket(ctx, msg.Packet, msg.Acknowledgement, relayer) + err = cbs.OnAcknowledgementPacket(ctx, msg.Packet, msg.Acknowledgement, relayer) if err != nil { return nil, sdkerrors.Wrap(err, "acknowledge packet callback failed") } diff --git a/testing/mock/mock.go b/testing/mock/mock.go index e2062dda51a..9edf5d3536a 100644 --- a/testing/mock/mock.go +++ b/testing/mock/mock.go @@ -205,11 +205,11 @@ func (am AppModule) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, re } // OnAcknowledgementPacket implements the IBCModule interface. -func (am AppModule) OnAcknowledgementPacket(sdk.Context, channeltypes.Packet, []byte, sdk.AccAddress) (*sdk.Result, error) { - return nil, nil +func (am AppModule) OnAcknowledgementPacket(sdk.Context, channeltypes.Packet, []byte, sdk.AccAddress) error { + return nil } // OnTimeoutPacket implements the IBCModule interface. -func (am AppModule) OnTimeoutPacket(sdk.Context, channeltypes.Packet, sdk.AccAddress) (*sdk.Result, error) { - return nil, nil +func (am AppModule) OnTimeoutPacket(sdk.Context, channeltypes.Packet, sdk.AccAddress) error { + return nil }