11package oracle
22
33import (
4- "strings"
5-
64 sdkerrors "cosmossdk.io/errors"
75 "github.com/cosmos/cosmos-sdk/codec"
86 sdk "github.com/cosmos/cosmos-sdk/types"
@@ -27,51 +25,44 @@ type IBCModule struct {
2725}
2826
2927func (im IBCModule ) OnChanOpenInit (
30- ctx sdk.Context , order ibcchanneltypes.Order , _ []string , portID , channelID string ,
28+ ctx sdk.Context , _ ibcchanneltypes.Order , _ []string , portID , channelID string ,
3129 channelCap * capabilitytypes.Capability , _ ibcchanneltypes.Counterparty , version string ,
3230) (string , error ) {
33- if strings .TrimSpace (version ) == "" {
34- version = types .Version
35- }
3631 if version != types .Version {
3732 return "" , types .NewErrorInvalidVersion (version , types .Version )
3833 }
3934
40- if order != ibcchanneltypes .ORDERED {
41- return "" , types .NewErrorInvalidChannelOrdering (order , ibcchanneltypes .ORDERED )
42- }
43-
4435 boundPortID := im .keeper .GetPortID (ctx )
45- if boundPortID != portID {
36+ if portID != boundPortID {
4637 return "" , types .NewErrorInvalidPort (portID , boundPortID )
4738 }
4839
49- if err := im .keeper .ClaimCapability (ctx , channelCap , ibchost .ChannelCapabilityPath (portID , channelID )); err != nil {
40+ capPath := ibchost .ChannelCapabilityPath (portID , channelID )
41+ if err := im .keeper .ClaimCapability (ctx , channelCap , capPath ); err != nil {
5042 return "" , err
5143 }
5244
53- return version , nil
45+ return types . Version , nil
5446}
5547
5648func (im IBCModule ) OnChanOpenTry (
57- ctx sdk.Context , order ibcchanneltypes.Order , _ []string , portID , channelID string ,
49+ ctx sdk.Context , _ ibcchanneltypes.Order , _ []string , portID , channelID string ,
5850 channelCap * capabilitytypes.Capability , _ ibcchanneltypes.Counterparty , counterpartyVersion string ,
5951) (string , error ) {
6052 if counterpartyVersion != types .Version {
6153 return "" , types .NewErrorInvalidCounterpartyVersion (counterpartyVersion , types .Version )
6254 }
6355
64- if order != ibcchanneltypes .ORDERED {
65- return "" , types .NewErrorInvalidChannelOrdering (order , ibcchanneltypes .ORDERED )
66- }
67-
6856 boundPortID := im .keeper .GetPortID (ctx )
69- if boundPortID != portID {
57+ if portID != boundPortID {
7058 return "" , types .NewErrorInvalidPort (portID , boundPortID )
7159 }
7260
73- if err := im .keeper .ClaimCapability (ctx , channelCap , ibchost .ChannelCapabilityPath (portID , channelID )); err != nil {
74- return "" , err
61+ capPath := ibchost .ChannelCapabilityPath (portID , channelID )
62+ if ! im .keeper .AuthenticateCapability (ctx , channelCap , capPath ) {
63+ if err := im .keeper .ClaimCapability (ctx , channelCap , capPath ); err != nil {
64+ return "" , err
65+ }
7566 }
7667
7768 return types .Version , nil
@@ -85,17 +76,20 @@ func (im IBCModule) OnChanOpenAck(_ sdk.Context, _, _, _ string, counterpartyVer
8576 return nil
8677}
8778
88- func (im IBCModule ) OnChanOpenConfirm (_ sdk.Context , _ , _ string ) error { return nil }
79+ func (im IBCModule ) OnChanOpenConfirm (_ sdk.Context , _ , _ string ) error {
80+ return nil
81+ }
8982
9083func (im IBCModule ) OnChanCloseInit (_ sdk.Context , _ , _ string ) error {
9184 return sdkerrors .Wrap (ibcerrors .ErrInvalidRequest , "user cannot close the channel" )
9285}
9386
94- func (im IBCModule ) OnChanCloseConfirm (_ sdk.Context , _ , _ string ) error { return nil }
87+ func (im IBCModule ) OnChanCloseConfirm (_ sdk.Context , _ , _ string ) error {
88+ return nil
89+ }
9590
9691func (im IBCModule ) OnRecvPacket (_ sdk.Context , _ ibcchanneltypes.Packet , _ sdk.AccAddress ) ibcexported.Acknowledgement {
97- err := sdkerrors .Wrap (ibcerrors .ErrInvalidRequest , "oracle module can not receive the packets" )
98- return ibcchanneltypes .NewErrorAcknowledgement (err )
92+ return ibcchanneltypes .NewErrorAcknowledgement (sdkerrors .Wrap (ibcerrors .ErrInvalidRequest , "oracle module can not receive the packets" ))
9993}
10094
10195func (im IBCModule ) OnAcknowledgementPacket (
@@ -109,6 +103,6 @@ func (im IBCModule) OnAcknowledgementPacket(
109103 return im .keeper .OnAcknowledgementPacket (ctx , packet , ack )
110104}
111105
112- func (im IBCModule ) OnTimeoutPacket (_ sdk.Context , _ ibcchanneltypes.Packet , _ sdk.AccAddress ) error {
113- return nil
106+ func (im IBCModule ) OnTimeoutPacket (ctx sdk.Context , packet ibcchanneltypes.Packet , _ sdk.AccAddress ) error {
107+ return im . keeper . OnTimeoutPacket ( ctx , packet )
114108}
0 commit comments