diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index 2f6d188b9e3..7637ffd3d71 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -3,10 +3,13 @@ package keeper import ( "context" "slices" + "strings" - errorsmod "cosmossdk.io/errors" + gogoproto "github.com/cosmos/gogoproto/proto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/dynamicpb" - "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/types" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" @@ -34,20 +37,25 @@ func (m msgServer) ModuleQuerySafe(ctx context.Context, msg *types.MsgModuleQuer return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "not module query safe: %s", query.Path) } - // TODO: sort this out! - // if err := m.QueryRouterService.CanInvoke(ctx, query.Path); err != nil { - // return nil, errorsmod.Wrapf(err, "no route to query: %s", query.Path) - // } + path := strings.TrimPrefix(query.Path, "/") + pathFullName := protoreflect.FullName(strings.ReplaceAll(path, "/", ".")) + + desc, err := gogoproto.GogoResolver.FindDescriptorByName(pathFullName) + if err != nil { + return nil, err + } + + md, isGRPC := desc.(protoreflect.MethodDescriptor) + if !isGRPC { + return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidRequest, "no descriptor found for query path: %s", string(desc.FullName())) + } - // res, err := m.QueryRouterService.Invoke(ctx, &abci.QueryRequest{ - // Path: query.Path, - // Data: query.Data, - // }) + msg := dynamicpb.NewMessage(md.Input()) + if err := m.cdc.Unmarshal(query.Data, msg); err != nil { + return nil, err + } - res, err := m.QueryRouterService.Invoke(ctx, &cmtservice.ABCIQueryRequest{ - Path: query.Path, - Data: query.Data, - }) + res, err := m.QueryRouterService.Invoke(ctx, msg) if err != nil { m.Logger.Debug("query failed", "path", query.Path, "error", err) return nil, err