github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/04-channel/handler.go (about) 1 package channel 2 3 import ( 4 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 5 sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors" 6 capabilitytypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/capability/types" 7 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/keeper" 8 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 9 ) 10 11 // HandleMsgChannelOpenInit defines the sdk.Handler for MsgChannelOpenInit 12 func HandleMsgChannelOpenInit(ctx sdk.Context, k keeper.Keeper, portCap *capabilitytypes.Capability, msg *types.MsgChannelOpenInit) (*sdk.Result, string, *capabilitytypes.Capability, error) { 13 channelID, capKey, err := k.ChanOpenInit( 14 ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, 15 portCap, msg.Channel.Counterparty, msg.Channel.Version, 16 ) 17 if err != nil { 18 return nil, "", nil, sdkerrors.Wrap(err, "channel handshake open init failed") 19 } 20 21 ctx.EventManager().EmitEvents(sdk.Events{ 22 sdk.NewEvent( 23 types.EventTypeChannelOpenInit, 24 sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), 25 sdk.NewAttribute(types.AttributeKeyChannelID, channelID), 26 sdk.NewAttribute(types.AttributeCounterpartyPortID, msg.Channel.Counterparty.PortId), 27 sdk.NewAttribute(types.AttributeCounterpartyChannelID, msg.Channel.Counterparty.ChannelId), 28 sdk.NewAttribute(types.AttributeKeyConnectionID, msg.Channel.ConnectionHops[0]), 29 ), 30 sdk.NewEvent( 31 sdk.EventTypeMessage, 32 sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), 33 ), 34 }) 35 36 return &sdk.Result{ 37 Events: ctx.EventManager().Events(), 38 }, channelID, capKey, nil 39 } 40 41 // HandleMsgChannelOpenTry defines the sdk.Handler for MsgChannelOpenTry 42 func HandleMsgChannelOpenTry(ctx sdk.Context, k keeper.Keeper, portCap *capabilitytypes.Capability, msg *types.MsgChannelOpenTry) (*sdk.Result, string, *capabilitytypes.Capability, error) { 43 channelID, capKey, err := k.ChanOpenTryV2(ctx, msg.Channel.Ordering, msg.Channel.ConnectionHops, msg.PortId, msg.PreviousChannelId, 44 portCap, msg.Channel.Counterparty, msg.Channel.Version, msg.CounterpartyVersion, msg.ProofInit, msg.ProofHeight, 45 ) 46 if err != nil { 47 return nil, "", nil, sdkerrors.Wrap(err, "channel handshake open try failed") 48 } 49 50 ctx.EventManager().EmitEvents(sdk.Events{ 51 sdk.NewEvent( 52 types.EventTypeChannelOpenTry, 53 sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), 54 sdk.NewAttribute(types.AttributeKeyChannelID, channelID), 55 sdk.NewAttribute(types.AttributeCounterpartyPortID, msg.Channel.Counterparty.PortId), 56 sdk.NewAttribute(types.AttributeCounterpartyChannelID, msg.Channel.Counterparty.ChannelId), 57 sdk.NewAttribute(types.AttributeKeyConnectionID, msg.Channel.ConnectionHops[0]), 58 ), 59 sdk.NewEvent( 60 sdk.EventTypeMessage, 61 sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), 62 ), 63 }) 64 65 return &sdk.Result{ 66 Events: ctx.EventManager().Events(), 67 }, channelID, capKey, nil 68 } 69 70 // HandleMsgChannelOpenAck defines the sdk.Handler for MsgChannelOpenAck 71 func HandleMsgChannelOpenAck(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelOpenAck) (*sdk.Result, error) { 72 err := k.ChanOpenAck( 73 ctx, msg.PortId, msg.ChannelId, channelCap, msg.CounterpartyVersion, msg.CounterpartyChannelId, msg.ProofTry, msg.ProofHeight, 74 ) 75 if err != nil { 76 return nil, sdkerrors.Wrap(err, "channel handshake open ack failed") 77 } 78 79 channel, _ := k.GetChannel(ctx, msg.PortId, msg.ChannelId) 80 81 ctx.EventManager().EmitEvents(sdk.Events{ 82 sdk.NewEvent( 83 types.EventTypeChannelOpenAck, 84 sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), 85 sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelId), 86 sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), 87 sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), 88 sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), 89 ), 90 sdk.NewEvent( 91 sdk.EventTypeMessage, 92 sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), 93 ), 94 }) 95 96 return &sdk.Result{ 97 Events: ctx.EventManager().Events(), 98 }, nil 99 } 100 101 // HandleMsgChannelOpenConfirm defines the sdk.Handler for MsgChannelOpenConfirm 102 func HandleMsgChannelOpenConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelOpenConfirm) (*sdk.Result, error) { 103 err := k.ChanOpenConfirm(ctx, msg.PortId, msg.ChannelId, channelCap, msg.ProofAck, msg.ProofHeight) 104 if err != nil { 105 return nil, sdkerrors.Wrap(err, "channel handshake open confirm failed") 106 } 107 108 channel, _ := k.GetChannel(ctx, msg.PortId, msg.ChannelId) 109 110 ctx.EventManager().EmitEvents(sdk.Events{ 111 sdk.NewEvent( 112 types.EventTypeChannelOpenConfirm, 113 sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), 114 sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelId), 115 sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), 116 sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), 117 sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), 118 ), 119 sdk.NewEvent( 120 sdk.EventTypeMessage, 121 sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), 122 ), 123 }) 124 125 return &sdk.Result{ 126 Events: ctx.EventManager().Events(), 127 }, nil 128 } 129 130 // HandleMsgChannelCloseInit defines the sdk.Handler for MsgChannelCloseInit 131 func HandleMsgChannelCloseInit(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelCloseInit) (*sdk.Result, error) { 132 err := k.ChanCloseInit(ctx, msg.PortId, msg.ChannelId, channelCap) 133 if err != nil { 134 return nil, sdkerrors.Wrap(err, "channel handshake close init failed") 135 } 136 137 channel, _ := k.GetChannel(ctx, msg.PortId, msg.ChannelId) 138 139 ctx.EventManager().EmitEvents(sdk.Events{ 140 sdk.NewEvent( 141 types.EventTypeChannelCloseInit, 142 sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), 143 sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelId), 144 sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), 145 sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), 146 sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), 147 ), 148 sdk.NewEvent( 149 sdk.EventTypeMessage, 150 sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), 151 ), 152 }) 153 154 return &sdk.Result{ 155 Events: ctx.EventManager().Events(), 156 }, nil 157 } 158 159 // HandleMsgChannelCloseConfirm defines the sdk.Handler for MsgChannelCloseConfirm 160 func HandleMsgChannelCloseConfirm(ctx sdk.Context, k keeper.Keeper, channelCap *capabilitytypes.Capability, msg *types.MsgChannelCloseConfirm) (*sdk.Result, error) { 161 err := k.ChanCloseConfirm(ctx, msg.PortId, msg.ChannelId, channelCap, msg.ProofInit, msg.ProofHeight) 162 if err != nil { 163 return nil, sdkerrors.Wrap(err, "channel handshake close confirm failed") 164 } 165 166 channel, _ := k.GetChannel(ctx, msg.PortId, msg.ChannelId) 167 168 ctx.EventManager().EmitEvents(sdk.Events{ 169 sdk.NewEvent( 170 types.EventTypeChannelCloseConfirm, 171 sdk.NewAttribute(types.AttributeKeyPortID, msg.PortId), 172 sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelId), 173 sdk.NewAttribute(types.AttributeCounterpartyPortID, channel.Counterparty.PortId), 174 sdk.NewAttribute(types.AttributeCounterpartyChannelID, channel.Counterparty.ChannelId), 175 sdk.NewAttribute(types.AttributeKeyConnectionID, channel.ConnectionHops[0]), 176 ), 177 sdk.NewEvent( 178 sdk.EventTypeMessage, 179 sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), 180 ), 181 }) 182 183 return &sdk.Result{ 184 Events: ctx.EventManager().Events(), 185 }, nil 186 }