Skip to content

Handle next trade on fiatsent#421

Merged
grunch merged 3 commits into
mainfrom
handle-next-trade-on-fiatsent
Jan 10, 2025
Merged

Handle next trade on fiatsent#421
grunch merged 3 commits into
mainfrom
handle-next-trade-on-fiatsent

Conversation

@grunch

@grunch grunch commented Jan 10, 2025

Copy link
Copy Markdown
Member

Add next_trade_pubkey and next_trade_index fields to order table, this fields should be sent when the maker of a range order is a buyer, mostrod needs these fields to create the new child order

Implement logic of saving next trade fields after fiat-sent action by buyer

Code refactoring to optimize some parts of the code

Add logic on release to use next trade fields in order when the maker of the range order is the buyer

Update mostro-core version

Summary by CodeRabbit

Release Notes

  • Dependencies

    • Updated mostro-core dependency to version 0.6.25
  • Database

    • Enhanced orders table schema with new columns for trade tracking
      • Added next_trade_pubkey
      • Added next_trade_index
  • Improvements

    • Refined error handling and control flow in order management processes
    • Improved database migration logging to reflect actual setup success
    • Introduced a new helper function for managing child orders

Add next_trade_pubkey and next_trade_index fields to order table, this fields should be sent when
the maker of a range order is a buyer, mostrod needs these fields to create the new child order

Implement logic of saving next trade fields after fiat-sent action by buyer

Code refactoring to optimize some parts of the code

Add logic on release to use next trade fields in order when the maker of the range order is the buyer

Update mostro-core version
@coderabbitai

coderabbitai Bot commented Jan 10, 2025

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@grunch has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 42 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 158f537 and 1c88037.

📒 Files selected for processing (2)
  • src/app/fiat_sent.rs (3 hunks)
  • src/app/release.rs (2 hunks)

Walkthrough

This pull request introduces updates to the Mostro project, focusing on trade-related functionality and database management. The changes include updating the mostro-core dependency version, modifying the orders table schema to add columns for next trade information, enhancing the trade handling logic in fiat_sent.rs and release.rs, and refining the database connection logging in db.rs. The modifications aim to improve trade tracking and error handling across the application.

Changes

File Change Summary
Cargo.toml Updated mostro-core dependency from 0.6.24 to 0.6.25
migrations/20221222153301_orders.sql Added two new columns to orders table:
- next_trade_pubkey (char(64))
- next_trade_index (integer, default 0)
src/app/fiat_sent.rs Added next_trade variable to handle NextTrade payload
Updated order with next_trade_pubkey and next_trade_index when conditions are met
src/app/release.rs Refactored error handling and control flow
Added new handle_child_order helper function
Improved order status and public key checks
src/db.rs Modified database creation logging to occur only after successful migration

Sequence Diagram

sequenceDiagram
    participant User
    participant App
    participant Database
    
    User->>App: Initiate Trade
    App->>Database: Retrieve Order
    Database-->>App: Order Details
    App->>App: Check Trade Conditions
    App->>Database: Update Order with Next Trade Info
    Database-->>App: Confirmation
    App->>User: Send Trade Update Message
Loading

Possibly related PRs

Poem

🐰 A Rabbit's Ode to Trades Anew

Migrations dance, columns take flight,
Next trades whisper with digital might
Core updated, logic refined
In Mostro's realm, connections aligned
Hop along, code's elegant view! 🚀


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (3)
src/app/fiat_sent.rs (1)

100-107: Add a comment explaining the next trade fields usage.

While the implementation is correct, adding a comment would help explain why these fields are only updated when the buyer is the maker.

+    // Update next trade fields only when the buyer is the maker of a range order
+    // These fields will be used to create the next child order in the range
     if order.creator_pubkey == event.rumor.pubkey.to_string() && next_trade.is_some() {
src/app/release.rs (2)

75-91: Enhance error messages for better debugging.

While the error handling is improved, the error messages could be more descriptive.

-        .ok_or(Error::msg("No order id"))?;
+        .ok_or(Error::msg("Order ID is required but was not provided"))?;

-        .ok_or(Error::msg("Order not found"))?;
+        .ok_or(Error::msg(format!("Order {} not found in database", order_id)))?;

-        .ok_or(Error::msg("No seller pubkey found"))?;
+        .ok_or(Error::msg(format!("Seller public key not found for order {}", order_id)))?;

170-205: Add documentation for the handle_child_order function.

The new helper function would benefit from documentation explaining its purpose and parameters.

+/// Manages the creation and update of child orders in a range order sequence
+/// 
+/// # Arguments
+/// * `child_order` - The child order to be created/updated
+/// * `order` - The parent order
+/// * `next_trade` - Optional tuple of (pubkey, index) for the next trade
+/// * `pool` - Database connection pool
+/// * `request_id` - Optional request ID for messaging
+/// 
+/// # Returns
+/// Result indicating success or failure of the operation
 async fn handle_child_order(
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d3c7840 and 75fc53f.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • Cargo.toml (1 hunks)
  • migrations/20221222153301_orders.sql (1 hunks)
  • src/app/fiat_sent.rs (3 hunks)
  • src/app/release.rs (2 hunks)
  • src/db.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: tests
🔇 Additional comments (4)
migrations/20221222153301_orders.sql (1)

40-42: LGTM! Schema changes look good.

The new columns next_trade_pubkey and next_trade_index are well-defined with appropriate types and constraints, consistent with the existing schema design.

src/app/fiat_sent.rs (2)

Line range hint 27-33: LGTM! Proper error handling for order retrieval.

The mutable order retrieval with proper error handling looks good.


57-60: LGTM! Clean payload extraction.

The next trade extraction from payload is well-implemented using pattern matching.

src/db.rs (1)

37-42: LGTM! Improved logging accuracy.

Moving the success log message inside the migration success block ensures it only appears when the database is fully initialized.

Comment thread src/app/release.rs
grunch and others added 2 commits January 10, 2025 11:02
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@grunch grunch merged commit a17b33b into main Jan 10, 2025
@grunch grunch deleted the handle-next-trade-on-fiatsent branch January 10, 2025 14:12
This was referenced Feb 12, 2025
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