-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
98 lines (77 loc) · 3.59 KB
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package ibc
import (
sdk "github.com/soominhyunwoo/chain-sdk/types"
sdkerrors "github.com/soominhyunwoo/chain-sdk/types/errors"
clienttypes "github.com/soominhyunwoo/chain-sdk/x/ibc/core/02-client/types"
connectiontypes "github.com/soominhyunwoo/chain-sdk/x/ibc/core/03-connection/types"
channeltypes "github.com/soominhyunwoo/chain-sdk/x/ibc/core/04-channel/types"
"github.com/soominhyunwoo/chain-sdk/x/ibc/core/keeper"
)
// NewHandler defines the IBC handler
func NewHandler(k keeper.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())
switch msg := msg.(type) {
// IBC client msg interface types
case *clienttypes.MsgCreateClient:
res, err := k.CreateClient(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *clienttypes.MsgUpdateClient:
res, err := k.UpdateClient(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *clienttypes.MsgUpgradeClient:
res, err := k.UpgradeClient(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *clienttypes.MsgSubmitMisbehaviour:
res, err := k.SubmitMisbehaviour(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
// IBC connection msgs
case *connectiontypes.MsgConnectionOpenInit:
res, err := k.ConnectionOpenInit(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *connectiontypes.MsgConnectionOpenTry:
res, err := k.ConnectionOpenTry(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *connectiontypes.MsgConnectionOpenAck:
res, err := k.ConnectionOpenAck(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *connectiontypes.MsgConnectionOpenConfirm:
res, err := k.ConnectionOpenConfirm(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
// IBC channel msgs
case *channeltypes.MsgChannelOpenInit:
res, err := k.ChannelOpenInit(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *channeltypes.MsgChannelOpenTry:
res, err := k.ChannelOpenTry(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *channeltypes.MsgChannelOpenAck:
res, err := k.ChannelOpenAck(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *channeltypes.MsgChannelOpenConfirm:
res, err := k.ChannelOpenConfirm(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *channeltypes.MsgChannelCloseInit:
res, err := k.ChannelCloseInit(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *channeltypes.MsgChannelCloseConfirm:
res, err := k.ChannelCloseConfirm(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
// IBC packet msgs get routed to the appropriate module callback
case *channeltypes.MsgRecvPacket:
res, err := k.RecvPacket(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *channeltypes.MsgAcknowledgement:
res, err := k.Acknowledgement(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *channeltypes.MsgTimeout:
res, err := k.Timeout(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *channeltypes.MsgTimeoutOnClose:
res, err := k.TimeoutOnClose(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized IBC message type: %T", msg)
}
}
}