-
Notifications
You must be signed in to change notification settings - Fork 117
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
[CORE-696] - Add query endpoint for x/rewards GetRewardShare. #673
Conversation
WalkthroughThe changes introduce a new feature to query reward shares by address in the dydxprotocol. This includes updates to the protocol's proto definitions, client CLI commands, keeper functions, and tests. Additionally, the indexer package is updated to support this new feature, including new interfaces, functions, and types. Changes
TipsChat with CodeRabbit Bot (
|
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.
Review Status
Actionable comments generated: 2
Files ignored due to filter (2)
- protocol/x/rewards/types/query.pb.go
- protocol/x/rewards/types/query.pb.gw.go
Files selected for processing (5)
- proto/dydxprotocol/rewards/query.proto (3 hunks)
- protocol/x/rewards/client/cli/query_reward_share.go (1 hunks)
- protocol/x/rewards/client/cli/query_reward_share_test.go (1 hunks)
- protocol/x/rewards/keeper/grpc_query.go (1 hunks)
- protocol/x/rewards/keeper/grpc_query_test.go (2 hunks)
Additional comments (Suppressed): 6
protocol/x/rewards/keeper/grpc_query_test.go (2)
4-7: The import of
github.com/dydxprotocol/v4-chain/protocol/dtypes
is new in this hunk. Ensure that this import is necessary and used in the code. If it's not used, it should be removed to keep the code clean and maintainable.49-91: The new test
TestQueryRewardShare
is well-structured and covers the main success scenario and the case where the request isnil
. It's good to see that the test checks both the error and the response object in each case. However, consider adding more test cases to cover other possible error scenarios, such as when theRewardShare
for a given address does not exist in the store.proto/dydxprotocol/rewards/query.proto (3)
1-11: The new import statements for "cosmos_proto/cosmos.proto" and "dydxprotocol/rewards/reward_share.proto" are added to support the new RPC method
RewardShare
. Ensure that these files exist and are accessible from this location.15-22: A new RPC method
RewardShare
is added to theQuery
service. This method takesQueryRewardShareRequest
as input and returnsQueryRewardShareResponse
. The HTTP GET path for this method is "/dydxprotocol/v4/rewards/shares/{address}". Ensure that this path does not conflict with any existing paths in your application.33-41: New message types
QueryRewardShareRequest
andQueryRewardShareResponse
are added to support theRewardShare
RPC method.QueryRewardShareRequest
takes a stringaddress
as input, andQueryRewardShareResponse
returns aRewardShare
object. Ensure that theRewardShare
object is correctly defined in "dydxprotocol/rewards/reward_share.proto".protocol/x/rewards/keeper/grpc_query.go (1)
- 23-35: The
RewardShare
function is well implemented. It correctly checks if the request isnil
and returns an error if so. It also correctly unwraps the context and retrieves the reward share using theGetRewardShare
function. However, it's important to ensure that theGetRewardShare
function handles errors properly, as any errors that occur within it will not be caught in this function. IfGetRewardShare
can return an error, you should modify the function to return that error and handle it inRewardShare
.Here's a potential modification if
GetRewardShare
can return an error:return &types.QueryRewardShareResponse{ - RewardShare: k.GetRewardShare(ctx, req.Address), + RewardShare, err := k.GetRewardShare(ctx, req.Address), }, nil + if err != nil { + return nil, status.Error(codes.Internal, "failed to get reward share") + } + return &types.QueryRewardShareResponse{RewardShare: RewardShare}, nil }
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.
Review Status
Actionable comments generated: 1
Files selected for processing (3)
- indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.lcd.ts (3 hunks)
- indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.rpc.Query.ts (2 hunks)
- indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.ts (3 hunks)
Additional comments (Suppressed): 10
indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.lcd.ts (3)
2-2: The import statement has been updated to include
QueryRewardShareRequest
andQueryRewardShareResponseSDKType
from./query
. Ensure that these types are correctly defined in the./query
file.13-13: The
rewardShare
method is being bound to thethis
context of theLCDQueryClient
class. This is a standard practice in JavaScript to ensure that the method has the correct context when called.25-28: A new method
rewardShare
has been added to theLCDQueryClient
class. This method takes aQueryRewardShareRequest
object as a parameter and returns aPromise
that resolves to aQueryRewardShareResponseSDKType
object. The method constructs an endpoint URL using theaddress
property of the request object and sends a GET request to this endpoint. Ensure that the server-side endpoint is correctly set up to handle these requests and return the expected data.indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.rpc.Query.ts (5)
4-4: The import statement has been updated to include
QueryRewardShareRequest
andQueryRewardShareResponse
from./query
. This is necessary for the newrewardShare
function.12-12: A new function
rewardShare
has been added to theQuery
interface. This function takes aQueryRewardShareRequest
and returns aPromise<QueryRewardShareResponse>
.20-20: The
rewardShare
function is bound tothis
in theQueryClientImpl
constructor. This ensures that the function can be called with the correct context.29-33: The
rewardShare
function is implemented in theQueryClientImpl
class. It encodes the request, sends it to thedydxprotocol.rewards.Query
service with theRewardShare
method, and decodes the response.44-45: The
rewardShare
function is added to the return object ofcreateRpcQueryExtension
. This allows it to be called on the extendedQueryClient
.indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.ts (2)
1-5: The import statement for
RewardShare
andRewardShareSDKType
has been added. This is necessary for the newQueryRewardShareRequest
andQueryRewardShareResponse
interfaces that have been introduced.116-209: New functions
createBaseQueryRewardShareRequest
,QueryRewardShareRequest.encode
,QueryRewardShareRequest.decode
,QueryRewardShareRequest.fromPartial
,createBaseQueryRewardShareResponse
,QueryRewardShareResponse.encode
,QueryRewardShareResponse.decode
, andQueryRewardShareResponse.fromPartial
have been added. These functions are used for creating, encoding, decoding, and creating from partial objects forQueryRewardShareRequest
andQueryRewardShareResponse
. ThecreateBaseQueryRewardShareRequest
function initializes theaddress
property to an empty string, and thecreateBaseQueryRewardShareResponse
function initializes therewardShare
property toundefined
.
export interface QueryParamsResponseSDKType { | ||
params?: ParamsSDKType; | ||
} | ||
/** QueryRewardShareRequest is a request type for the RewardShare RPC method. */ | ||
|
||
export interface QueryRewardShareRequest { | ||
address: string; | ||
} | ||
/** QueryRewardShareRequest is a request type for the RewardShare RPC method. */ | ||
|
||
export interface QueryRewardShareRequestSDKType { | ||
address: string; | ||
} | ||
/** QueryRewardShareResponse is a response type for the RewardsShare RPC method. */ | ||
|
||
export interface QueryRewardShareResponse { | ||
rewardShare?: RewardShare; | ||
} | ||
/** QueryRewardShareResponse is a response type for the RewardsShare RPC method. */ | ||
|
||
export interface QueryRewardShareResponseSDKType { | ||
reward_share?: RewardShareSDKType; | ||
} |
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.
New interfaces QueryRewardShareRequest
, QueryRewardShareRequestSDKType
, QueryRewardShareResponse
, and QueryRewardShareResponseSDKType
have been added. These interfaces are used for the new RewardShare
RPC method. The QueryRewardShareRequest
and QueryRewardShareRequestSDKType
interfaces have an address
property, and the QueryRewardShareResponse
and QueryRewardShareResponseSDKType
interfaces have a rewardShare
property. The rewardShare
property in QueryRewardShareResponseSDKType
should be rewardShare
to maintain consistency with the other interfaces.
- reward_share?: RewardShareSDKType;
+ rewardShare?: RewardShareSDKType;
Changelist
Add query endpoint for x/rewards GetRewardShare
Test Plan
appropriate unit and cli tests.
Author/Reviewer Checklist
state-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.