Skip to content
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

feat(x/nft): add new queries for nft modules that support query string #18355

Merged
merged 14 commits into from
Nov 17, 2023

Conversation

hieuvubk
Copy link
Contributor

@hieuvubk hieuvubk commented Nov 3, 2023

Description

Closes: #17488

  • Addes new versions for Balance, Owner, Supply, NFT, Class that receives request via query string.

  • Tested new funcs


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

  • New Features

    • Introduced new query capabilities for NFT balances, owners, supplies, NFTs, and classes using query strings.
    • Enhanced existing RPC methods with query parameters for more dynamic searches.
  • Documentation

    • Updated CHANGELOG to reflect the addition of new query methods and parameters.

@hieuvubk hieuvubk requested a review from a team as a code owner November 3, 2023 10:23
Copy link
Contributor

coderabbitai bot commented Nov 3, 2023

Walkthrough

Walkthrough

The Cosmos NFT module has been updated to include new RPC methods that allow querying NFT data using query strings. These additions provide alternative ways to request information about NFT balances, owners, supplies, individual NFTs, and classes. The changes are reflected in the service's protocol buffers and the corresponding Go implementation, including tests. The updates are documented in the module's changelog, highlighting the new query capabilities introduced in the system.

Changes

File Path Change Summary
proto/cosmos/nft/v1beta1/query.proto Added new RPC methods with "ByQueryString" suffix and corresponding request/response message types for querying NFT data using query strings.
x/nft/keeper/grpc_query.go Implemented new functions in the Keeper struct to handle the new query string-based RPC methods.
x/nft/keeper/grpc_query_test.go Added tests for the new query string-based functions to ensure correct functionality and error handling.
x/nft/CHANGELOG.md Documented the addition of new query string-based versions for existing NFT queries, marking the update as part of pull request #18355.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2caf00d and 0b9f754.
Files ignored due to filter (4)
  • api/cosmos/nft/v1beta1/query_grpc.pb.go
  • client/docs/swagger-ui/swagger.yaml
  • x/nft/query.pb.go
  • x/nft/query.pb.gw.go
Files selected for processing (3)
  • proto/cosmos/nft/v1beta1/query.proto (5 hunks)
  • x/nft/keeper/grpc_query.go (5 hunks)
  • x/nft/keeper/grpc_query_test.go (5 hunks)
Additional comments: 25
x/nft/keeper/grpc_query.go (5)
  • 34-56: The function BalanceByQueryString is similar to Balance but accepts a request via a query string. Ensure that the query string is properly parsed and validated before being used in the function. Also, consider adding error handling for invalid query strings.

  • 81-109: The function OwnerByQueryString is similar to Owner but accepts a request via a query string. Ensure that the query string is properly parsed and validated before being used in the function. Also, consider adding error handling for invalid query strings.

  • 122-138: The function SupplyByQueryString is similar to Supply but accepts a request via a query string. Ensure that the query string is properly parsed and validated before being used in the function. Also, consider adding error handling for invalid query strings.

  • 220-242: The function NFTByQueryString is similar to NFT but accepts a request via a query string. Ensure that the query string is properly parsed and validated before being used in the function. Also, consider adding error handling for invalid query strings.

  • 260-279: The function ClassByQueryString is similar to Class but accepts a request via a query string. Ensure that the query string is properly parsed and validated before being used in the function. Also, consider adding error handling for invalid query strings.

proto/cosmos/nft/v1beta1/query.proto (15)
  • 14-20: The new RPC method BalanceByQueryString has been added. Ensure that the server-side implementation correctly handles the query string parameters.

  • 28-30: The new RPC method OwnerByQueryString has been added. Ensure that the server-side implementation correctly handles the query string parameters.

  • 38-40: The new RPC method SupplyByQueryString has been added. Ensure that the server-side implementation correctly handles the query string parameters.

  • 54-56: The new RPC method NFTByQueryString has been added. Ensure that the server-side implementation correctly handles the query string parameters.

  • 64-66: The new RPC method ClassByQueryString has been added. Ensure that the server-side implementation correctly handles the query string parameters.

  • 83-90: The new request message type QueryBalanceByQueryStringRequest has been added. Ensure that the server-side implementation correctly handles the fields in this message.

  • 98-102: The new response message type QueryBalanceByQueryStringResponse has been added. Ensure that the server-side implementation correctly populates the fields in this message.

  • 113-120: The new request message type QueryOwnerByQueryStringRequest has been added. Ensure that the server-side implementation correctly handles the fields in this message.

  • 128-132: The new response message type QueryOwnerByQueryStringResponse has been added. Ensure that the server-side implementation correctly populates the fields in this message.

  • 140-144: The new request message type QuerySupplyByQueryStringRequest has been added. Ensure that the server-side implementation correctly handles the fields in this message.

  • 152-156: The new response message type QuerySupplyByQueryStringResponse has been added. Ensure that the server-side implementation correctly populates the fields in this message.

  • 188-195: The new request message type QueryNFTByQueryStringRequest has been added. Ensure that the server-side implementation correctly handles the fields in this message.

  • 203-207: The new response message type QueryNFTByQueryStringResponse has been added. Ensure that the server-side implementation correctly populates the fields in this message.

  • 215-219: The new request message type QueryClassByQueryStringRequest has been added. Ensure that the server-side implementation correctly handles the fields in this message.

  • 227-231: The new response message type QueryClassByQueryStringResponse has been added. Ensure that the server-side implementation correctly populates the fields in this message.

x/nft/keeper/grpc_query_test.go (5)
  • 83-146: The TestBalanceByQueryString function tests the BalanceByQueryString method. It covers various scenarios including empty ClassId, invalid Owner address, and successful query. The test cases are well-structured and cover the necessary edge cases. However, it would be better to add a test case for a non-existent Owner address.

  • 237-324: The TestOwnerByQueryString function tests the OwnerByQueryString method. It covers various scenarios including empty ClassId, empty nft id, non-existent nft id, non-existent ClassId, and successful query. The test cases are well-structured and cover the necessary edge cases.

  • 409-491: The TestSupplyByQueryString function tests the SupplyByQueryString method. It covers various scenarios including empty ClassId, non-existent ClassId, zero supply, and successful query. The test cases are well-structured and cover the necessary edge cases.

  • 708-793: The TestNFTByQueryString function tests the NFTByQueryString method. It covers various scenarios including empty ClassId, empty nft id, non-existent ClassId, non-existent nft id, and successful query. The test cases are well-structured and cover the necessary edge cases.

  • 862-927: The TestClassByQueryString function tests the ClassByQueryString method. It covers various scenarios including empty ClassId, non-existent ClassId, and successful query. The test cases are well-structured and cover the necessary edge cases.

@julienrbrt julienrbrt changed the title New queries for nft modules that support query string feat(x/nft): add new queries for nft modules that support query string Nov 3, 2023
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0b9f754 and 7737f3d.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)

CHANGELOG.md Outdated
@@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add duration `shutdown-grace` for resource clean up (closing database handles) before exit.
* (x/auth/vesting) [#17810](https://github.com/cosmos/cosmos-sdk/pull/17810) Add the ability to specify a start time for continuous vesting accounts.
* (baseapp) [#18071](https://github.com/cosmos/cosmos-sdk/pull/18071) Add hybrid handlers to `MsgServiceRouter`.
* (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the changelog entry. It should be "Adds" instead of "Addes". Also, there's an extra period at the end of the sentence. Here's the corrected version:

- * (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string..
+ * (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Adds new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receive requests via query string.

Commitable suggestion (Beta)
Suggested change
* (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string..
* (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Adds new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receive requests via query string.
[ISSUE]

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Julien Robert <julien@rbrt.fr>
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7737f3d and a5d1531.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)

CHANGELOG.md Outdated
@@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add duration `shutdown-grace` for resource clean up (closing database handles) before exit.
* (x/auth/vesting) [#17810](https://github.com/cosmos/cosmos-sdk/pull/17810) Add the ability to specify a start time for continuous vesting accounts.
* (baseapp) [#18071](https://github.com/cosmos/cosmos-sdk/pull/18071) Add hybrid handlers to `MsgServiceRouter`.
* (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo in the changelog entry. It should be "Adds" instead of "Addes".

- * (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string.
+ * (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Adds new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string.

Commitable suggestion (Beta)
Suggested change
* (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string.
* (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Adds new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly lgtm! however, we can simplufy grpc_query.go.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho, XXXByQueryString should simply call the other method XXX with the request correctly filled.
This avoids repeating the method logic, which could inevitably differ mistakenly after a while.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly lgtm! however, we can simplify grpc_query.go.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a5d1531 and f519f89.
Files selected for processing (1)
  • x/nft/keeper/grpc_query.go (5 hunks)
Files skipped from review due to trivial changes (1)
  • x/nft/keeper/grpc_query.go

CHANGELOG.md Outdated
@@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add duration `shutdown-grace` for resource clean up (closing database handles) before exit.
* (x/auth/vesting) [#17810](https://github.com/cosmos/cosmos-sdk/pull/17810) Add the ability to specify a start time for continuous vesting accounts.
* (baseapp) [#18071](https://github.com/cosmos/cosmos-sdk/pull/18071) Add hybrid handlers to `MsgServiceRouter`.
* (x/nft) [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, can you delete this and put it under x/nft/CHANGELOG.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, did it

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f519f89 and 778d2fa.
Files selected for processing (1)
  • x/nft/CHANGELOG.md (1 hunks)

Comment on lines 34 to 37
### Features

* [#17825](https://github.com/cosmos/cosmos-sdk/pull/17825) Add AutoCLI Options.
* [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typographical error in the changelog entry. The word "Addes" should be corrected to "Adds", and "receives" should be "receive" to match subject-verb agreement.

- * [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string.
+ * [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Adds new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receive requests via query string.

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
### Features
* [#17825](https://github.com/cosmos/cosmos-sdk/pull/17825) Add AutoCLI Options.
* [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Addes new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receives request via query string.
### Features
* [#17825](https://github.com/cosmos/cosmos-sdk/pull/17825) Add AutoCLI Options.
* [#18355](https://github.com/cosmos/cosmos-sdk/pull/18355) Adds new versions for `Balance`, `Owner`, `Supply`, `NFT`, `Class` queries that receive requests via query string.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thank you

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one last nit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a since comment above all the messages and rpcs?

@@ -55,12 +80,27 @@ message QueryBalanceRequest {
string owner = 2;
}

// QueryBalanceByQueryStringRequest is the request type for the Query/Balance RPC method
message QueryBalanceByQueryStringRequest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message QueryBalanceByQueryStringRequest {
//
// Since: nft v0.1.1
message QueryBalanceByQueryStringRequest {

@@ -14,16 +14,31 @@ service Query {
option (google.api.http).get = "/cosmos/nft/v1beta1/balance/{owner}/{class_id}";
}

// BalancebyQueryString queries the number of NFTs of a given class owned by the owner, same as balanceOf in ERC721
rpc BalanceByQueryString(QueryBalanceByQueryStringRequest) returns (QueryBalanceByQueryStringResponse) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rpc BalanceByQueryString(QueryBalanceByQueryStringRequest) returns (QueryBalanceByQueryStringResponse) {
//
// Since: nft v0.1.1
rpc BalanceByQueryString(QueryBalanceByQueryStringRequest) returns (QueryBalanceByQueryStringResponse) {

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 778d2fa and eb38459.
Files selected for processing (1)
  • proto/cosmos/nft/v1beta1/query.proto (5 hunks)

@julienrbrt julienrbrt added this pull request to the merge queue Nov 17, 2023
Merged via the queue into cosmos:main with commit d322b23 Nov 17, 2023
59 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: NFT module's Query not support class_id and nft_id with / (slash)
4 participants