github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/27-interchain-accounts/controller/keeper/relay.go (about) 1 package keeper 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 icatypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/types" 8 clienttypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/types" 9 channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 10 ) 11 12 // SendTx takes pre-built packet data containing messages to be executed on the host chain from an authentication module and attempts to send the packet. 13 // The packet sequence for the outgoing packet is returned as a result. 14 // If the base application has the capability to send on the provided portID. An appropriate 15 // absolute timeoutTimestamp must be provided. If the packet is timed out, the channel will be closed. 16 // In the case of channel closure, a new channel may be reopened to reconnect to the host chain. 17 func (k Keeper) SendTx(ctx sdk.Context, chanCap *capabilitytypes.Capability, connectionID, portID string, icaPacketData icatypes.InterchainAccountPacketData, timeoutTimestamp uint64) (uint64, error) { 18 activeChannelID, found := k.GetOpenActiveChannel(ctx, connectionID, portID) 19 if !found { 20 return 0, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel on connection %s for port %s", connectionID, portID) 21 } 22 23 sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, portID, activeChannelID) 24 if !found { 25 return 0, sdkerrors.Wrap(channeltypes.ErrChannelNotFound, activeChannelID) 26 } 27 28 destinationPort := sourceChannelEnd.GetCounterparty().GetPortID() 29 destinationChannel := sourceChannelEnd.GetCounterparty().GetChannelID() 30 31 if uint64(ctx.BlockTime().UnixNano()) >= timeoutTimestamp { 32 return 0, icatypes.ErrInvalidTimeoutTimestamp 33 } 34 35 return k.createOutgoingPacket(ctx, portID, activeChannelID, destinationPort, destinationChannel, chanCap, icaPacketData, timeoutTimestamp) 36 } 37 38 func (k Keeper) createOutgoingPacket( 39 ctx sdk.Context, 40 sourcePort, 41 sourceChannel, 42 destinationPort, 43 destinationChannel string, 44 chanCap *capabilitytypes.Capability, 45 icaPacketData icatypes.InterchainAccountPacketData, 46 timeoutTimestamp uint64, 47 ) (uint64, error) { 48 if err := icaPacketData.ValidateBasic(); err != nil { 49 return 0, sdkerrors.Wrap(err, "invalid interchain account packet data") 50 } 51 52 // get the next sequence 53 sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel) 54 if !found { 55 return 0, sdkerrors.Wrapf(channeltypes.ErrSequenceSendNotFound, "failed to retrieve next sequence send for channel %s on port %s", sourceChannel, sourcePort) 56 } 57 58 packet := channeltypes.NewPacket( 59 icaPacketData.GetBytes(), 60 sequence, 61 sourcePort, 62 sourceChannel, 63 destinationPort, 64 destinationChannel, 65 clienttypes.ZeroHeight(), 66 timeoutTimestamp, 67 ) 68 69 if err := k.ics4Wrapper.SendPacket(ctx, chanCap, packet); err != nil { 70 return 0, err 71 } 72 73 return packet.Sequence, nil 74 } 75 76 // OnTimeoutPacket removes the active channel associated with the provided packet, the underlying channel end is closed 77 // due to the semantics of ORDERED channels 78 func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet) error { 79 return nil 80 }