Skip to content

Commit

Permalink
fix some queries, CLI and permissionless logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Aug 29, 2024
1 parent b017871 commit 8db2423
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
12 changes: 6 additions & 6 deletions x/ccv/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func NewQueryCmd() *cobra.Command {
// parameters managed by the x/params module.
func CmdConsumerGenesis() *cobra.Command {
cmd := &cobra.Command{
Use: "consumer-genesis [chainid]",
Short: "Query for consumer chain genesis state by chain id",
Use: "consumer-genesis [consumer-id]",
Short: "Query for consumer chain genesis state by consumer id",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand Down Expand Up @@ -241,12 +241,12 @@ $ %s query provider validator-consumer-key foochain %s1gghjut3ccd8ay0zduzj64hwre
func CmdProviderValidatorKey() *cobra.Command {
bech32PrefixConsAddr := sdk.GetConfig().GetBech32ConsensusAddrPrefix()
cmd := &cobra.Command{
Use: "validator-provider-key [chainid] [consumer-validator-address]",
Use: "validator-provider-key [consumer-id] [consumer-validator-address]",
Short: "Query validator consensus public key for the provider chain",
Long: strings.TrimSpace(
fmt.Sprintf(`Returns the currently assigned validator consensus public key for the provider chain.
Example:
$ %s query provider validator-provider-key foochain %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
$ %s query provider validator-provider-key 333 %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
`,
version.AppName, bech32PrefixConsAddr,
),
Expand All @@ -259,15 +259,15 @@ $ %s query provider validator-provider-key foochain %s1gghjut3ccd8ay0zduzj64hwre
}
queryClient := types.NewQueryClient(clientCtx)

consumerChainID := args[0]
consumerID := args[0]

addr, err := sdk.ConsAddressFromBech32(args[1])
if err != nil {
return err
}

req := &types.QueryValidatorProviderAddrRequest{
ChainId: consumerChainID,
ConsumerId: consumerID,
ConsumerAddress: addr.String(),
}
res, err := queryClient.QueryValidatorProviderAddr(cmd.Context(), req)
Expand Down
35 changes: 7 additions & 28 deletions x/ccv/provider/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ Note that the one that signs this message is the owner of this consumer chain. T
changed by updating the consumer chain.
Example:
%s tx provider create-consumer [chain-id] [path/to/metadata.json] [path/to/initialization-parameters.json] [path/to/power-shaping-parameters.json] --from node0 --home ../node0 --chain-id $CID
%s tx provider create-consumer [path/to/create_consumer.json] --from node0 --home ../node0 --chain-id $CID
`, version.AppName)),
Args: cobra.ExactArgs(4),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -240,37 +240,16 @@ Example:

signer := clientCtx.GetFromAddress().String()

chainId := args[0]

metadata := types.ConsumerMetadata{}
metadataJson, err := os.ReadFile(args[1])
if err != nil {
return err
}
if err = json.Unmarshal(metadataJson, &metadata); err != nil {
return fmt.Errorf("metadata unmarshalling failed: %w", err)
}

initializationParameters := types.ConsumerInitializationParameters{}
initializationParametersJson, err := os.ReadFile(args[2])
if err != nil {
return err
}
if err = json.Unmarshal(initializationParametersJson, &initializationParameters); err != nil {
return fmt.Errorf("initialization parameters unmarshalling failed: %w", err)
}

powerShapingParameters := types.PowerShapingParameters{}

powerShapingParametersJson, err := os.ReadFile(args[3])
consCreateJson, err := os.ReadFile(args[0])
if err != nil {
return err
}
if err = json.Unmarshal(powerShapingParametersJson, &powerShapingParameters); err != nil {
return fmt.Errorf("power-shaping parameters unmarshalling failed: %w", err)
consCreate := types.MsgCreateConsumer{}
if err = json.Unmarshal(consCreateJson, &consCreate); err != nil {
return fmt.Errorf("consumer data unmarshalling failed: %w", err)
}

msg, err := types.NewMsgCreateConsumer(signer, chainId, metadata, &initializationParameters, &powerShapingParameters)
msg, err := types.NewMsgCreateConsumer(signer, consCreate.ChainId, consCreate.Metadata, consCreate.InitializationParameters, consCreate.PowerShapingParameters)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (k Keeper) QueryValidatorProviderAddr(goCtx context.Context, req *types.Que
}
consumerAddr := types.NewConsumerConsAddress(consumerAddrTmp)

providerAddr, found := k.GetValidatorByConsumerAddr(ctx, req.ChainId, consumerAddr)
providerAddr, found := k.GetValidatorByConsumerAddr(ctx, req.ConsumerId, consumerAddr)
if !found {
return &types.QueryValidatorProviderAddrResponse{}, nil
}
Expand Down

0 comments on commit 8db2423

Please sign in to comment.