Feature-nip69-order-status#467
Conversation
WalkthroughThis pull request introduces a new function, Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (6)
✨ Finishing Touches
🪧 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
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/nip33.rs (2)
74-91: Documentation mismatch and function naming suggestionThe documentation on line 80 states that this function returns a "json string with order status according to nip69" but the function actually returns a plain string (not JSON-formatted). Also, the function name
create_status_tagsuggests it creates a tag object, but it only returns the status string.Consider:
- Updating the documentation to accurately reflect the return value
- Renaming the function to something like
determine_order_statusorget_normalized_statusto better reflect its purpose-/// # Returns a json string with order status according to nip69 +/// # Returns a string with the normalized order status according to nip69 /// Possible states for nostr event are pending, in-progress, success, canceled -fn create_status_tag(order: &Order) -> String { +fn determine_order_status(order: &Order) -> String {
83-90: Consider simplifying the status check logicThe current implementation uses a somewhat counterintuitive approach by checking if various status checks return errors. This makes the code a bit harder to follow. Consider refactoring to make the intent clearer.
- if order.check_status(Status::Pending).is_err() - && order.check_status(Status::Success).is_err() - && order.check_status(Status::Canceled).is_err() - { - "in-progress".to_string() - } else { - order.status.to_string() - } + match order.status.as_str() { + "Pending" | "Success" | "Canceled" => order.status.to_string(), + _ => "in-progress".to_string() + }Alternatively, if
check_statusis the preferred approach:- if order.check_status(Status::Pending).is_err() - && order.check_status(Status::Success).is_err() - && order.check_status(Status::Canceled).is_err() - { - "in-progress".to_string() - } else { - order.status.to_string() - } + // If it's not one of the standard statuses, return "in-progress" + if order.check_status(Status::Pending).is_ok() + || order.check_status(Status::Success).is_ok() + || order.check_status(Status::Canceled).is_ok() + { + order.status.to_string() + } else { + "in-progress".to_string() + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/nip33.rs(2 hunks)
🔇 Additional comments (2)
src/nip33.rs (2)
116-116: Good modularization of status handlingMoving the status determination logic to a dedicated function is a good improvement that enhances code modularity and maintainability.
74-91:Details
❓ Verification inconclusive
Verify behavior change for non-standard statuses
This change introduces a potential behavior difference: previously any status would be returned as-is, but now statuses other than Pending, Success, and Canceled will be mapped to "in-progress". Please verify this is the intended behavior according to the nip69 specification.
Also applies to: 116-116
🏁 Script executed:
#!/bin/bash # Check if there are any order statuses in the codebase other than the three explicitly handled ones echo "Searching for Status enum definition..." rg -A 10 "enum Status" --type rust echo "Searching for potential status values used in the codebase..." rg "Status::[A-Za-z]+" --type rust | sort | uniqLength of output: 6336
Attention: Verify Mapping for Non-Standard Statuses
The updated
create_status_tag()function insrc/nip33.rs(lines 74–91 and line 116) now converts any order status that isn’tPending,Success, orCanceledto"in-progress". Our code search uncovered numerous other status values (e.g.,SettledHoldInvoice,WaitingBuyerInvoice,CooperativelyCanceled, etc.) used across the codebase. This behavior represents a departure from the previous implementation where statuses were returned as-is. Please verify that this change aligns with the nip69 specification and is intended; if non-standard statuses should be preserved instead of defaulting to"in-progress", further adjustments might be necessary.
Catrya
left a comment
There was a problem hiding this comment.
Hi @arkanoider
Statuses should only be published once. What's happening is that every time the database status changes, a 38383 event with the status in-progress is published again. This event should only be published once when the order is taken and moves to the waiting-buyer-invoice or awaiting-payment in the db. But not again when it moves to active or fiatsent in db.
It's also happening that when a dispute is opened, when the admin resolves it, another event with the status in-progress is published. It should be canceled if the admin canceled it, or success if the admin completed it.
I still need to do more testing, but this is what I've found so far.
|
do a round of tests with this improvements. Use this pull request of |
|
@Catrya now we should have this mapping between order status and nostr events:
Other states should not create events on nostr. |
* 📝 Add docstrings to `feature-full-privacy-mode-checks` (#455) * add feature to check correctly if order is full privacy or normal * 📝 Add docstrings to `feature-full-privacy-mode-checks` Docstrings generation was requested by @arkanoider. * #454 (comment) The following files were modified: * `src/app/order.rs` * `src/util.rs` --------- Co-authored-by: arkanoider <github.913zc@simplelogin.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: arkanoider <113362043+arkanoider@users.noreply.github.com> * Fix network in order event (#452) Now in orers event 38383 the network that comes out is the correct one * Feature anyhow removal (#459) * remove of anyhow dependency start * removed anyhow dependecy * remove patch from cargo.toml * Update mostro-core version --------- Co-authored-by: Francisco Calderón <fjcalderon@gmail.com> * Feature disputes (#463) * Feature: dispute fix for new logic * fix for coop cancel case * Add logic for info message about dispute for solver * first working dispute info message for admin after taking disputes * added fields to dispute info message for solver * removed some probably useless and refactored a bit admin-take-dispute function * clippy suggestion * other cosmetics to admin take file * some other cosmetics on admin-take-dispute file * fix on admin-take * Update admin_take_dispute.rs * fixed a wrong search of order id in admin take file@ * Fix: added correct check to add solver from admin cli * fix: wrong check on admin cancel * Fix initiator pubkey: now is the trade key of initiator not identity * quick fix for full privacy orders * new logic with mixed full privacy - regular reputation mode * Update cargo toml to compile with version 0.6.32 of mostro-core - this is in preparation for migrating to nostr-sdk 0.40 * rollback sdk to 0.38 version to merge disputes - we will come back to 0.40 when we will fix signature issue * Update mostro-core dependency --------- Co-authored-by: Francisco Calderón <fjcalderon@gmail.com> * added correction for the case of buyer adding back a new invoice after payment failure (#462) * Fix for nostr sdk 40 issue on incoming message (#465) * testing sdk 40 * fix for sdk 40 * cleaned cargo.toml * Bump mostro core version --------- Co-authored-by: Francisco Calderón <fjcalderon@gmail.com> * fix: sends order with an updated 'status' field as the reply to add-invoice when there is a preimage (#464) * Feature-nip69-order-status (#467) * feature: align to nip69 order status in nostr event * Improved in progress nip69 logic * refined event states of the order with nip69 request * add another check to avoid multiple events with in-progress state * Privacy range order fix (#468) * add optional field for users in full privacy inside solver message * To be tested - privacy range child order fix * fix cargo.toml * bumped mostro-core version to 6.35 * New user or privacy order send same user info with zeros (#471) * new user or privacy order send same user info with zeros * fix days field and removed some println! macro with nicer tracing messages * bumped mostro-core version to 6.36 and added requested fix to compile * Add previous order state in database for solver message (#472) * add previous state in database for solver message * bumped mostro-core version to 6.36 * Taker info message to maker. I think that could be modifies in a more generic UserInfo. (#473) * added logic to send infos to maker when an order is taken * Add takers info message for maker * fix cargo.toml * set peer pubkey to empty string when notifying taker reputation to maker * moved user info message to the right point of the order flow * fix cargo.toml * changed message struct from UserDisputeInfo to UserInfo * fix: get master keys for user infos * Bumped mostro-core to version 6.38 * fix for buy order flow with message to maker (#479) * Rabbit fixes --------- Co-authored-by: Francisco Calderón <fjcalderon@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Catrya <140891948+Catrya@users.noreply.github.com> Co-authored-by: Bilthon <bilthon@gmail.com>
* feature: align to nip69 order status in nostr event * Improved in progress nip69 logic * refined event states of the order with nip69 request * add another check to avoid multiple events with in-progress state
* 📝 Add docstrings to `feature-full-privacy-mode-checks` (#455) * add feature to check correctly if order is full privacy or normal * 📝 Add docstrings to `feature-full-privacy-mode-checks` Docstrings generation was requested by @arkanoider. * #454 (comment) The following files were modified: * `src/app/order.rs` * `src/util.rs` --------- Co-authored-by: arkanoider <github.913zc@simplelogin.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: arkanoider <113362043+arkanoider@users.noreply.github.com> * Feature disputes (#463) * Feature: dispute fix for new logic * fix for coop cancel case * Add logic for info message about dispute for solver * first working dispute info message for admin after taking disputes * added fields to dispute info message for solver * removed some probably useless and refactored a bit admin-take-dispute function * clippy suggestion * other cosmetics to admin take file * some other cosmetics on admin-take-dispute file * fix on admin-take * Update admin_take_dispute.rs * fixed a wrong search of order id in admin take file@ * Fix: added correct check to add solver from admin cli * fix: wrong check on admin cancel * Fix initiator pubkey: now is the trade key of initiator not identity * quick fix for full privacy orders * new logic with mixed full privacy - regular reputation mode * Update cargo toml to compile with version 0.6.32 of mostro-core - this is in preparation for migrating to nostr-sdk 0.40 * rollback sdk to 0.38 version to merge disputes - we will come back to 0.40 when we will fix signature issue * Update mostro-core dependency --------- Co-authored-by: Francisco Calderón <fjcalderon@gmail.com> * Fix for nostr sdk 40 issue on incoming message (#465) * testing sdk 40 * fix for sdk 40 * cleaned cargo.toml * Bump mostro core version --------- Co-authored-by: Francisco Calderón <fjcalderon@gmail.com> * Feature-nip69-order-status (#467) * feature: align to nip69 order status in nostr event * Improved in progress nip69 logic * refined event states of the order with nip69 request * add another check to avoid multiple events with in-progress state * Taker info message to maker. I think that could be modifies in a more generic UserInfo. (#473) * added logic to send infos to maker when an order is taken * Add takers info message for maker * fix cargo.toml * set peer pubkey to empty string when notifying taker reputation to maker * moved user info message to the right point of the order flow * fix cargo.toml * changed message struct from UserDisputeInfo to UserInfo * fix: get master keys for user infos * Bumped mostro-core to version 6.38 * first commit for database encryption * Moving on with encryption work * Implemented base64 on cipher * Takebuy and takesell pending orders check now working with encryption * Removed unwraps * Finishing code: changed password management and completing checks * Finishing code: used hashset for search * added unit test for evaluate timings * first order cycle completed - to be fixed empty password case * Added logic for testing a caching idea using hashmap to speed up search of identity keys when encrypted * ready to start review process * Cleaned test * removed patch from cargo.toml * Rabbit fixes * some improvements to have also rating working with encryption * Removed useless call in db.rs * fix for tests * Cosmetics on release.rs - improved a bit a function in more ribust way * fix: wrong check on full privacy orders in disputes * fix: more meaningful variable name in dispute setup * fix: wrong commented lines reactivated * fix: some fixes in privacy orders with encryption * fix: some fixes following coderabbit advices Introduced a random delay on password entering to avoid timing attacks. Removed awaiting from store_encrypted function that does not require async. * refactor: removed many useless connection opening to database with direct use of borrowed pool variable * chore: more meaningful text for user in db.rs * chore: improved encryption unit test now fix salt for testing works - fix salt and password are used to test timings with decryption using key caching, to test it do: cargo test test_fetch_string_column_scalar -- --nocapture * refactor: some improvements in db.rs improved password error management reduce code duplication for pending orders checks * chore(rebase-on-main): commit cargo.lock for rebasing on top of main encrytpion * feat: completing refactor and rebase of encryption pr * refactor: introduced new refactoring of encryption-decryption function - cargo compiles now, we will have to create the new mostro-core after some testings. - bumped nostr-sdk to 0.41 release, no breaking changes * chore: temporary added git branch of mostro-core to compile * chore(test): fix tests * chore: bumped mostro-core version in cargo.toml * fix: wrong database path string creation * chore: fix tests in db.rs * fix: child order after a trade with a full privacy user have wrong master keys * fix: typo on check password hash function * fix: child order event after a complete order does not send user information also if order is normal (not full privacy) * fix: if a child order come from a privacy order user rating are sent in the event wit all zeroes * fix: fixed bug found by Catrya - when I recreate the child order master keys were saved without encryption so when a takesell or takebuy comes in the search for pending user orders generate a decrytpion error. --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>
@Catrya,
this should fix #369 .
Order status in nostr event should be one of this now:
Summary by CodeRabbit