Skip to content

Remove seller/buyer token#133

Merged
grunch merged 6 commits into
mainfrom
remove-token
Sep 2, 2025
Merged

Remove seller/buyer token#133
grunch merged 6 commits into
mainfrom
remove-token

Conversation

@grunch
Copy link
Copy Markdown
Member

@grunch grunch commented Sep 1, 2025

Summary by CodeRabbit

  • Refactor

    • Removed display of dispute tokens from direct messages.
    • Simplified order handling by removing legacy buyer/seller token fields and updating order creation and retrieval flows.
    • Added a startup migration to remove legacy token columns from existing databases.
  • Chores

    • Bumped core dependency to a newer patch version.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 1, 2025

Walkthrough

Bumped mostro-core to 0.6.49. Removed token from Payload::Dispute handling. Shortened SmallOrder::new call by removing two trailing None args. Removed buyer_token and seller_token from Order struct, schema, SQL paths, and added a migration to drop legacy columns on startup.

Changes

Cohort / File(s) Summary
Dependency bump
Cargo.toml
Update dependency: mostro-core "0.6.46""0.6.49".
CLI: DM payload handling
src/cli/get_dm.rs
Pattern for Payload::Dispute changed from (id, token, info)(id, info); token extraction/printing removed; minor formatting of long calls.
CLI: New order construction
src/cli/new_order.rs
SmallOrder::new invocation shortened by removing two trailing None arguments (reduced arity); no other logic changes.
DB: Order schema & persistence
src/db.rs
Removed buyer_token and seller_token from pub struct Order; updated CREATE TABLE, INSERT, and UPDATE SQL to exclude those columns; removed related bindings and initializations; added migrate_remove_token_columns(pool) invoked in connect() to DROP legacy columns if present; refactored get_all_trade_keys to a scalar query.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant CLI as mostro-cli
  participant MC as mostro-core (0.6.49)
  participant DB as Local DB

  rect rgb(240,248,255)
  note over U,CLI: Fetch Direct Messages
  U->>CLI: run get-dm
  CLI->>MC: get_direct_messages(...)
  MC-->>CLI: Messages incl. Payload::Dispute(id, info)
  CLI->>CLI: match Dispute (id, info) — token removed
  CLI-->>U: print id and optional info
  end

  rect rgb(245,255,240)
  note over U,CLI: Create New Order
  U->>CLI: run new-order ...
  CLI->>CLI: SmallOrder::new(..., expires_at)  %% trailing None args removed
  CLI->>DB: INSERT Order (columns exclude buyer_token/seller_token)
  DB-->>CLI: OK
  CLI-->>U: Order created
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

I thump my paws — the core's anew,
Tokens hopped off, the rows feel true.
Orders trimmed to lean and bright,
Messages simpler in the night.
I munch a carrot — code feels right! 🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bbbf520 and aba5108.

📒 Files selected for processing (1)
  • src/db.rs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/db.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch remove-token

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
Copy Markdown
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/db.rs (1)

437-443: Tighten results for trade_keys (filter empties; optional ordering).

Not critical, but helps produce a stable, clean list.

-        let rows = sqlx::query_as::<_, TradeKeyRow>(
-            "SELECT DISTINCT trade_keys FROM orders WHERE trade_keys IS NOT NULL",
-        )
+        let rows = sqlx::query_as::<_, TradeKeyRow>(
+            "SELECT DISTINCT trade_keys FROM orders WHERE trade_keys IS NOT NULL ORDER BY trade_keys",
+        )
         .fetch_all(pool)
         .await?;
 
-        let trade_keys: Vec<String> = rows.into_iter().filter_map(|row| row.trade_keys).collect();
+        let trade_keys: Vec<String> = rows
+            .into_iter()
+            .filter_map(|row| row.trade_keys)
+            .filter(|s| !s.trim().is_empty())
+            .collect();
src/cli/get_dm.rs (1)

68-76: Print Dispute info without Option wrapper.

Minor UX tweak: avoid printing Some(...) by unwrapping when present.

-                    Payload::Dispute(id, info) => {
+                    Payload::Dispute(id, info) => {
                         println!("Action: {}", message.action);
                         println!("Dispute id: {}", id);
-                        if info.is_some() {
-                            println!();
-                            println!("Dispute info: {:#?}", info);
-                            println!();
-                        }
+                        if let Some(info) = info {
+                            println!();
+                            println!("Dispute info: {}", info);
+                            println!();
+                        }
                     }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f6c2d7a and 3774453.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • Cargo.toml (1 hunks)
  • src/cli/get_dm.rs (3 hunks)
  • src/cli/new_order.rs (0 hunks)
  • src/db.rs (3 hunks)
💤 Files with no reviewable changes (1)
  • src/cli/new_order.rs
🧰 Additional context used
🧬 Code graph analysis (1)
src/cli/get_dm.rs (1)
src/util.rs (1)
  • get_direct_messages (281-386)
🔇 Additional comments (4)
Cargo.toml (1)

42-42: Dependency bump to mostro-core 0.6.49 looks good.

Matches the Payload::Dispute signature change in code. Ensure Cargo.lock is updated accordingly in the PR if it's tracked.

src/db.rs (1)

353-353: Update statement mapping is consistent.

SET columns align with subsequent binds; no token fields remain. Looks correct.

src/cli/get_dm.rs (2)

24-25: Line wrap/readability only.

No semantic change; fine as-is.


36-37: Admin path call formatting only.

No functional change; looks good.

Comment thread src/db.rs
Copy link
Copy Markdown
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/db.rs (2)

350-372: Don’t update created_at on UPDATE; keep it immutable.

created_at should be write-once. Recommend dropping it from the UPDATE SET/binds.

               SET kind = ?, status = ?, amount = ?, fiat_code = ?, min_amount = ?, max_amount = ?, 
                   fiat_amount = ?, payment_method = ?, premium = ?, trade_keys = ?, counterparty_pubkey = ?,
-                  is_mine = ?, buyer_invoice = ?, created_at = ?, expires_at = ?
+                  is_mine = ?, buyer_invoice = ?, expires_at = ?
               WHERE id = ?
@@
             .bind(&self.counterparty_pubkey)
             .bind(self.is_mine)
             .bind(&self.buyer_invoice)
-            .bind(self.created_at)
             .bind(self.expires_at)
             .bind(id)

437-443: Simplify DISTINCT trade_keys fetch with query_scalar + flatten.

Removes the ad-hoc row type and one pass over the Vec.

-        #[derive(sqlx::FromRow)]
-        struct TradeKeyRow {
-            trade_keys: Option<String>,
-        }
-
-        let rows = sqlx::query_as::<_, TradeKeyRow>(
-            "SELECT DISTINCT trade_keys FROM orders WHERE trade_keys IS NOT NULL",
-        )
-        .fetch_all(pool)
-        .await?;
-
-        let trade_keys: Vec<String> = rows.into_iter().filter_map(|row| row.trade_keys).collect();
+        let trade_keys: Vec<String> = sqlx::query_scalar::<_, Option<String>>(
+            "SELECT DISTINCT trade_keys FROM orders WHERE trade_keys IS NOT NULL",
+        )
+        .fetch_all(pool)
+        .await?
+        .into_iter()
+        .flatten()
+        .collect();
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3774453 and 4d5f47d.

📒 Files selected for processing (1)
  • src/db.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
src/db.rs (1)

256-258: Placeholders now match columns (17 = 17).

This resolves the earlier runtime bind-count mismatch on INSERT. Looks good.

Comment thread src/db.rs
Copy link
Copy Markdown
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)
src/db.rs (1)

487-499: Simplify: fetch DISTINCT trade_keys via query_scalar and drop the ad-hoc row type.

Reduces code and avoids Option since the WHERE already excludes NULLs.

-        #[derive(sqlx::FromRow)]
-        struct TradeKeyRow {
-            trade_keys: Option<String>,
-        }
-
-        let rows = sqlx::query_as::<_, TradeKeyRow>(
-            "SELECT DISTINCT trade_keys FROM orders WHERE trade_keys IS NOT NULL",
-        )
-        .fetch_all(pool)
-        .await?;
-
-        let trade_keys: Vec<String> = rows.into_iter().filter_map(|row| row.trade_keys).collect();
+        let trade_keys: Vec<String> = sqlx::query_scalar::<_, String>(
+            "SELECT DISTINCT trade_keys FROM orders WHERE trade_keys IS NOT NULL",
+        )
+        .fetch_all(pool)
+        .await?;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2158dfa and 0c075f2.

📒 Files selected for processing (1)
  • src/db.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (4)
src/db.rs (4)

67-70: Good: migration invoked only for existing databases.

This keeps the fresh-install path clean and avoids unnecessary checks.


313-315: Placeholder count now matches the 17 columns.

Previous mismatch is resolved. Looks good.


410-410: Update SET/binds alignment looks correct.

14 placeholders before WHERE + 1 for id; 15 binds provided. No issues.


75-127: Add version-aware migration with rebuild fallback for SQLite < 3.35. Python’s sqlite3 (v3.40.1) supports ALTER TABLE…DROP COLUMN, but older SQLite versions require a table rebuild—please apply the suggested diff to include the version check and fallback.

@grunch grunch merged commit d38dae9 into main Sep 2, 2025
2 checks passed
@grunch grunch deleted the remove-token branch September 2, 2025 14:39
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