diff --git a/Cargo.lock b/Cargo.lock index 8d54478..d44978d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1991,9 +1991,9 @@ dependencies = [ [[package]] name = "mostro-core" -version = "0.6.20" +version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "926d9b23a394e7fc4e4aee38cb5e7a26c09766da67216ad63c730396c439fb63" +checksum = "52433fda546a12791848792b51980953e66385ff733cbf42df687854315e8f5b" dependencies = [ "anyhow", "bitcoin", diff --git a/Cargo.toml b/Cargo.toml index 2f3358e..a7c0dc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ uuid = { version = "1.8.0", features = [ "serde", ] } reqwest = { version = "0.12.1", features = ["json"] } -mostro-core = { version = "0.6.20", features = ["sqlx"] } +mostro-core = { version = "0.6.21", features = ["sqlx"] } tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } config = "0.14.0" diff --git a/src/app.rs b/src/app.rs index 1366aa2..2bd3559 100644 --- a/src/app.rs +++ b/src/app.rs @@ -137,7 +137,7 @@ async fn check_trade_index(pool: &Pool, event: &UnwrappedGift, msg: &Mes send_cant_do_msg( None, msg.get_inner_message_kind().id, - Some(CantDoReason::InvalidTextMessage), + Some(CantDoReason::CantCreateUser), &event.rumor.pubkey, ) .await; diff --git a/src/app/admin_add_solver.rs b/src/app/admin_add_solver.rs index f00e673..03b0eb3 100644 --- a/src/app/admin_add_solver.rs +++ b/src/app/admin_add_solver.rs @@ -2,7 +2,7 @@ use crate::db::add_new_user; use crate::util::{send_cant_do_msg, send_dm}; use anyhow::Result; -use mostro_core::message::{Action, Message, Payload}; +use mostro_core::message::{Action, CantDoReason, Message, Payload}; use mostro_core::user::User; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -35,7 +35,13 @@ pub async fn admin_add_solver_action( // Check if the pubkey is Mostro if event.rumor.pubkey.to_string() != my_keys.public_key().to_string() { // We create a Message - send_cant_do_msg(request_id, None, None, &event.rumor.pubkey).await; + send_cant_do_msg( + request_id, + None, + Some(CantDoReason::InvalidPubkey), + &event.rumor.pubkey, + ) + .await; return Ok(()); } let trade_index = inner_message.trade_index.unwrap_or(0); diff --git a/src/app/admin_take_dispute.rs b/src/app/admin_take_dispute.rs index e2f9281..5dbc473 100644 --- a/src/app/admin_take_dispute.rs +++ b/src/app/admin_take_dispute.rs @@ -4,7 +4,7 @@ use crate::util::{get_nostr_client, send_cant_do_msg, send_dm, send_new_order_ms use anyhow::{Error, Result}; use mostro_core::dispute::{Dispute, Status}; -use mostro_core::message::{Action, Message, Payload, Peer}; +use mostro_core::message::{Action, CantDoReason, Message, Payload, Peer}; use mostro_core::order::Order; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -74,7 +74,13 @@ pub async fn admin_take_dispute_action( if let Ok(dispute_status) = Status::from_str(&dispute.status) { if !pubkey_event_can_solve(pool, &event.rumor.pubkey, dispute_status).await { // We create a Message - send_cant_do_msg(request_id, Some(dispute_id), None, &event.rumor.pubkey).await; + send_cant_do_msg( + request_id, + Some(dispute_id), + Some(CantDoReason::InvalidPubkey), + &event.rumor.pubkey, + ) + .await; return Ok(()); } } else { diff --git a/src/app/cancel.rs b/src/app/cancel.rs index d66da4b..1f8e22c 100644 --- a/src/app/cancel.rs +++ b/src/app/cancel.rs @@ -6,7 +6,7 @@ use crate::lightning::LndConnector; use crate::util::{send_cant_do_msg, send_new_order_msg, update_order_event}; use anyhow::{Error, Result}; -use mostro_core::message::{Action, Message}; +use mostro_core::message::{Action, CantDoReason, Message}; use mostro_core::order::{Kind as OrderKind, Order, Status}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -40,6 +40,20 @@ pub async fn cancel_action( } }; + if order.status == Status::Canceled.to_string() + || order.status == Status::CooperativelyCanceled.to_string() + || order.status == Status::CanceledByAdmin.to_string() + { + send_cant_do_msg( + request_id, + Some(order_id), + Some(CantDoReason::OrderAlreadyCanceled), + &event.rumor.pubkey, + ) + .await; + return Ok(()); + } + if order.status == Status::Pending.to_string() { // Validates if this user is the order creator if user_pubkey != order.creator_pubkey { @@ -75,8 +89,7 @@ pub async fn cancel_action( } if order.kind == OrderKind::Sell.to_string() - && (order.status == Status::WaitingBuyerInvoice.to_string() - || order.status == Status::WaitingBuyerInvoice.to_string()) + && order.status == Status::WaitingBuyerInvoice.to_string() { cancel_add_invoice(ln_client, &mut order, event, pool, my_keys, request_id).await?; } diff --git a/src/app/dispute.rs b/src/app/dispute.rs index 855c11e..bf2a710 100644 --- a/src/app/dispute.rs +++ b/src/app/dispute.rs @@ -11,7 +11,7 @@ use crate::util::{get_nostr_client, send_cant_do_msg, send_new_order_msg}; use anyhow::{Error, Result}; use mostro_core::dispute::Dispute; -use mostro_core::message::{Action, Message, Payload}; +use mostro_core::message::{Action, CantDoReason, Message, Payload}; use mostro_core::order::{Order, Status}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -184,7 +184,13 @@ pub async fn dispute_action( match get_counterpart_info(&message_sender, &buyer, &seller) { Ok((counterpart, is_buyer_dispute)) => (counterpart, is_buyer_dispute), Err(_) => { - send_cant_do_msg(request_id, Some(order.id), None, &event.rumor.pubkey).await; + send_cant_do_msg( + request_id, + Some(order.id), + Some(CantDoReason::InvalidPubkey), + &event.rumor.pubkey, + ) + .await; return Ok(()); } }; diff --git a/src/app/fiat_sent.rs b/src/app/fiat_sent.rs index aeaae55..ce9d895 100644 --- a/src/app/fiat_sent.rs +++ b/src/app/fiat_sent.rs @@ -1,7 +1,7 @@ use crate::util::{send_cant_do_msg, send_new_order_msg, update_order_event}; use anyhow::{Error, Result}; -use mostro_core::message::{Action, Message, Payload, Peer}; +use mostro_core::message::{Action, CantDoReason, Message, Payload, Peer}; use mostro_core::order::{Order, Status}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -46,7 +46,13 @@ pub async fn fiat_sent_action( } // Check if the pubkey is the buyer if Some(event.rumor.pubkey.to_string()) != order.buyer_pubkey { - send_cant_do_msg(request_id, Some(order.id), None, &event.rumor.pubkey).await; + send_cant_do_msg( + request_id, + Some(order.id), + Some(CantDoReason::InvalidPubkey), + &event.rumor.pubkey, + ) + .await; return Ok(()); } diff --git a/src/app/order.rs b/src/app/order.rs index caaeef8..2b4250b 100644 --- a/src/app/order.rs +++ b/src/app/order.rs @@ -2,7 +2,7 @@ use crate::cli::settings::Settings; use crate::lightning::invoice::is_valid_invoice; use crate::util::{get_bitcoin_price, publish_order, send_cant_do_msg, send_new_order_msg}; use anyhow::Result; -use mostro_core::message::{Action, Message}; +use mostro_core::message::{Action, CantDoReason, Message}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; use nostr_sdk::Keys; @@ -49,7 +49,13 @@ pub async fn order_action( // in case of single order do like usual if let (Some(min), Some(max)) = (order.min_amount, order.max_amount) { if min >= max { - send_cant_do_msg(request_id, order.id, None, &event.rumor.pubkey).await; + send_cant_do_msg( + request_id, + order.id, + Some(CantDoReason::InvalidAmount), + &event.rumor.pubkey, + ) + .await; return Ok(()); } if order.amount != 0 { @@ -70,11 +76,16 @@ pub async fn order_action( } let premium = (order.premium != 0).then_some(order.premium); - let amount = (order.amount != 0).then_some(order.amount); let fiat_amount = (order.fiat_amount != 0).then_some(order.fiat_amount); - if premium.is_some() && amount.is_some() && fiat_amount.is_some() { - send_cant_do_msg(request_id, None, None, &event.sender).await; + if premium.is_some() && fiat_amount.is_some() { + send_cant_do_msg( + request_id, + None, + Some(CantDoReason::InvalidParameters), + &event.sender, + ) + .await; return Ok(()); } diff --git a/src/app/rate_user.rs b/src/app/rate_user.rs index a68a07a..0086e00 100644 --- a/src/app/rate_user.rs +++ b/src/app/rate_user.rs @@ -80,7 +80,13 @@ pub async fn update_user_reputation_action( let message_sender = event.rumor.pubkey.to_string(); if order.status != Status::Success.to_string() { - send_cant_do_msg(request_id, Some(order.id), None, &event.rumor.pubkey).await; + send_cant_do_msg( + request_id, + Some(order.id), + Some(CantDoReason::InvalidOrderStatus), + &event.rumor.pubkey, + ) + .await; error!("Order Id {order_id} wrong status"); return Ok(()); } diff --git a/src/app/take_buy.rs b/src/app/take_buy.rs index 05830af..5dc7e30 100644 --- a/src/app/take_buy.rs +++ b/src/app/take_buy.rs @@ -4,7 +4,7 @@ use crate::util::{ }; use anyhow::{Error, Result}; -use mostro_core::message::{Action, Message}; +use mostro_core::message::{Action, CantDoReason, Message}; use mostro_core::order::{Kind, Order, Status}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -38,7 +38,13 @@ pub async fn take_buy_action( // Maker can't take own order if order.kind != Kind::Buy.to_string() || order.creator_pubkey == event.rumor.pubkey.to_hex() { - send_cant_do_msg(request_id, Some(order.id), None, &event.rumor.pubkey).await; + send_cant_do_msg( + request_id, + Some(order.id), + Some(CantDoReason::InvalidPubkey), + &event.rumor.pubkey, + ) + .await; return Ok(()); } diff --git a/src/app/take_sell.rs b/src/app/take_sell.rs index 95b0b5d..a5ab170 100644 --- a/src/app/take_sell.rs +++ b/src/app/take_sell.rs @@ -39,7 +39,13 @@ pub async fn take_sell_action( // Maker can't take own order if order.creator_pubkey == event.rumor.pubkey.to_hex() { - send_cant_do_msg(request_id, Some(order.id), None, &event.rumor.pubkey).await; + send_cant_do_msg( + request_id, + Some(order.id), + Some(CantDoReason::InvalidPubkey), + &event.rumor.pubkey, + ) + .await; return Ok(()); } diff --git a/src/util.rs b/src/util.rs index f059428..04ef46a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -637,7 +637,7 @@ pub async fn settle_seller_hold_invoice( send_cant_do_msg( request_id, Some(order.id), - Some(CantDoReason::InvalidPeer), + Some(CantDoReason::InvalidPubkey), &event.rumor.pubkey, ) .await;