Skip to content

Conversation

@arkanoider
Copy link
Collaborator

@arkanoider arkanoider commented Mar 8, 2025

@grunch , @Catrya

this is the complementary fix for mostro-cli to have disputes working.

Summary by CodeRabbit

  • New Features
    • Added a new command for retrieving the latest direct messages for admin users.
    • Enhanced administrative commands for settling and canceling disputes with improved key retrieval and error handling.
  • Refactor
    • Improved command handling logic for administrative actions, ensuring more specific implementations.
    • Minor formatting adjustments for better readability in message retrieval functions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 8, 2025

Walkthrough

This pull request implements new administrative commands in the CLI. It introduces the GetAdminDm command for retrieving direct messages for admin users and enhances the handling of AdmSettle, AdmCancel, and AdmTakeDispute commands by incorporating admin private key retrieval. Two new asynchronous functions for executing admin dispute actions have been added, and minor formatting adjustments were made in other parts of the code.

Changes

File(s) Change Summary
src/cli.rs Added GetAdminDm command; updated handling for AdmSettle and AdmCancel to retrieve admin private key from the environment.
src/cli/take_dispute.rs Introduced two new asynchronous functions, execute_admin_cancel_dispute and execute_admin_settle_dispute, to log details and send dispute messages synchronously.
src/cli/send_dm.rs Removed a blank line in the execute_send_dm function, causing a formatting change without affecting functionality.
src/util.rs Adjusted formatting in the get_direct_messages function for improved readability; no changes to logic or behavior.
src/cli/get_dm.rs Modified execute_get_dm to include an admin parameter, altering logic for retrieving direct messages based on admin status.

Sequence Diagram(s)

sequenceDiagram
    participant CLI
    participant Env
    participant DisputeHandler
    participant MessageSender

    CLI->>Env: Retrieve "NSEC_PRIVKEY"
    Env-->>CLI: Return admin private key or error
    CLI->>DisputeHandler: Dispatch AdmSettle/AdmCancel command with order_id and admin key
    DisputeHandler->>MessageSender: Create dispute message (Action: AdminSettle/AdminCancel) and log details
    MessageSender-->>DisputeHandler: Acknowledge message delivery
    DisputeHandler-->>CLI: Return command result
Loading

Possibly related PRs

Poem

I’m a hopping rabbit in code so fine,
Admin commands now dance in line.
Disputes settle and cancel with a beat,
Logging keys and messages neat.
I nibble on changes with joyful glee,
Hoppin’ through commits merrily!
🐰💻

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

@arkanoider arkanoider requested review from Catrya and grunch March 8, 2025 21:32
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 (2)
src/cli.rs (1)

425-446: Consider extracting duplicated admin key retrieval logic.

The admin key retrieval and error handling logic is duplicated across multiple command handlers. Consider extracting this into a helper function to improve maintainability.

+ fn get_admin_key() -> Result<Keys> {
+     match std::env::var("NSEC_PRIVKEY") {
+         Ok(id_key) => Keys::parse(&id_key),
+         Err(e) => {
+             println!("Failed to get mostro admin private key: {}", e);
+             std::process::exit(1);
+         }
+     }
+ }
+
  Commands::AdmSettle { order_id } => {
-     let id_key = match std::env::var("NSEC_PRIVKEY") {
-         Ok(id_key) => Keys::parse(&id_key)?,
-         Err(e) => {
-             println!("Failed to get mostro admin private key: {}", e);
-             std::process::exit(1);
-         }
-     };
+     let id_key = get_admin_key()?;
      execute_admin_settle_dispute(order_id, &id_key, &trade_keys, mostro_key, &client)
          .await?;
  }
  Commands::AdmCancel { order_id } => {
-     let id_key = match std::env::var("NSEC_PRIVKEY") {
-         Ok(id_key) => Keys::parse(&id_key)?,
-         Err(e) => {
-             println!("Failed to get mostro admin private key: {}", e);
-             std::process::exit(1);
-         }
-     };
+     let id_key = get_admin_key()?;
      execute_admin_cancel_dispute(order_id, &id_key, &trade_keys, mostro_key, &client)
          .await?;
  }
src/cli/take_dispute.rs (1)

40-70: Fix the log message for settle dispute.

The log message incorrectly states "Request of take dispute" when it should indicate a settle dispute action.

  println!(
-     "Request of take dispute {} from mostro pubId {}",
+     "Request of settle dispute {} from mostro pubId {}",
      dispute_id,
      mostro_key.clone()
  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 76b5a44 and 86e7bdf.

📒 Files selected for processing (4)
  • src/cli.rs (2 hunks)
  • src/cli/send_dm.rs (0 hunks)
  • src/cli/take_dispute.rs (2 hunks)
  • src/util.rs (1 hunks)
💤 Files with no reviewable changes (1)
  • src/cli/send_dm.rs
🔇 Additional comments (5)
src/util.rs (1)

203-204: LGTM! Simple formatting change.

The line split for improved readability doesn't affect functionality.

src/cli.rs (2)

36-36: LGTM! Added wildcard import for take_dispute.

This import allows direct access to the newly added admin dispute functions.


448-457: Code now correctly uses admin key for dispute operations.

The previous implementation might have been using the wrong keys for admin operations. This change ensures admin dispute commands use the admin private key from the environment variable.

src/cli/take_dispute.rs (2)

8-38: LGTM! Admin cancel dispute implementation.

The function correctly implements admin cancellation of disputes using the provided admin keys.


93-93: LGTM! Added helpful debug logging.

Adding the identity key to the log output helps with debugging and verification.

Copy link
Member

@Catrya Catrya left a comment

Choose a reason for hiding this comment

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

when i do admaddsolver, mostro-cli responds:

Sending AdminAddSolver command for order None to mostro pubId 00000018c1ae3147f9010b5d768ec2b121acf1a67f238be8e2bdd7c1f9eef705
Error: Missing order ID
Bye Bye!

Will fix tonite...it's probably the same thing of admin_take_dispute command.

@Catrya
Copy link
Member

Catrya commented Mar 10, 2025

when i do admaddsolver, mostro-cli responds:

Sending AdminAddSolver command for order None to mostro pubId 00000018c1ae3147f9010b5d768ec2b121acf1a67f238be8e2bdd7c1f9eef705
Error: Missing order ID
Bye Bye!

Will fix tonite...it's probably the same thing of admin_take_dispute command.

@arkanoider you mean this error?:

I can't take a dispute, mostro sends: "cant_do":"invalid_pubkey"

What I'm seeing is that mostro-cli is creating a new identity_keys to take the dispute, not using the one I set in the db.

prueba@pop-os:~/musers$ mcli admtakedispute -d f5ce09d0-078d-43e0-92ba-ccf53949052c
Request of take dispute f5ce09d0-078d-43e0-92ba-ccf53949052c from mostro pubId 00000018c1ae3147f9010b5d768ec2b121acf1a67f238be8e2bdd7c1f9eef705
identity_keys: "00191449dd5100039db02765c72d7851d035f48133d7d996c7bc6043e7a31188"
SENDING DM with trade keys: "c7201c776fbd5665c1adeb32596b5f50f8df8264d939d1a43f13651cf443a5ee"
Bye Bye!

but that user is in db with another identity_keys

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)
src/cli.rs (1)

36-36: Consider importing only the specific functions needed.

While importing all functions from the take_dispute module works, importing only the specific functions used would be more precise and maintainable.

-use take_dispute::*;
+use take_dispute::{execute_admin_settle_dispute, execute_admin_cancel_dispute, execute_take_dispute};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 86e7bdf and 724bda8.

📒 Files selected for processing (2)
  • src/cli.rs (4 hunks)
  • src/cli/get_dm.rs (2 hunks)
🔇 Additional comments (7)
src/cli/get_dm.rs (3)

16-16: LGTM: Added admin parameter to support admin operations.

The addition of the admin boolean parameter allows the function to differentiate between regular user and admin operations, which aligns with the PR objective of fixing admin commands.


20-36: Implementation correctly handles admin vs regular user paths.

The conditional logic appropriately handles different retrieval methods based on the user's admin status. For admin users, the function retrieves the admin private key from the environment variable, addressing the issue with admin dispute commands.


65-76: Good addition of Dispute payload handling.

The implementation properly handles and displays dispute information, including optional fields like token and additional info. This complements the changes for admin dispute commands.

src/cli.rs (4)

162-170: LGTM: Added GetAdminDm command for admin operations.

The new command follows the structure of existing commands and includes appropriate parameters, enabling admin users to retrieve direct messages specifically for dispute handling.


378-382: Implementation correctly passes admin status to execute_get_dm.

The function calls properly pass the admin status parameter (false for regular GetDm, true for GetAdminDm), ensuring that the appropriate logic is executed for each command type.


438-459: LGTM: Fixed admin key handling for AdmSettle and AdmCancel commands.

The implementation now correctly retrieves the admin private key from the environment variable instead of using identity keys, which addresses the reported issue with admin commands. The error handling for missing keys is also appropriate.


461-470: LGTM: Fixed admin key handling for AdmTakeDispute command.

The implementation now correctly retrieves the admin private key from the environment variable, addressing the reported "invalid_pubkey" error mentioned in the PR comments. This ensures that the correct admin key is used for taking disputes.

@arkanoider
Copy link
Collaborator Author

Closing this in favor of #123

@arkanoider arkanoider closed this Mar 14, 2025
@grunch grunch deleted the feature-disputes branch June 2, 2025 12:47
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.

3 participants