Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Feb 20, 2025
1 parent 484a8f3 commit 2683d70
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions x/avs/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,13 @@ func QueryAVSInfo() *cobra.Command {
Use: "AVSInfo query <avsAddr>",
Short: "AVSInfo query",
Long: "AVSInfo query for current registered AVS",
Example: fmt.Sprintf("%s query avs AVSInfo 0x598ACcB5e7F83cA6B19D70592Def9E5b25B978CA", version.AppName),
Example: fmt.Sprintf("%s query avs AVSInfo 0x598ACcB5e7F83cA6B19D70592Def9E5b25B978CA", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if !common.IsHexAddress(args[0]) {
return xerrors.Errorf("invalid avs address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
queryClient, clientCtx, err := commonQuerySetup(cmd, args[0])
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryAVSInfoReq{
AVSAddress: args[0],
}
Expand All @@ -76,12 +71,12 @@ func QueryAVSAddressByChainID() *cobra.Command {
Example: fmt.Sprintf("%s query avs AVSAddrByChainID imuachaintestnet_233-1", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
// pass the default address so it doesn't matter
queryClient, clientCtx, err := commonQuerySetup(cmd, common.Address{}.Hex())
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QueryAVSAddressByChainIDReq{
Chain: args[0],
}
Expand All @@ -96,6 +91,21 @@ func QueryAVSAddressByChainID() *cobra.Command {
return cmd
}

// commonQuerySetup handles the common setup logic for query commands
func commonQuerySetup(cmd *cobra.Command, taskAddress string) (types.QueryClient, client.Context, error) {
if !common.IsHexAddress(taskAddress) {
return nil, client.Context{}, xerrors.Errorf("invalid address,err:%s", types.ErrInvalidAddr)
}

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return nil, client.Context{}, err
}

queryClient := types.NewQueryClient(clientCtx)
return queryClient, clientCtx, nil
}

func QueryTaskInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "TaskInfo <task-address-in-hex> <task-id>",
Expand All @@ -104,15 +114,11 @@ func QueryTaskInfo() *cobra.Command {
Example: fmt.Sprintf("%s query avs TaskInfo 0x96949787E6a209AFb4dE035754F79DC9982D3F2a 2", version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
if !common.IsHexAddress(args[0]) {
return xerrors.Errorf("invalid task address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
queryClient, clientCtx, err := commonQuerySetup(cmd, args[0])
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := types.QueryAVSTaskInfoReq{
TaskAddress: args[0],
TaskId: args[1],
Expand All @@ -136,15 +142,10 @@ func QuerySubmitTaskResult() *cobra.Command {
Example: fmt.Sprintf("%s query avs SubmitTaskResult 0x96949787E6a209AFb4dE035754F79DC9982D3F2a 2 im18cggcpvwspnd5c6ny8wrqxpffj5zmhkl3agtrj", version.AppName),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
if !common.IsHexAddress(args[0]) {
return xerrors.Errorf("invalid address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
queryClient, clientCtx, err := commonQuerySetup(cmd, args[0])
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := types.QuerySubmitTaskResultReq{
TaskAddress: args[0],
TaskId: args[1],
Expand All @@ -165,19 +166,15 @@ func QueryChallengeInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "ChallengeInfo <task-address-in-hex> <task-id>",
Short: "Query the ChallengeInfo by taskAddr and taskID",
Long: "Query the currently Challenge Info ",
Example: fmt.Sprintf("%s query avs ChallengeInfo 0x96949787E6a209AFb4dE035754F79DC9982D3F2a 2 im18cggcpvwspnd5c6ny8wrqxpffj5zmhkl3agtrj", version.AppName),
Args: cobra.ExactArgs(3),
Long: "Query the currently Challenge Info",
Example: fmt.Sprintf("%s query avs ChallengeInfo 0x96949787E6a209AFb4dE035754F79DC9982D3F2a 2", version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
if !common.IsHexAddress(args[0]) {
return xerrors.Errorf("invalid address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
queryClient, clientCtx, err := commonQuerySetup(cmd, args[0])
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := types.QueryChallengeInfoReq{
TaskAddress: args[0],
TaskId: args[1],
Expand Down

0 comments on commit 2683d70

Please sign in to comment.