Skip to content

Commit

Permalink
chore: push temporary module safe query impl
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Dec 4, 2024
1 parent 7d7690e commit 68be8b5
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions modules/apps/27-interchain-accounts/host/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check failure on line 9 in modules/apps/27-interchain-accounts/host/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / lint

redundant-import-alias: Import alias "protoreflect" is redundant (revive)

Check failure on line 9 in modules/apps/27-interchain-accounts/host/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / lint

redundant-import-alias: Import alias "protoreflect" is redundant (revive)
"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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 68be8b5

Please sign in to comment.