github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/icamauth/keeper/msg_server.go (about) 1 package keeper 2 3 import ( 4 "context" 5 "time" 6 7 host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host" 8 9 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 10 sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors" 11 icatypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/types" 12 channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 13 "github.com/fibonacci-chain/fbc/x/icamauth/types" 14 ) 15 16 var _ types.MsgServer = msgServer{} 17 18 type msgServer struct { 19 Keeper 20 } 21 22 // NewMsgServerImpl creates and returns a new types.MsgServer, fulfilling the icamauth Msg service interface 23 func NewMsgServerImpl(keeper Keeper) types.MsgServer { 24 return &msgServer{Keeper: keeper} 25 } 26 27 // RegisterAccount implements the Msg/RegisterAccount interface 28 func (k msgServer) RegisterAccount(goCtx context.Context, msg *types.MsgRegisterAccount) (*types.MsgRegisterAccountResponse, error) { 29 ctx := sdk.UnwrapSDKContext(goCtx) 30 31 if err := k.icaControllerKeeper.RegisterInterchainAccount(ctx, msg.ConnectionId, msg.Owner, msg.Version); err != nil { 32 return nil, err 33 } 34 35 return &types.MsgRegisterAccountResponse{}, nil 36 } 37 38 // SubmitTx implements the Msg/SubmitTx interface 39 func (k msgServer) SubmitTx(goCtx context.Context, msg *types.MsgSubmitTx) (*types.MsgSubmitTxResponse, error) { 40 ctx := sdk.UnwrapSDKContext(goCtx) 41 42 portID, err := icatypes.NewControllerPortID(msg.Owner) 43 if err != nil { 44 return nil, err 45 } 46 47 channelID, found := k.icaControllerKeeper.GetActiveChannelID(ctx, msg.ConnectionId, portID) 48 if !found { 49 return nil, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) 50 } 51 52 chanCap, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) 53 if !found { 54 return nil, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") 55 } 56 57 data, err := icatypes.SerializeCosmosTx(k.cdc, []sdk.MsgAdapter{msg.GetTxMsg()}) 58 if err != nil { 59 return nil, err 60 } 61 62 packetData := icatypes.InterchainAccountPacketData{ 63 Type: icatypes.EXECUTE_TX, 64 Data: data, 65 } 66 67 // timeoutTimestamp set to max value with the unsigned bit shifted to sastisfy hermes timestamp conversion 68 // it is the responsibility of the auth module developer to ensure an appropriate timeout timestamp 69 timeoutTimestamp := ctx.BlockTime().Add(time.Minute).UnixNano() 70 _, err = k.icaControllerKeeper.SendTx(ctx, chanCap, msg.ConnectionId, portID, packetData, uint64(timeoutTimestamp)) 71 if err != nil { 72 return nil, err 73 } 74 75 return &types.MsgSubmitTxResponse{}, nil 76 }