Skip to content

feat(torii-client): retrieve controllers from client#2996

Merged
Larkooo merged 5 commits intodojoengine:mainfrom
Larkooo:torii-client-controllers
Feb 7, 2025
Merged

feat(torii-client): retrieve controllers from client#2996
Larkooo merged 5 commits intodojoengine:mainfrom
Larkooo:torii-client-controllers

Conversation

@Larkooo
Copy link
Collaborator

@Larkooo Larkooo commented Feb 6, 2025

Summary by CodeRabbit

  • New Features
    • Enabled retrieval of controller details based on specified contract addresses.
    • Introduced a new, structured representation for controller data that includes address, username, and deployment time.
    • Added an asynchronous method to retrieve controllers from the client interface.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

Warning

Rate limit exceeded

@Larkooo has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 34bdd1e and 07d8803.

📒 Files selected for processing (1)
  • crates/torii/grpc/src/client.rs (2 hunks)

Ohayo sensei, here’s the detailed breakdown of the changes:

Walkthrough

This pull request introduces a new asynchronous method controllers in the Client struct to retrieve controllers based on provided contract addresses. The method acquires a write lock on the gRPC client, calls retrieve_controllers, and converts the response into a vector of Controller instances. Additionally, a new Controller struct is added in the gRPC module along with a TryFrom implementation to enable conversion from the proto representation.

Changes

File(s) Change Summary
crates/torii/client/.../mod.rs Added new async controllers method to Client struct; updated import to include Controller.
crates/torii/grpc/.../types/mod.rs Introduced new Controller struct (with address, username, deployed_at) and implemented TryFrom<proto::types::Controller> for it.
crates/torii/grpc/.../client.rs Added new async retrieve_controllers method to WorldClient struct; updated import to include RetrieveControllersRequest.

Sequence Diagram(s)

sequenceDiagram
    participant Cl as Client
    participant GRPC as gRPC Client
    participant S as Server
    Cl->>GRPC: Acquire lock & call retrieve_controllers(contract_addresses)
    GRPC->>S: Request controller data
    S-->>GRPC: Return proto::Controller data
    GRPC-->>Cl: Send response
    Cl->>Cl: Convert proto data to Controller via TryFrom
Loading

Possibly Related PRs

Suggested Reviewers

  • glihm (sensei)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
crates/torii/grpc/src/types/mod.rs (1)

28-37: Ohayo sensei! The TryFrom implementation is correct but could be more robust.

The implementation correctly converts proto type to struct, but consider adding error handling for empty or invalid addresses.

Consider this more robust implementation:

 impl TryFrom<proto::types::Controller> for Controller {
     type Error = SchemaError;
     fn try_from(value: proto::types::Controller) -> Result<Self, Self::Error> {
+        if value.address.is_empty() {
+            return Err(SchemaError::InvalidField("address".to_string()));
+        }
         Ok(Self {
             address: Felt::from_bytes_be_slice(&value.address),
             username: value.username,
             deployed_at: value.deployed_at_timestamp,
         })
     }
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99d2e60 and e6e9bc1.

📒 Files selected for processing (2)
  • crates/torii/client/src/client/mod.rs (2 hunks)
  • crates/torii/grpc/src/types/mod.rs (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: ci
crates/torii/client/src/client/mod.rs

[warning] 18-18: Code formatting issue: line exceeds maximum line length. Please format the code.


[warning] 91-91: Code formatting issue: line exceeds maximum line length. Please format the code.


[warning] 98-98: Code formatting issue: line exceeds maximum line length. Please format the code.

🔇 Additional comments (1)
crates/torii/grpc/src/types/mod.rs (1)

21-26: Ohayo sensei! The Controller struct looks well-designed.

The struct has appropriate fields and derives all necessary traits.

};
use torii_grpc::types::schema::Entity;
use torii_grpc::types::{EntityKeysClause, Event, EventQuery, Query, Token, TokenBalance};
use torii_grpc::types::{Controller, EntityKeysClause, Event, EventQuery, Query, Token, TokenBalance};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ohayo sensei! Line exceeds maximum length.

Apply this diff to fix the line length issue:

-use torii_grpc::types::{Controller, EntityKeysClause, Event, EventQuery, Query, Token, TokenBalance};
+use torii_grpc::types::{
+    Controller, EntityKeysClause, Event, EventQuery, Query, Token, TokenBalance,
+};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use torii_grpc::types::{Controller, EntityKeysClause, Event, EventQuery, Query, Token, TokenBalance};
use torii_grpc::types::{
Controller, EntityKeysClause, Event, EventQuery, Query, Token, TokenBalance,
};

Comment on lines +93 to +99
/// Retrieves controllers matching contract addresses.
pub async fn controllers(&self, contract_addresses: Vec<Felt>) -> Result<Vec<Controller>, Error> {
let mut grpc_client = self.inner.write().await;
let RetrieveControllersResponse { controllers } =
grpc_client.retrieve_controllers(contract_addresses).await?;
Ok(controllers.into_iter().map(TryInto::try_into).collect::<Result<Vec<Controller>, _>>()?)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ohayo sensei! The implementation looks good but needs formatting.

The method correctly retrieves and converts controllers, but the line length needs to be fixed.

Apply this diff to fix the line length issue:

-        let RetrieveControllersResponse { controllers } =
-            grpc_client.retrieve_controllers(contract_addresses).await?;
-        Ok(controllers.into_iter().map(TryInto::try_into).collect::<Result<Vec<Controller>, _>>()?)
+        let RetrieveControllersResponse { controllers } = grpc_client
+            .retrieve_controllers(contract_addresses)
+            .await?;
+        Ok(controllers
+            .into_iter()
+            .map(TryInto::try_into)
+            .collect::<Result<Vec<Controller>, _>>()?)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Retrieves controllers matching contract addresses.
pub async fn controllers(&self, contract_addresses: Vec<Felt>) -> Result<Vec<Controller>, Error> {
let mut grpc_client = self.inner.write().await;
let RetrieveControllersResponse { controllers } =
grpc_client.retrieve_controllers(contract_addresses).await?;
Ok(controllers.into_iter().map(TryInto::try_into).collect::<Result<Vec<Controller>, _>>()?)
}
/// Retrieves controllers matching contract addresses.
pub async fn controllers(&self, contract_addresses: Vec<Felt>) -> Result<Vec<Controller>, Error> {
let mut grpc_client = self.inner.write().await;
let RetrieveControllersResponse { controllers } = grpc_client
.retrieve_controllers(contract_addresses)
.await?;
Ok(controllers
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<Controller>, _>>()?)
}
🧰 Tools
🪛 GitHub Actions: ci

[warning] 98-98: Code formatting issue: line exceeds maximum line length. Please format the code.

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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
crates/torii/grpc/src/client.rs (1)

98-107: Consider converting Felt to bytes for consistency.

Ohayo! While the implementation follows the same pattern as other retrieve methods, I notice that unlike retrieve_tokens and other similar methods, this one doesn't convert the Felt values to bytes. For consistency with other methods, consider applying the same conversion.

Here's how you could modify it:

 pub async fn retrieve_controllers(
     &mut self,
     contract_addresses: Vec<Felt>,
 ) -> Result<RetrieveControllersResponse, Error> {
     self.inner
-        .retrieve_controllers(RetrieveControllersRequest { contract_addresses })
+        .retrieve_controllers(RetrieveControllersRequest {
+            contract_addresses: contract_addresses
+                .into_iter()
+                .map(|c| c.to_bytes_be().to_vec())
+                .collect(),
+        })
         .await
         .map_err(Error::Grpc)
         .map(|res| res.into_inner())
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ffaf1e and 34bdd1e.

📒 Files selected for processing (2)
  • crates/torii/client/src/client/mod.rs (2 hunks)
  • crates/torii/grpc/src/client.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/torii/client/src/client/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: ensure-wasm
  • GitHub Check: docs
  • GitHub Check: clippy
🔇 Additional comments (1)
crates/torii/grpc/src/client.rs (1)

12-22: Ohayo! The imports look good, sensei!

The new import RetrieveControllersRequest is properly grouped with other request types and follows the existing formatting conventions.

@codecov
Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.

Project coverage is 57.10%. Comparing base (99d2e60) to head (07d8803).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/grpc/src/client.rs 0.00% 15 Missing ⚠️
crates/torii/client/src/client/mod.rs 0.00% 12 Missing ⚠️
crates/torii/grpc/src/types/mod.rs 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2996      +/-   ##
==========================================
- Coverage   57.14%   57.10%   -0.04%     
==========================================
  Files         429      429              
  Lines       56834    56868      +34     
==========================================
- Hits        32477    32476       -1     
- Misses      24357    24392      +35     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Larkooo Larkooo enabled auto-merge (squash) February 6, 2025 19:39
@Larkooo Larkooo merged commit d11a7ec into dojoengine:main Feb 7, 2025
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants