-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibc.go
91 lines (70 loc) · 3.27 KB
/
ibc.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
package wormhole
import (
"fmt"
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
"github.com/noble-assets/wormhole/keeper"
"github.com/noble-assets/wormhole/types"
)
var _ porttypes.IBCModule = IBCModule{}
type IBCModule struct {
*keeper.Keeper
}
func NewIBCModule(keeper *keeper.Keeper) IBCModule {
return IBCModule{Keeper: keeper}
}
func (m IBCModule) OnChanOpenInit(ctx sdk.Context, _ channeltypes.Order, _ []string, port string, channel string, cap *capabilitytypes.Capability, _ channeltypes.Counterparty, version string) (string, error) {
if port != types.Port {
return "", errors.Wrapf(types.ErrInvalidPort, "expected port %s, got %s", types.Port, port)
}
if version != types.Version {
return "", errors.Wrapf(types.ErrInvalidVersion, "expected version %s, got %s", types.Version, version)
}
err := m.ClaimCapability(ctx, cap, host.ChannelCapabilityPath(port, channel))
return types.Version, err
}
func (m IBCModule) OnChanOpenTry(ctx sdk.Context, _ channeltypes.Order, _ []string, port string, channel string, cap *capabilitytypes.Capability, _ channeltypes.Counterparty, counterpartyVersion string) (string, error) {
if port != types.Port {
return "", errors.Wrapf(types.ErrInvalidPort, "expected port %s, got %s", types.Port, port)
}
if counterpartyVersion != types.Version {
return "", errors.Wrapf(types.ErrInvalidVersion, "expected counterparty version %s, got %s", types.Version, counterpartyVersion)
}
err := m.ClaimCapability(ctx, cap, host.ChannelCapabilityPath(port, channel))
return types.Version, err
}
func (m IBCModule) OnChanOpenAck(_ sdk.Context, port string, _ string, _ string, counterpartyVersion string) error {
if port != types.Port {
return errors.Wrapf(types.ErrInvalidPort, "expected port %s, got %s", types.Port, port)
}
if counterpartyVersion != types.Version {
return errors.Wrapf(types.ErrInvalidVersion, "expected counterparty version %s, got %s", types.Version, counterpartyVersion)
}
return nil
}
func (m IBCModule) OnChanOpenConfirm(_ sdk.Context, port string, _ string) error {
if port != types.Port {
return errors.Wrapf(types.ErrInvalidPort, "expected port %s, got %s", types.Port, port)
}
return nil
}
func (m IBCModule) OnChanCloseInit(_ sdk.Context, _ string, _ string) error {
return fmt.Errorf("channels with version %s cannot be closed", types.Version)
}
func (m IBCModule) OnChanCloseConfirm(_ sdk.Context, _ string, _ string) error {
return fmt.Errorf("channels with version %s cannot be closed", types.Version)
}
func (m IBCModule) OnRecvPacket(_ sdk.Context, _ channeltypes.Packet, _ sdk.AccAddress) exported.Acknowledgement {
return channeltypes.NewErrorAcknowledgement(fmt.Errorf("channels with version %s cannot receive packets", types.Version))
}
func (m IBCModule) OnAcknowledgementPacket(_ sdk.Context, _ channeltypes.Packet, _ []byte, _ sdk.AccAddress) error {
return nil
}
func (m IBCModule) OnTimeoutPacket(_ sdk.Context, _ channeltypes.Packet, _ sdk.AccAddress) error {
return nil
}