Skip to content

Commit

Permalink
add some query cli
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Aug 25, 2024
1 parent 87ec5a6 commit 922a6a4
Show file tree
Hide file tree
Showing 13 changed files with 2,668 additions and 241 deletions.
42 changes: 42 additions & 0 deletions proto/exocore/avs/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,43 @@ message QueryAVSTaskInfoReq {
// task_addr is the task contract address,its type should be a sdk.AccAddress
string task_addr = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// task_id is the task identifier
string task_id = 2 ;
}

// QuerySubmitTaskResultReq is the request to obtain the task information.
message QuerySubmitTaskResultReq {
// task_addr is the task contract address,its type should be a sdk.AccAddress
string task_addr = 1 [(gogoproto.customname) = "TaskAddress"];
// task_id is the task identifier
string task_id = 2 ;
// operator_addr is the operator address,its type should be a sdk.AccAddress
string operator_addr = 3
[(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// QueryChallengeInfoReq is the request to obtain the task information.
message QueryChallengeInfoReq {
// task_addr is the task contract address,its type should be a sdk.AccAddress
string task_addr = 1 [(gogoproto.customname) = "TaskAddress"];
// task_id is the task identifier
string task_id = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// operator_addr is the operator address,its type should be a sdk.AccAddress
string operator_addr = 3
[(cosmos_proto.scalar) = "cosmos.AddressString"];
}


// QuerySubmitTaskResultResponse is the response of avs related information
message QuerySubmitTaskResultResponse {
// info is the taskResult.
TaskResultInfo info = 1;
}

// QueryChallengeInfoResponse is the response of avs related information
message QueryChallengeInfoResponse {
// challenge_addr is the challenge address,its type should be a common.HexAddress.
string challenge_addr = 1;
}
// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
Expand All @@ -54,4 +88,12 @@ service Query {
rpc QueryAVSAddrByChainID(QueryAVSAddrByChainIDReq) returns (QueryAVSAddrByChainIDResponse) {
option (google.api.http).get = "/exocore/avs/QueryAVSAddrByChainID";
}
// Parameters queries the parameters of the module.
rpc QuerySubmitTaskResult(QuerySubmitTaskResultReq) returns (QuerySubmitTaskResultResponse) {
option (google.api.http).get = "/exocore/avs/QuerySubmitTaskResult";
}
// Parameters queries the parameters of the module.
rpc QueryChallengeInfo(QueryChallengeInfoReq) returns (QueryChallengeInfoResponse) {
option (google.api.http).get = "/exocore/avs/QueryChallengeInfo";
}
}
2 changes: 1 addition & 1 deletion proto/exocore/avs/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ message SubmitTaskResultReq {
// from_address is the address of the operator (sdk.AccAddress).
string from_address = 1
[(cosmos_proto.scalar) = "cosmos.AddressString"];
// info is the operator info.
// info is the taskResult.
TaskResultInfo info = 2;
}
// SubmitTaskResultResponse is the response to submit task results.
Expand Down
42 changes: 42 additions & 0 deletions proto/exocore/operator/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,34 @@ message OperatorConsAddrPair {
bool opting_out = 3;
}


// QueryAllOperatorsWithOptInAVSRequest is the request to obtain all opt-in operator addresses
// for a specific avs with pagination.
message QueryAllOperatorsWithOptInAVSRequest {
// avs address
string avs = 1;
}

// QueryAllOperatorsWithOptInAVSResponse is the response that includes a list of all avs
// for a specified operator address.
message QueryAllOperatorsWithOptInAVSResponse {
// operator_list is a list of operator addresses.
repeated string operator_list = 1;
}

// QueryAllAVSsByOperatorRequest is the request to obtain all operator addresses
// and consensus keys for a specific chain ID, with pagination.
message QueryAllAVSsByOperatorRequest {
// operator address.
string operator = 1;
}

// QueryAllAVSsByOperatorResponse is the response that includes a list of all operators
// and their consensus keys for a specified chain ID.
message QueryAllAVSsByOperatorResponse {
// avs_list is a list of avs addresses .
repeated string avs_list = 1;
}
// Query defines the gRPC querier service.
service Query {
// QueryOperatorInfo queries the operator information.
Expand Down Expand Up @@ -251,4 +279,18 @@ service Query {
get: "/exocore/operator/v1/all_operator_cons_addrs/{chain}"
};
}

// QueryAllOperatorsWithOptInAVS queries operator list by avs.
rpc QueryAllOperatorsWithOptInAVS(QueryAllOperatorsWithOptInAVSRequest) returns (QueryAllOperatorsWithOptInAVSResponse) {
option (google.api.http) = {
get: "/exocore/operator/v1/opt/operator_list/{avs}"
};
}

// QueryAllAVSsByOperator queries avs list.
rpc QueryAllAVSsByOperator(QueryAllAVSsByOperatorRequest) returns (QueryAllAVSsByOperatorResponse) {
option (google.api.http) = {
get: "/exocore/operator/v1/opt/avs_list/{operator}"
};
}
}
73 changes: 70 additions & 3 deletions x/avs/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ func GetQueryCmd(_ string) *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(QueryAVSInfo())
cmd.AddCommand(QueryAVSAddrByChainID())
cmd.AddCommand(QueryTaskInfo())
cmd.AddCommand(
QueryAVSInfo(),
QueryAVSAddrByChainID(),
QueryTaskInfo(),
QueryChallengeInfo(),
QuerySubmitTaskResult(),
)
return cmd
}

Expand Down Expand Up @@ -120,3 +124,66 @@ func QueryTaskInfo() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func QuerySubmitTaskResult() *cobra.Command {
cmd := &cobra.Command{
Use: "SubmitTaskResult <task-address-in-hex> <task-id> <operator-addreess>",
Short: "Query the SubmitTaskResult by taskAddr taskID operatorAddr",
Long: "Query the currently submitted Task Result",
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)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := types.QuerySubmitTaskResultReq{
TaskAddress: args[0],
TaskId: args[1],
OperatorAddr: args[2],
}
res, err := queryClient.QuerySubmitTaskResult(context.Background(), &req)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

Check failure on line 158 in x/avs/client/cli/query.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)
func QueryChallengeInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "ChallengeInfo <task-address-in-hex> <task-id> <operator-addreess>",
Short: "Query the ChallengeInfo by taskAddr taskID operatorAddr",
Long: "Query the currently Challenge Info ",
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)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := types.QueryChallengeInfoReq{
TaskAddress: args[0],
TaskId: args[1],
OperatorAddr: args[2],
}
res, err := queryClient.QueryChallengeInfo(context.Background(), &req)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
26 changes: 26 additions & 0 deletions x/avs/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"strconv"

"github.com/ExocoreNetwork/exocore/x/avs/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -28,3 +29,28 @@ func (k Keeper) QueryAVSAddrByChainID(ctx context.Context, req *types.QueryAVSAd
}
return &types.QueryAVSAddrByChainIDResponse{AVSAddress: avsAddr.String()}, nil
}

Check failure on line 31 in x/avs/keeper/query.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not `gofumpt`-ed (gofumpt)
func (k Keeper) QuerySubmitTaskResult(ctx context.Context, req *types.QuerySubmitTaskResultReq) (*types.QuerySubmitTaskResultResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
id, err := strconv.ParseUint(req.TaskId, 10, 64)
if err != nil {
return &types.QuerySubmitTaskResultResponse{}, err
}

info, err := k.GetTaskResultInfo(c, req.OperatorAddr, req.TaskAddress, id)
return &types.QuerySubmitTaskResultResponse{
Info: info,
}, err
}

func (k Keeper) QueryChallengeInfo(ctx context.Context, req *types.QueryChallengeInfoReq) (*types.QueryChallengeInfoResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
id, err := strconv.ParseUint(req.TaskId, 10, 64)
if err != nil {
return &types.QueryChallengeInfoResponse{}, err
}

addr, err := k.GetTaskChallengedInfo(c, req.OperatorAddr, req.TaskAddress, id)
return &types.QueryChallengeInfoResponse{
ChallengeAddr: addr,
}, err
}
16 changes: 16 additions & 0 deletions x/avs/keeper/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,19 @@ func (k *Keeper) IsExistTaskChallengedInfo(ctx sdk.Context, operatorAddress, tas
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixTaskChallengeResult)
return store.Has(infoKey)
}

func (k *Keeper) GetTaskChallengedInfo(ctx sdk.Context, operatorAddress, taskContractAddress string, taskID uint64) (addr string, err error) {
if !common.IsHexAddress(taskContractAddress) {
return "", types.ErrInvalidAddr
}
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixTaskChallengeResult)
infoKey := assetstype.GetJoinedStoreKey(operatorAddress, taskContractAddress,
strconv.FormatUint(taskID, 10))
value := store.Get(infoKey)
if value == nil {
return "", errorsmod.Wrap(types.ErrNoKeyInTheStore,
fmt.Sprintf("GetTaskChallengedInfo: key is %s", infoKey))
}

return common.Bytes2Hex(value), nil
}
Loading

0 comments on commit 922a6a4

Please sign in to comment.