-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add queries for PSS and consumer commission rate #1733
Changes from 29 commits
b0d4cf9
0162242
7ad2993
5cd5ba5
5393f19
03af237
07429fa
0ab0b32
1a0fa9e
56ca38d
c614fd2
6503f9b
330c085
629cfd1
afd4652
2e95f89
a9db491
1e3a8e7
149ba7a
24be8b2
b311f35
22ca561
5509108
ad91b0e
559b28f
00e43a9
4f9084f
d4fc4cb
938d930
9739ddd
c01ab08
4661a99
219d310
10dbb53
d642e8a
69d0b28
f9e63f0
3ae3031
ed402f8
c75594f
899f3ea
b1c1beb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,9 @@ func NewQueryCmd() *cobra.Command { | |
cmd.AddCommand(CmdProposedConsumerChains()) | ||
cmd.AddCommand(CmdAllPairsValConAddrByConsumerChainID()) | ||
cmd.AddCommand(CmdProviderParameters()) | ||
cmd.AddCommand(CmdConsumerChainOptedInValidators()) | ||
cmd.AddCommand(CmdConsumerChainsValidatorHasToValidate()) | ||
cmd.AddCommand(CmdValidatorConsumerCommissionRate()) | ||
return cmd | ||
} | ||
|
||
|
@@ -409,3 +412,123 @@ $ %s query provider params | |
|
||
return cmd | ||
} | ||
|
||
// Command to query opted-in validators by consumer chain ID | ||
func CmdConsumerChainOptedInValidators() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "consumer-opted-in-validators [chainid]", | ||
Short: "Query opted-in validators for a given consumer chain", | ||
Long: strings.TrimSpace( | ||
fmt.Sprintf(`Query opted-in validators for a given consumer chain. | ||
Example: | ||
$ %s consumer-opted-in-validators foochain | ||
`, version.AppName), | ||
), | ||
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) | ||
|
||
res, err := queryClient.QueryConsumerChainOptedInValidators(cmd.Context(), | ||
&types.QueryConsumerChainOptedInValidatorsRequest{ChainId: args[0]}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
// Command to query the consumer chains list a given validator has to validate | ||
func CmdConsumerChainsValidatorHasToValidate() *cobra.Command { | ||
bech32PrefixConsAddr := sdk.GetConfig().GetBech32ConsensusAddrPrefix() | ||
cmd := &cobra.Command{ | ||
Use: "has-to-validate [provider-validator-address]", | ||
Short: "Query the consumer chains list a given validator has to validate", | ||
Long: strings.TrimSpace( | ||
fmt.Sprintf(`Query the consumer chains list a given validator has to validate. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we make this a bit more explicit? |
||
Example: | ||
$ %s has-to-validate %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj | ||
`, version.AppName, bech32PrefixConsAddr), | ||
), | ||
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) | ||
|
||
addr, err := sdk.ConsAddressFromBech32(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, err := queryClient.QueryConsumerChainsValidatorHasToValidate(cmd.Context(), | ||
&types.QueryConsumerChainsValidatorHasToValidateRequest{ | ||
ProviderAddress: addr.String(), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
// Command to query the consumer commission rate a validator charges | ||
// on a consumer chain | ||
func CmdValidatorConsumerCommissionRate() *cobra.Command { | ||
bech32PrefixConsAddr := sdk.GetConfig().GetBech32ConsensusAddrPrefix() | ||
cmd := &cobra.Command{ | ||
Use: "validator-consumer-commission-rate [chainid] [provider-validator-address]", | ||
Short: "Query the consumer commission rate a validator charges on a consumer chain", | ||
Long: strings.TrimSpace( | ||
fmt.Sprintf(`Query the consumer commission rate a validator charges on a consumer chain. | ||
Example: | ||
$ %s validator-consumer-commission-rate foochain %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj | ||
`, version.AppName, bech32PrefixConsAddr), | ||
), | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
addr, err := sdk.ConsAddressFromBech32(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, err := queryClient.QueryValidatorConsumerCommissionRate(cmd.Context(), | ||
&types.QueryValidatorConsumerCommissionRateRequest{ | ||
ChainId: args[0], | ||
ProviderAddress: addr.String(), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -249,9 +249,16 @@ func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) { | |||||
chainID := string(iterator.Key()[1:]) | ||||||
clientID := string(iterator.Value()) | ||||||
|
||||||
// Get the consumer TopN value by checking | ||||||
// if the chain is a TopN chain, | ||||||
// otherwise it's a OptIn chain | ||||||
topN, isTopN := k.GetTopN(ctx, chainID) | ||||||
|
||||||
chains = append(chains, types.Chain{ | ||||||
ChainId: chainID, | ||||||
ClientId: clientID, | ||||||
Opt_In: !isTopN, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, below in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sense, thanks. Updated. |
||||||
Top_N: topN, | ||||||
}) | ||||||
} | ||||||
|
||||||
|
@@ -1296,4 +1303,4 @@ func (k Keeper) DeleteConsumerCommissionRate( | |||||
) { | ||||||
store := ctx.KVStore(k.storeKey) | ||||||
store.Delete(types.ConsumerCommissionRateKey(chainID, providerAddr)) | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this? (it's more clear for users is a perfectly fine reason if you think it applies)
Can't we keep the TopN == 0 means it's an opt-in chain, and just have the TopN field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need it in the logic. The intention was to make it clearer for the user. But after some thought, it can actually be removed.