Skip to content

Commit

Permalink
Remove sdk.Result from application callbacks cosmos#215
Browse files Browse the repository at this point in the history
  • Loading branch information
smadarasmi committed Jul 3, 2021
1 parent 007c680 commit 3bc4d18
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
22 changes: 9 additions & 13 deletions modules/apps/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -404,24 +404,22 @@ func (am AppModule) OnAcknowledgementPacket(
)
}

return &sdk.Result{
Events: ctx.EventManager().Events().ToABCIEvents(),
}, nil
return nil
}

// OnTimeoutPacket implements the IBCModule interface
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(
Expand All @@ -434,7 +432,5 @@ func (am AppModule) OnTimeoutPacket(
),
)

return &sdk.Result{
Events: ctx.EventManager().Events().ToABCIEvents(),
}, nil
return nil
}
4 changes: 2 additions & 2 deletions modules/core/05-port/types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
8 changes: 4 additions & 4 deletions testing/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3bc4d18

Please sign in to comment.