Skip to content

Commit

Permalink
add parameter for url of the google api when defining RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
TimmyExogenous committed Oct 15, 2024
1 parent 082e5eb commit 39b5043
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 207 deletions.
24 changes: 12 additions & 12 deletions proto/exocore/operator/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ message QueryAllOperatorsResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// OperatorAVSAddressDetails includes the address of operator and AVS
message OperatorAVSAddressDetails {
// OperatorAVSAddress includes the address of operator and AVS
message OperatorAVSAddress {
// operator_addr should be the string type of sdk.AccAddress
string operator_addr = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// avs_address is the address of the AVS - either an 0x address or a chainID.
string avs_address = 2 [(gogoproto.customname) = "AVSAddress"];
string avs_address = 2;
}

// QueryOperatorUSDValueRequest is the request to obtain the USD value for operator.
message QueryOperatorUSDValueRequest {
// details is the operator and AVS address
OperatorAVSAddressDetails details = 1;
// operator_and_avs is the operator and AVS address
OperatorAVSAddress operator_and_avs = 1 [(gogoproto.embed) = true];;

Check failure on line 45 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" with name "operator_and_avs" on message "QueryOperatorUSDValueRequest" changed option "json_name" from "details" to "operatorAndAvs".

Check failure on line 45 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryOperatorUSDValueRequest" changed type from "exocore.operator.v1.OperatorAVSAddressDetails" to "exocore.operator.v1.OperatorAVSAddress".

Check failure on line 45 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryOperatorUSDValueRequest" changed name from "details" to "operator_and_avs".
}

// QueryOperatorUSDValueResponse is the response to obtain the USD value for operator.
Expand All @@ -62,8 +62,8 @@ message QueryAVSUSDValueRequest {
// QueryOperatorSlashInfoRequest is the request to obtain the slash information for the specified
// operator and AVS
message QueryOperatorSlashInfoRequest {
// details is the operator and AVS address
OperatorAVSAddressDetails details = 1;
// operator_and_avs is the operator and AVS address
OperatorAVSAddress operator_and_avs = 1 [(gogoproto.embed) = true];

Check failure on line 66 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" with name "operator_and_avs" on message "QueryOperatorSlashInfoRequest" changed option "json_name" from "details" to "operatorAndAvs".

Check failure on line 66 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryOperatorSlashInfoRequest" changed type from "exocore.operator.v1.OperatorAVSAddressDetails" to "exocore.operator.v1.OperatorAVSAddress".

Check failure on line 66 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryOperatorSlashInfoRequest" changed name from "details" to "operator_and_avs".
// pagination related options.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
Expand Down Expand Up @@ -217,8 +217,8 @@ message QueryAllAVSsByOperatorResponse {
// QueryOptInfoRequest is the request to obtain the opted information of specified operator
// and AVS
message QueryOptInfoRequest {
// details is the operator and AVS address
OperatorAVSAddressDetails details = 1;
// operator_and_avs is the operator and AVS address
OperatorAVSAddress operator_and_avs = 1 [(gogoproto.embed) = true];
}

// Query defines the gRPC querier service.
Expand Down Expand Up @@ -265,7 +265,7 @@ service Query {

// QueryOperatorUSDValue queries the opted-in USD value for the operator
rpc QueryOperatorUSDValue(QueryOperatorUSDValueRequest) returns(QueryOperatorUSDValueResponse){
option (google.api.http).get = "/exocore/operator/v1/QueryOperatorUSDValue";
option (google.api.http).get = "/exocore/operator/v1/QueryOperatorUSDValue/{operator_and_avs.operator_addr}/{operator_and_avs.avs_address}";
}

// QueryAVSUSDValue queries the USD value for the AVS
Expand All @@ -275,7 +275,7 @@ service Query {

// QueryOperatorSlashInfo queries the slash information for the specified operator and AVS
rpc QueryOperatorSlashInfo(QueryOperatorSlashInfoRequest) returns(QueryOperatorSlashInfoResponse){
option (google.api.http).get = "/exocore/operator/v1/QueryOperatorSlashInfo";
option (google.api.http).get = "/exocore/operator/v1/QueryOperatorSlashInfo/{operator_and_avs.operator_addr}/{operator_and_avs.avs_address}";
}

// QueryAllOperatorConsAddrsByChainID queries all operators and their consensus addresses
Expand Down Expand Up @@ -306,7 +306,7 @@ service Query {
// QueryOptInfo queries specified opted information.
rpc QueryOptInfo(QueryOptInfoRequest) returns (OptedInfo) {
option (google.api.http) = {
get: "/exocore/operator/v1/opt_info"
get: "/exocore/operator/v1/opt_info/{operator_and_avs.operator_addr}/{operator_and_avs.avs_address}"
};
}
}
29 changes: 21 additions & 8 deletions x/operator/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"strings"

"github.com/ExocoreNetwork/exocore/x/avs/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -261,15 +262,18 @@ func QueryOperatorUSDValue() *cobra.Command {
if err != nil {
return xerrors.Errorf("invalid operator address,err:%s", err.Error())
}
if !common.IsHexAddress(args[1]) {
return xerrors.Errorf("invalid avs address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := operatortypes.NewQueryClient(clientCtx)
req := &operatortypes.QueryOperatorUSDValueRequest{
Details: &operatortypes.OperatorAVSAddressDetails{
OperatorAVSAddress: &operatortypes.OperatorAVSAddress{
OperatorAddr: args[0],
AVSAddress: args[1],
AvsAddress: strings.ToLower(args[1]),
},
}
res, err := queryClient.QueryOperatorUSDValue(context.Background(), req)
Expand All @@ -292,13 +296,16 @@ func QueryAVSUSDValue() *cobra.Command {
Long: "Get the USD value for the avs",
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)
if err != nil {
return err
}
queryClient := operatortypes.NewQueryClient(clientCtx)
req := &operatortypes.QueryAVSUSDValueRequest{
AVSAddress: args[0],
AVSAddress: strings.ToLower(args[0]),
}
res, err := queryClient.QueryAVSUSDValue(context.Background(), req)
if err != nil {
Expand All @@ -325,6 +332,9 @@ func QueryOperatorSlashInfo() *cobra.Command {
if err != nil {
return xerrors.Errorf("invalid operator address,err:%s", err.Error())
}
if !common.IsHexAddress(args[1]) {
return xerrors.Errorf("invalid avs address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
Expand All @@ -335,9 +345,9 @@ func QueryOperatorSlashInfo() *cobra.Command {
}
queryClient := operatortypes.NewQueryClient(clientCtx)
req := &operatortypes.QueryOperatorSlashInfoRequest{
Details: &operatortypes.OperatorAVSAddressDetails{
OperatorAVSAddress: &operatortypes.OperatorAVSAddress{
OperatorAddr: args[0],
AVSAddress: args[1],
AvsAddress: strings.ToLower(args[1]),
},
Pagination: pageReq,
}
Expand Down Expand Up @@ -372,7 +382,7 @@ func QueryAllOperatorsWithOptInAVS() *cobra.Command {

queryClient := operatortypes.NewQueryClient(clientCtx)
req := operatortypes.QueryAllOperatorsByOptInAVSRequest{
Avs: args[0],
Avs: strings.ToLower(args[0]),
}
res, err := queryClient.QueryAllOperatorsWithOptInAVS(context.Background(), &req)
if err != nil {
Expand Down Expand Up @@ -431,15 +441,18 @@ func GetOptInfo() *cobra.Command {
if err != nil {
return xerrors.Errorf("invalid operator address,err:%s", err.Error())
}
if !common.IsHexAddress(args[1]) {
return xerrors.Errorf("invalid avs address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := operatortypes.NewQueryClient(clientCtx)
req := &operatortypes.QueryOptInfoRequest{
Details: &operatortypes.OperatorAVSAddressDetails{
OperatorAVSAddress: &operatortypes.OperatorAVSAddress{
OperatorAddr: args[0],
AVSAddress: args[1],
AvsAddress: strings.ToLower(args[1]),
},
}
res, err := queryClient.QueryOptInfo(context.Background(), req)
Expand Down
6 changes: 3 additions & 3 deletions x/operator/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (k Keeper) QueryAllOperatorConsAddrsByChainID(

func (k *Keeper) QueryOperatorUSDValue(ctx context.Context, req *types.QueryOperatorUSDValueRequest) (*types.QueryOperatorUSDValueResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
optedUSDValues, err := k.GetOperatorOptedUSDValue(c, req.Details.AVSAddress, req.Details.OperatorAddr)
optedUSDValues, err := k.GetOperatorOptedUSDValue(c, req.AvsAddress, req.OperatorAddr)
if err != nil {
return nil, err
}
Expand All @@ -203,7 +203,7 @@ func (k *Keeper) QueryOperatorSlashInfo(goCtx context.Context, req *types.QueryO
ctx := sdk.UnwrapSDKContext(goCtx)
res := make([]*types.OperatorSlashInfoByID, 0)

slashPrefix := types.AppendMany(types.KeyPrefixOperatorSlashInfo, assetstype.GetJoinedStoreKeyForPrefix(req.Details.OperatorAddr, req.Details.AVSAddress))
slashPrefix := types.AppendMany(types.KeyPrefixOperatorSlashInfo, assetstype.GetJoinedStoreKeyForPrefix(req.OperatorAddr, req.AvsAddress))
store := prefix.NewStore(ctx.KVStore(k.storeKey), slashPrefix)
pageRes, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error {
ret := &types.OperatorSlashInfo{}
Expand Down Expand Up @@ -251,5 +251,5 @@ func (k *Keeper) QueryAllAVSsByOperator(goCtx context.Context, req *types.QueryA

func (k *Keeper) QueryOptInfo(goCtx context.Context, req *types.QueryOptInfoRequest) (*types.OptedInfo, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
return k.GetOptedInfo(ctx, req.Details.OperatorAddr, req.Details.AVSAddress)
return k.GetOptedInfo(ctx, req.OperatorAddr, req.AvsAddress)
}
Loading

0 comments on commit 39b5043

Please sign in to comment.