-
Notifications
You must be signed in to change notification settings - Fork 203
/
query_effective_policy.go
66 lines (58 loc) · 1.77 KB
/
query_effective_policy.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
package cli
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/lavanet/lava/utils"
"github.com/lavanet/lava/utils/sigs"
"github.com/lavanet/lava/x/pairing/types"
"github.com/spf13/cobra"
)
func CmdEffectivePolicy() *cobra.Command {
cmd := &cobra.Command{
Use: "effective-policy [spec-id] [consumer/project]",
Short: "Query to show the effective policy of a consumer taking into account plan policy and subscription policy, consumer/project can also be defined as --from walletName",
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
specID := args[0]
var address string
if len(args) > 1 {
address = args[1]
} else {
clientCtxForTx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
keyName, err := sigs.GetKeyName(clientCtxForTx)
if err != nil {
utils.LavaFormatFatal("failed getting key name from clientCtx", err)
}
clientKey, err := clientCtxForTx.Keyring.Key(keyName)
if err != nil {
return err
}
addressAccount, err := clientKey.GetAddress()
if err != nil {
return err
}
address = addressAccount.String()
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
params := &types.QueryEffectivePolicyRequest{
Consumer: address,
SpecID: specID,
}
res, err := queryClient.EffectivePolicy(cmd.Context(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
cmd.Flags().String(flags.FlagFrom, "", "wallet name or address of the developer to query for, to be used instead of [consumer/project]")
flags.AddQueryFlagsToCmd(cmd)
return cmd
}