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

Update localdb id range order #104

Merged
merged 5 commits into from
Dec 30, 2024
Merged

Update localdb id range order #104

merged 5 commits into from
Dec 30, 2024

Conversation

grunch
Copy link
Member

@grunch grunch commented Dec 27, 2024

Summary by CodeRabbit

  • New Features

    • Added a new asynchronous function to retrieve trade keys for users.
    • Introduced a unique request identifier in message creation logic.
    • Enhanced message handling with improved error reporting for various failure reasons.
    • Updated direct message retrieval to include additional user context.
  • Bug Fixes

    • Enhanced error handling for order processing and user updates.
  • Chores

    • Reformatted dependency declarations for improved readability.
    • Removed unnecessary debug logging from the message handling function.
    • Marked temporary solutions with "FIXME" comments for clarity.

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces several modifications across different files in the mostro-cli project. The changes primarily focus on enhancing message handling, error reporting, and key generation functionality. In Cargo.toml, the nostr-sdk dependency declaration is reformatted for improved readability. The send_msg.rs file now includes a unique request ID for message tracking and improved order processing. A new get_trade_keys method is added to the User struct in db.rs, while util.rs sees some minor logging and comment adjustments. Additionally, several CLI functions have been updated to improve error handling and message processing.

Changes

File Change Summary
Cargo.toml - Reformatted nostr-sdk dependency declaration
- Added commented-out mostro-core path dependency
src/cli/send_msg.rs - Added UUID-based request_id to message creation
- Enhanced response handling and order processing
- Improved error checking for trade keys
src/db.rs - Added get_trade_keys async method to User struct
- Generates keys from user's mnemonic
src/util.rs - Removed debug print statement in get_direct_messages
- Added FIXME comment in send_message_sync
src/cli.rs - Updated execute_get_dm function signature to include trade_index
src/cli/get_dm.rs - Updated execute_get_dm function to handle trade_index
- Enhanced message processing logic with new match arms
src/cli/new_order.rs - Added import for CantDoReason
- Improved error handling for order execution
src/cli/take_buy.rs - Added import for CantDoReason
- Enhanced error handling for buy action
src/cli/take_sell.rs - Added import for CantDoReason
- Streamlined error handling for sell action

Possibly Related PRs

Poem

🐰 A rabbit's tale of code so bright,
Messages flying with request ID might,
Keys generated, dependencies neat,
Logging trimmed, making changes sweet,
In the world of Mostro, code takes flight! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53aec13 and a4bdee3.

📒 Files selected for processing (3)
  • src/cli.rs (1 hunks)
  • src/cli/get_dm.rs (2 hunks)
  • src/cli/send_msg.rs (3 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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: 1

🧹 Nitpick comments (2)
src/cli/send_msg.rs (2)

45-45: Consider using a full 128-bit identifier for uniqueness
Truncating UUID to 64 bits is typically fine, but consider using the entire UUID to further reduce collision risk where it’s critical to guarantee request uniqueness.


67-114: Refactor logic to handle matching response and order creation more cleanly
This block uses a multi-step chain with find_map returning (Option<SmallOrder>, Option<i64>). If code complexity grows or more response types need handling, consider refactoring into dedicated helper methods that:

  1. Match the request ID.
  2. Validate the presence of a NewOrder message.
  3. Conditionally create a DB order and update the user’s trade index.

Separating these steps into smaller functions can reduce future maintenance overhead and clarify the control flow.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 149a253 and 70d5e45.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • Cargo.toml (2 hunks)
  • src/cli/send_msg.rs (3 hunks)
  • src/db.rs (1 hunks)
  • src/util.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • src/util.rs
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
🔇 Additional comments (2)
src/cli/send_msg.rs (2)

48-48: Message creation looks good
No issues found—this is a clean way to include the newly generated request ID in your order message.


57-57: Synchronous message sending call appears correct
The code handles potential errors via ?, and the usage of send_message_sync is clearly structured.

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: 1

🧹 Nitpick comments (4)
src/cli/get_dm.rs (1)

68-72: Good error messaging for CantDo payload.
Printing the cant_do_reason helps with debugging. Consider adding user-friendly guidance or next steps for the user if applicable.

src/cli/new_order.rs (1)

147-160: Refactor repeated Action::CantDo handling
The approach here is clean for handling specific error reasons with Action::CantDo. However, since similar logic is repeated in other CLI modules, consider extracting a helper function to reduce duplication and maintain consistent behavior across the codebase.

src/cli/take_buy.rs (1)

68-81: Consistent error case checks
You're correctly switching on cant_do_reason for more granular error reporting. For maintainability, consider refactoring similar checks across modules into a shared function.

src/cli/take_sell.rs (1)

111-125: Extract shared code for user updates
This block for updating user data and trade indexes appears in multiple places. Centralizing it into a helper function would improve readability and reduce duplication.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d50f90e and 53aec13.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • src/cli.rs (1 hunks)
  • src/cli/get_dm.rs (2 hunks)
  • src/cli/new_order.rs (2 hunks)
  • src/cli/take_buy.rs (2 hunks)
  • src/cli/take_sell.rs (3 hunks)
  • src/db.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/db.rs
🔇 Additional comments (8)
src/cli/get_dm.rs (3)

5-9: Imports look good, providing new functionality for message matching.
It appears you're now using Action, Message, and Payload from mostro_core::message. This is appropriate for the extended match logic below.


16-16: Consider validating or documenting the new trade_index parameter.
You’ve introduced trade_index to the function signature without explicit validation or explanation of acceptable ranges. A quick check (e.g., ensuring it’s non-negative) or clarifying in documentation could help avoid edge-case errors.


73-91: Check database error for “order not found” vs. other errors.
Currently, is_err() is used to judge whether to insert a new Order. However, a database connectivity error or other failure also satisfies is_err(), which might lead you to erroneously create a duplicate order. Distinguishing “not found” from “DB error” could improve robustness.

src/cli.rs (1)

359-359: Ensure consistent usage of the added trade_index parameter.
Passing trade_index to execute_get_dm aligns the call site with the updated function signature. Double-check that no other parts of the codebase rely on the old signature.

src/cli/new_order.rs (1)

2-2: Good use of import for structured error handling
Bringing in CantDoReason from mostro_core::message helps keep your code consistent with the extended error handling approach across the codebase.

src/cli/take_buy.rs (1)

2-2: New import aligns with updated error structure
Importing CantDoReason neatly supports handling customized error reasons.

src/cli/take_sell.rs (2)

3-3: Import for extended error handling
Including CantDoReason is consistent with the newly introduced Action::CantDo pattern.


87-100: Specialized handling for CantDo
The structure here properly distinguishes known reasons (e.g., out-of-range amounts) from unknown ones. It mirrors the approach elsewhere, helping unify error handling.

trade index and trade key on child order
@grunch grunch merged commit 32997a1 into main Dec 30, 2024
1 of 2 checks passed
@grunch grunch deleted the update-localdb-id-range-order branch December 30, 2024 20:38
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.

1 participant