-
Notifications
You must be signed in to change notification settings - Fork 327
/
query_state_info.go
71 lines (60 loc) · 2.03 KB
/
query_state_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cli
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const (
FlagStateIndex = "index"
FlagRollappHeight = "rollapp-height"
FlagFinalized = "finalized"
)
func CmdShowStateInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "state [rollapp-id]",
Short: "Query the state associated with the specified rollapp-id and any other flags. If no flags are provided, return the latest state.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
argRollappId := args[0]
flagSet := cmd.Flags()
argIndex, err := flagSet.GetUint64(FlagStateIndex)
if err != nil {
return err
}
argHeight, err := flagSet.GetUint64(FlagRollappHeight)
if err != nil {
return err
}
argFinalized, err := flagSet.GetBool(FlagFinalized)
if err != nil {
return err
}
if (argHeight != 0 && argIndex != 0) || (argHeight != 0 && argFinalized) || (argIndex != 0 && argFinalized) {
return status.Error(codes.InvalidArgument, fmt.Sprintf("only one flag can be use for %s, %s or %s", FlagStateIndex, FlagRollappHeight, FlagFinalized))
}
params := &types.QueryGetStateInfoRequest{
RollappId: argRollappId,
Index: argIndex,
Height: argHeight,
Finalized: argFinalized,
}
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.StateInfo(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
cmd.Flags().Uint64(FlagStateIndex, 0, "Use a specific state-index to query state-info at")
cmd.Flags().Uint64(FlagRollappHeight, 0, "Use a specific height of the rollapp to query state-info at")
cmd.Flags().Bool(FlagFinalized, false, "Indicates whether to return the latest finalized state")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}