-
Notifications
You must be signed in to change notification settings - Fork 199
/
query_provider_delegators.go
54 lines (44 loc) · 1.44 KB
/
query_provider_delegators.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
package cli
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/spf13/cobra"
"github.com/lavanet/lava/utils"
"github.com/lavanet/lava/x/dualstaking/types"
)
func CmdQueryProviderDelegators() *cobra.Command {
cmd := &cobra.Command{
Use: "provider-delegators [provider]",
Short: "shows all the delegators of a specific provider",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
provider, err := utils.ParseCLIAddress(clientCtx, args[0])
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
// check if the command includes --with-pending
withPendingDelegationsFlag := cmd.Flags().Lookup(WithPendingDelegatorsFlagName)
if withPendingDelegationsFlag == nil {
return fmt.Errorf("%s flag wasn't found", WithPendingDelegatorsFlagName)
}
withPendingDelegations := withPendingDelegationsFlag.Changed
res, err := queryClient.ProviderDelegators(cmd.Context(), &types.QueryProviderDelegatorsRequest{
Provider: provider,
WithPending: withPendingDelegations,
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
cmd.Flags().Bool(WithPendingDelegatorsFlagName, false, "output with pending delegations (applied from next epoch)")
return cmd
}