forked from quicksilver-zone/quicksilver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ibc_module.go
152 lines (135 loc) · 3.66 KB
/
ibc_module.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package interchainstaking
import (
"errors"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported"
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper"
)
var _ porttypes.IBCModule = IBCModule{}
// IBCModule implements the ICS26 interface for interchain accounts controller chains.
type IBCModule struct {
keeper *keeper.Keeper
}
// NewIBCModule creates a new IBCModule given the keeper.
func NewIBCModule(k *keeper.Keeper) IBCModule {
return IBCModule{
keeper: k,
}
}
// OnChanOpenInit implements the IBCModule interface.
func (im IBCModule) OnChanOpenInit(
ctx sdk.Context,
_ channeltypes.Order,
_ []string,
portID string,
channelID string,
chanCap *capabilitytypes.Capability,
_ channeltypes.Counterparty,
_ string,
) (string, error) {
return "", nil
}
// OnChanOpenTry implements the IBCModule interface.
func (IBCModule) OnChanOpenTry(
_ sdk.Context,
_ channeltypes.Order,
_ []string,
_ string,
_ string,
_ *capabilitytypes.Capability,
_ channeltypes.Counterparty,
_ string,
) (string, error) {
return "", nil
}
// OnChanOpenAck implements the IBCModule interface.
func (im IBCModule) OnChanOpenAck(
ctx sdk.Context,
portID,
channelID string,
_ string,
_ string,
) error {
// get connection from port
connectionID, _, err := im.keeper.IBCKeeper.ChannelKeeper.GetChannelConnection(ctx, portID, channelID)
if err != nil {
return err
}
return im.keeper.HandleChannelOpenAck(ctx, portID, connectionID)
}
// OnChanOpenConfirm implements the IBCModule interface.
func (im IBCModule) OnChanOpenConfirm(
_ sdk.Context,
_,
_ string,
) error {
return nil
}
// OnChanCloseInit implements the IBCModule interface.
func (im IBCModule) OnChanCloseInit(
_ sdk.Context,
_,
_ string,
) error {
return nil
}
// OnChanCloseConfirm implements the IBCModule interface.
func (IBCModule) OnChanCloseConfirm(
_ sdk.Context,
_,
_ string,
) error {
return nil
}
// OnRecvPacket implements the IBCModule interface. A successful acknowledgement
// is returned if the packet data is successfully decoded and the receive application
// logic returns without error.
func (im IBCModule) OnRecvPacket(
_ sdk.Context,
_ channeltypes.Packet,
_ sdk.AccAddress,
) ibcexported.Acknowledgement {
return channeltypes.NewErrorAcknowledgement(errors.New("cannot receive packet via interchain accounts authentication module"))
}
// OnAcknowledgementPacket implements the IBCModule interface.
func (im IBCModule) OnAcknowledgementPacket(
ctx sdk.Context,
packet channeltypes.Packet,
acknowledgement []byte,
_ sdk.AccAddress,
) error {
connectionID, _, err := im.keeper.IBCKeeper.ChannelKeeper.GetChannelConnection(ctx, packet.SourcePort, packet.SourceChannel)
if err != nil {
err = fmt.Errorf("packet connection not found: %w", err)
ctx.Logger().Error(err.Error())
return err
}
err = im.keeper.HandleAcknowledgement(ctx, packet, acknowledgement, connectionID)
if err != nil {
im.keeper.Logger(ctx).Error("CALLBACK ERROR:", "error", err.Error())
}
return err
}
// OnTimeoutPacket implements the IBCModule interface.
func (im IBCModule) OnTimeoutPacket(
ctx sdk.Context,
packet channeltypes.Packet,
_ sdk.AccAddress,
) error {
return im.keeper.HandleTimeout(ctx, packet)
}
// NegotiateAppVersion implements the IBCModule interface.
func (IBCModule) NegotiateAppVersion(
_ sdk.Context,
_ channeltypes.Order,
_ string,
_ string,
_ channeltypes.Counterparty,
_ string,
) (string, error) {
return "", nil
}