feat(torii-client): retrieve controllers from client#2996
feat(torii-client): retrieve controllers from client#2996Larkooo merged 5 commits intodojoengine:mainfrom
Conversation
|
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 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. 📒 Files selected for processing (1)
Ohayo sensei, here’s the detailed breakdown of the changes: WalkthroughThis pull request introduces a new asynchronous method Changes
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
Possibly Related PRs
Suggested Reviewers
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
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
📒 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}; |
There was a problem hiding this comment.
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.
| use torii_grpc::types::{Controller, EntityKeysClause, Event, EventQuery, Query, Token, TokenBalance}; | |
| use torii_grpc::types::{ | |
| Controller, EntityKeysClause, Event, EventQuery, Query, Token, TokenBalance, | |
| }; |
| /// 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>, _>>()?) | ||
| } |
There was a problem hiding this comment.
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.
| /// 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.
There was a problem hiding this comment.
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_tokensand other similar methods, this one doesn't convert theFeltvalues 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
📒 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
RetrieveControllersRequestis properly grouped with other request types and follows the existing formatting conventions.
Codecov ReportAttention: Patch coverage is
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. |
Summary by CodeRabbit