Skip to content

Commit

Permalink
feat: agd vstorage 'path' for data or children
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Dec 15, 2023
1 parent d61be8d commit ac656d2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions golang/cosmos/x/vstorage/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/Agoric/agoric-sdk/golang/cosmos/x/vstorage/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/gogo/protobuf/proto"
"github.com/spf13/cobra"
)

Expand All @@ -18,6 +19,7 @@ func GetQueryCmd(storeKey string) *cobra.Command {
swingsetQueryCmd.AddCommand(
GetCmdGetData(storeKey),
GetCmdGetChildren(storeKey),
GetCmdGetPath(storeKey),
)

return swingsetQueryCmd
Expand Down Expand Up @@ -86,3 +88,44 @@ func GetCmdGetChildren(queryRoute string) *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// GetCmdGetPath queries vstorage data or children, depending on the path
func GetCmdGetPath(queryRoute string) *cobra.Command {
cmd := &cobra.Command{
Use: "path [path]",
Short: "get vstorage data, or children if path ends with '.'",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

path := args[0]

var res proto.Message

// if path ends with '.' then remove it and query children
if path[len(path)-1] == '.' {
path = path[:len(path)-1]
res, err = queryClient.Children(cmd.Context(), &types.QueryChildrenRequest{
Path: path,
})
} else {
res, err = queryClient.Data(cmd.Context(), &types.QueryDataRequest{
Path: path,
})
}

if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}

0 comments on commit ac656d2

Please sign in to comment.