diff --git a/Cargo.lock b/Cargo.lock index d44978d2..77278a43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1991,9 +1991,9 @@ dependencies = [ [[package]] name = "mostro-core" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52433fda546a12791848792b51980953e66385ff733cbf42df687854315e8f5b" +checksum = "489c5f06b2a2a622cbf5901303885b44002f1f19d7f9650e997787dfe586de28" dependencies = [ "anyhow", "bitcoin", diff --git a/Cargo.toml b/Cargo.toml index a7c0dc33..242519d5 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.21", features = ["sqlx"] } +mostro-core = { version = "0.6.22", features = ["sqlx"] } tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } config = "0.14.0" diff --git a/epa.patch b/epa.patch new file mode 100644 index 00000000..3acc6f94 --- /dev/null +++ b/epa.patch @@ -0,0 +1,57 @@ +diff --git a/src/app/release.rs b/src/app/release.rs +index 2513540..ffdefed 100644 +--- a/src/app/release.rs ++++ b/src/app/release.rs +@@ -328,6 +328,7 @@ pub async fn get_child_order( + } + Ordering::Less => { + notify_invalid_amount(order, request_id).await; ++ return Ok((false, order.clone())); + } + } + } +@@ -337,6 +338,8 @@ pub async fn get_child_order( + + fn create_base_order(order: &Order) -> Order { + let mut new_order = order.clone(); ++ new_order.id = uuid::Uuid::new_v4(); ++ new_order.status = Status::Pending.to_string(); + new_order.amount = 0; + new_order.hash = None; + new_order.preimage = None; +@@ -363,8 +366,6 @@ async fn update_order_for_equal(new_max: i64, new_order: &mut Order, my_keys: &K + new_order.fiat_amount = new_max; + new_order.max_amount = None; + new_order.min_amount = None; +- new_order.status = Status::Pending.to_string(); +- new_order.id = uuid::Uuid::new_v4(); + + let tags = crate::nip33::order_to_tags(new_order, None); + let event = crate::nip33::new_event(my_keys, "", new_order.id.to_string(), tags)?; +@@ -372,7 +373,7 @@ async fn update_order_for_equal(new_max: i64, new_order: &mut Order, my_keys: &K + new_order.clone().create(&pool).await?; + NOSTR_CLIENT + .get() +- .unwrap() ++ .ok_or_else(|| anyhow::Error::msg("NOSTR_CLIENT not initialized"))? + .send_event(event) + .await + .map_err(|err| anyhow::Error::msg(err.to_string()))?; +@@ -388,8 +389,6 @@ async fn update_order_for_greater( + let pool = db::connect().await?; + new_order.max_amount = Some(new_max); + new_order.fiat_amount = 0; +- new_order.id = uuid::Uuid::new_v4(); +- new_order.status = Status::Pending.to_string(); + + let tags = crate::nip33::order_to_tags(new_order, None); + let event = crate::nip33::new_event(my_keys, "", new_order.id.to_string(), tags)?; +@@ -397,7 +396,7 @@ async fn update_order_for_greater( + new_order.clone().create(&pool).await?; + NOSTR_CLIENT + .get() +- .unwrap() ++ .ok_or_else(|| anyhow::Error::msg("NOSTR_CLIENT not initialized"))? + .send_event(event) + .await + .map_err(|err| anyhow::Error::msg(err.to_string()))?; diff --git a/src/app/add_invoice.rs b/src/app/add_invoice.rs index b2ba221b..b756ff35 100644 --- a/src/app/add_invoice.rs +++ b/src/app/add_invoice.rs @@ -83,13 +83,11 @@ pub async fn add_invoice_action( { Ok(_) => payment_request, Err(_) => { - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::IncorrectInvoiceAmount, - None, + Some(CantDoReason::InvalidAmount), &event.rumor.pubkey, - None, ) .await; return Ok(()); @@ -120,13 +118,11 @@ pub async fn add_invoice_action( return Ok(()); } _ => { - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::NotAllowedByStatus, - None, + Some(CantDoReason::NotAllowedByStatus), &event.rumor.pubkey, - None, ) .await; return Ok(()); diff --git a/src/app/admin_cancel.rs b/src/app/admin_cancel.rs index 3bf9bc7d..298e4b8a 100644 --- a/src/app/admin_cancel.rs +++ b/src/app/admin_cancel.rs @@ -4,11 +4,11 @@ use std::str::FromStr; use crate::db::{find_dispute_by_order_id, is_assigned_solver}; use crate::lightning::LndConnector; use crate::nip33::new_event; -use crate::util::{get_nostr_client, send_dm, send_new_order_msg, update_order_event}; +use crate::util::{get_nostr_client, send_cant_do_msg, send_dm, update_order_event}; use anyhow::{Error, Result}; use mostro_core::dispute::Status as DisputeStatus; -use mostro_core::message::{Action, Message, MessageKind}; +use mostro_core::message::{Action, CantDoReason, Message, MessageKind}; use mostro_core::order::{Order, Status}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -35,15 +35,14 @@ pub async fn admin_cancel_action( match is_assigned_solver(pool, &event.rumor.pubkey.to_string(), order_id).await { Ok(false) => { - send_new_order_msg( - inner_message.request_id, + send_cant_do_msg( + request_id, Some(order_id), - Action::IsNotYourDispute, - None, + Some(CantDoReason::IsNotYourDispute), &event.rumor.pubkey, - inner_message.trade_index, ) .await; + return Ok(()); } Err(e) => { @@ -78,15 +77,14 @@ pub async fn admin_cancel_action( } if order.status != Status::Dispute.to_string() { - send_new_order_msg( - inner_message.request_id, + send_cant_do_msg( + request_id, Some(order.id), - Action::NotAllowedByStatus, - None, + Some(CantDoReason::NotAllowedByStatus), &event.rumor.pubkey, - inner_message.trade_index, ) .await; + return Ok(()); } diff --git a/src/app/admin_settle.rs b/src/app/admin_settle.rs index c25a8626..87a6a3f7 100644 --- a/src/app/admin_settle.rs +++ b/src/app/admin_settle.rs @@ -2,12 +2,12 @@ use crate::db::{find_dispute_by_order_id, is_assigned_solver}; use crate::lightning::LndConnector; use crate::nip33::new_event; use crate::util::{ - get_nostr_client, send_dm, send_new_order_msg, settle_seller_hold_invoice, update_order_event, + get_nostr_client, send_cant_do_msg, send_dm, settle_seller_hold_invoice, update_order_event, }; use anyhow::{Error, Result}; use mostro_core::dispute::Status as DisputeStatus; -use mostro_core::message::{Action, Message, MessageKind}; +use mostro_core::message::{Action, CantDoReason, Message, MessageKind}; use mostro_core::order::{Order, Status}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -37,15 +37,14 @@ pub async fn admin_settle_action( match is_assigned_solver(pool, &event.rumor.pubkey.to_string(), order_id).await { Ok(false) => { - send_new_order_msg( - msg.get_inner_message_kind().request_id, + send_cant_do_msg( + request_id, Some(order_id), - Action::IsNotYourDispute, - None, + Some(CantDoReason::IsNotYourDispute), &event.rumor.pubkey, - inner_message.trade_index, ) .await; + return Ok(()); } Err(e) => { @@ -80,15 +79,14 @@ pub async fn admin_settle_action( } if order.status != Status::Dispute.to_string() { - send_new_order_msg( - inner_message.request_id, + send_cant_do_msg( + request_id, Some(order.id), - Action::NotAllowedByStatus, - None, + Some(CantDoReason::NotAllowedByStatus), &event.rumor.pubkey, - inner_message.trade_index, ) .await; + return Ok(()); } diff --git a/src/app/admin_take_dispute.rs b/src/app/admin_take_dispute.rs index 5dbc4734..978d2ebd 100644 --- a/src/app/admin_take_dispute.rs +++ b/src/app/admin_take_dispute.rs @@ -1,6 +1,6 @@ use crate::db::find_solver_pubkey; use crate::nip33::new_event; -use crate::util::{get_nostr_client, send_cant_do_msg, send_dm, send_new_order_msg}; +use crate::util::{get_nostr_client, send_cant_do_msg, send_dm}; use anyhow::{Error, Result}; use mostro_core::dispute::{Dispute, Status}; @@ -56,16 +56,14 @@ pub async fn admin_take_dispute_action( let mut dispute = match Dispute::by_id(pool, dispute_id).await? { Some(dispute) => dispute, None => { - // We create a Message - send_new_order_msg( + send_cant_do_msg( request_id, Some(dispute_id), - Action::NotFound, - None, + Some(CantDoReason::NotFound), &event.rumor.pubkey, - None, ) .await; + return Ok(()); } }; diff --git a/src/app/cancel.rs b/src/app/cancel.rs index 1f8e22c7..e61ac185 100644 --- a/src/app/cancel.rs +++ b/src/app/cancel.rs @@ -57,14 +57,11 @@ pub async fn cancel_action( if order.status == Status::Pending.to_string() { // Validates if this user is the order creator if user_pubkey != order.creator_pubkey { - // We create a Message - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::IsNotYourOrder, - None, + Some(CantDoReason::IsNotYourOrder), &event.rumor.pubkey, - None, ) .await; } else { diff --git a/src/app/dispute.rs b/src/app/dispute.rs index bf2a710c..c2ce6b8d 100644 --- a/src/app/dispute.rs +++ b/src/app/dispute.rs @@ -115,15 +115,14 @@ async fn get_valid_order( // Only allow disputes for Active or FiatSent orders if !matches!(status, Status::Active | Status::FiatSent) { // Notify the sender that the action is not allowed for this status - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::NotAllowedByStatus, - None, + Some(CantDoReason::NotAllowedByStatus), &event.rumor.pubkey, - None, ) .await; + return Err(Error::msg(format!( "Order {} with status {} does not allow disputes. Must be Active or FiatSent", order.id, order.status diff --git a/src/app/fiat_sent.rs b/src/app/fiat_sent.rs index ce9d8950..690e167e 100644 --- a/src/app/fiat_sent.rs +++ b/src/app/fiat_sent.rs @@ -33,15 +33,14 @@ pub async fn fiat_sent_action( }; // Send to user a DM with the error if order.status != Status::Active.to_string() { - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::NotAllowedByStatus, - None, + Some(CantDoReason::NotAllowedByStatus), &event.rumor.pubkey, - None, ) .await; + return Ok(()); } // Check if the pubkey is the buyer diff --git a/src/app/order.rs b/src/app/order.rs index 2b4250be..9b6788aa 100644 --- a/src/app/order.rs +++ b/src/app/order.rs @@ -1,8 +1,8 @@ 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 crate::util::{get_bitcoin_price, publish_order, send_cant_do_msg}; use anyhow::Result; -use mostro_core::message::{Action, CantDoReason, Message}; +use mostro_core::message::{CantDoReason, Message}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; use nostr_sdk::Keys; @@ -28,15 +28,14 @@ pub async fn order_action( match is_valid_invoice(invoice.clone(), None, None).await { Ok(_) => (), Err(_) => { - send_new_order_msg( + send_cant_do_msg( request_id, order.id, - Action::IncorrectInvoiceAmount, - None, + Some(CantDoReason::InvalidAmount), &event.rumor.pubkey, - None, ) .await; + return Ok(()); } } @@ -59,15 +58,14 @@ pub async fn order_action( return Ok(()); } if order.amount != 0 { - send_new_order_msg( + send_cant_do_msg( request_id, None, - Action::InvalidSatsAmount, - None, + Some(CantDoReason::InvalidAmount), &event.rumor.pubkey, - None, ) .await; + return Ok(()); } amount_vec.clear(); @@ -106,28 +104,25 @@ pub async fn order_action( // Check amount is positive - extra safety check if quote < 0 { - send_new_order_msg( + send_cant_do_msg( request_id, None, - Action::InvalidSatsAmount, - None, + Some(CantDoReason::InvalidAmount), &event.rumor.pubkey, - None, ) .await; + return Ok(()); } if quote > mostro_settings.max_order_amount as i64 || quote < mostro_settings.min_payment_amount as i64 { - send_new_order_msg( + send_cant_do_msg( request_id, None, - Action::OutOfRangeSatsAmount, - None, + Some(CantDoReason::OutOfRangeSatsAmount), &event.rumor.pubkey, - None, ) .await; return Ok(()); diff --git a/src/app/release.rs b/src/app/release.rs index 4acdc7ab..2baf3398 100644 --- a/src/app/release.rs +++ b/src/app/release.rs @@ -1,5 +1,5 @@ use crate::cli::settings::Settings; -use crate::db; +use crate::db::{self}; use crate::lightning::LndConnector; use crate::lnurl::resolv_ln_address; use crate::util::{ @@ -7,11 +7,10 @@ use crate::util::{ update_order_event, }; use crate::NOSTR_CLIENT; - use anyhow::{Error, Result}; use fedimint_tonic_lnd::lnrpc::payment::PaymentStatus; use lnurl::lightning_address::LightningAddress; -use mostro_core::message::{Action, CantDoReason, Message}; +use mostro_core::message::{Action, CantDoReason, Message, Payload}; use mostro_core::order::{Order, Status}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -102,15 +101,14 @@ pub async fn release_action( && current_status != Status::FiatSent && current_status != Status::Dispute { - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::NotAllowedByStatus, - None, + Some(CantDoReason::NotAllowedByStatus), &event.rumor.pubkey, - None, ) .await; + return Ok(()); } @@ -273,122 +271,26 @@ async fn payment_success( ) .await; - // Check if order is range type - // Add parent range id and update max amount - if order.max_amount.is_some() && order.min_amount.is_some() { - if let Some(max) = order.max_amount { - if let Some(new_max) = max.checked_sub(order.fiat_amount) { - let mut new_order = order.clone(); - new_order.amount = 0; - new_order.hash = None; - new_order.preimage = None; - new_order.buyer_invoice = None; - new_order.taken_at = 0; - new_order.invoice_held_at = 0; - new_order.range_parent_id = Some(order.id); - if new_order.kind == "sell" { - new_order.buyer_pubkey = None; - new_order.master_buyer_pubkey = None; - new_order.trade_index_buyer = None; - } else { - new_order.seller_pubkey = None; - new_order.master_seller_pubkey = None; - new_order.trade_index_seller = None; - } - if let Some(min_amount) = &order.min_amount { - match new_max.cmp(min_amount) { - Ordering::Equal => { - // Update order in case max == min - let pool = db::connect().await?; - new_order.fiat_amount = new_max; - new_order.max_amount = None; - new_order.min_amount = None; - new_order.status = Status::Pending.to_string(); - new_order.id = uuid::Uuid::new_v4(); - new_order.status = Status::Pending.to_string(); - // We transform the order fields to tags to use in the event - let tags = crate::nip33::order_to_tags(&new_order, None); - - info!("range order tags to be republished: {:#?}", tags); - // nip33 kind with order fields as tags and order id as identifier - let event = crate::nip33::new_event( - my_keys, - "", - new_order.id.to_string(), - tags, - )?; - let event_id = event.id.to_string(); - // We update the order with the new event_id - new_order.event_id = event_id; - // CRUD order creation - new_order.clone().create(&pool).await?; - let _ = NOSTR_CLIENT - .get() - .unwrap() - .send_event(event) - .await - .map(|_s| ()) - .map_err(|err| err.to_string()); - } - Ordering::Greater => { - // Update order in case new max is still greater the min amount - let pool = db::connect().await?; - // let mut new_order = order.clone(); - new_order.max_amount = Some(new_max); - new_order.fiat_amount = 0; - new_order.id = uuid::Uuid::new_v4(); - new_order.status = Status::Pending.to_string(); - // CRUD order creation - // We transform the order fields to tags to use in the event - let tags = crate::nip33::order_to_tags(&new_order, None); - - info!("range order tags to be republished: {:#?}", tags); - // nip33 kind with order fields as tags and order id as identifier - let event = crate::nip33::new_event( - my_keys, - "", - new_order.id.to_string(), - tags, - )?; - let event_id = event.id.to_string(); - // We update the order with the new event_id - new_order.event_id = event_id; - new_order.clone().create(&pool).await?; - let _ = NOSTR_CLIENT - .get() - .unwrap() - .send_event(event) - .await - .map(|_s| ()) - .map_err(|err| err.to_string()); - } - // Update order status in case new max is smaller the min amount - Ordering::Less => {} - } - } else { - send_cant_do_msg( - None, - Some(order.id), - Some(CantDoReason::InvalidAmount), - buyer_pubkey, - ) - .await; - send_cant_do_msg( - request_id, - Some(order.id), - Some(CantDoReason::InvalidAmount), - seller_pubkey, - ) - .await; - } - } - } + let (is_range, child_order) = get_child_order(order, request_id, my_keys).await?; + if is_range { + // Let's wait 5 secs before publish this new event + tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; + // We send a message to the order creator with the new order + let creator_pubkey = child_order.creator_pubkey.clone(); + let creator_pubkey = PublicKey::from_str(&creator_pubkey)?; + let new_order = child_order.as_new_order(); + // As we are creating a new order from Mostro to user, we need to ask to the user + // for the trade_pubkey and the last_trade_index to update the user trade_index and order trade_pubkey + send_new_order_msg( + request_id, + Some(order.id), + Action::NewOrder, + Some(Payload::Order(new_order)), + &creator_pubkey, + None, + ) + .await; } - - // Let's wait 5 secs before publish this new event - tokio::time::sleep(tokio::time::Duration::from_secs(5)).await; - // We publish a new replaceable kind nostr event with the status updated - // and update on local database the status and new event id if let Ok(order_updated) = update_order_event(my_keys, Status::Success, order).await { let pool = db::connect().await?; if let Ok(order_success) = order_updated.update(&pool).await { @@ -398,3 +300,143 @@ async fn payment_success( } Ok(()) } + +/// Check if order is range type +/// Add parent range id and update max amount +/// publish a new replaceable kind nostr event with the status updated +/// and update on local database the status and new event id +pub async fn get_child_order( + order: &mut Order, + request_id: Option, + my_keys: &Keys, +) -> Result<(bool, Order)> { + let (Some(max_amount), Some(min_amount)) = (order.max_amount, order.min_amount) else { + return Ok((false, order.clone())); + }; + + if let Some(new_max) = max_amount.checked_sub(order.fiat_amount) { + let mut new_order = create_base_order(order); + + match new_max.cmp(&min_amount) { + Ordering::Equal => { + update_order_for_equal(new_max, &mut new_order, my_keys).await?; + return Ok((true, new_order)); + } + Ordering::Greater => { + update_order_for_greater(new_max, &mut new_order, my_keys).await?; + return Ok((true, new_order)); + } + Ordering::Less => { + notify_invalid_amount(order, request_id).await; + return Ok((false, order.clone())); + } + } + } + + Ok((false, order.clone())) +} + +fn create_base_order(order: &Order) -> Order { + let mut new_order = order.clone(); + new_order.id = uuid::Uuid::new_v4(); + new_order.status = Status::Pending.to_string(); + new_order.amount = 0; + new_order.hash = None; + new_order.preimage = None; + new_order.buyer_invoice = None; + new_order.taken_at = 0; + new_order.invoice_held_at = 0; + new_order.range_parent_id = Some(order.id); + + if new_order.kind == "sell" { + new_order.buyer_pubkey = None; + new_order.master_buyer_pubkey = None; + new_order.trade_index_buyer = None; + } else { + new_order.seller_pubkey = None; + new_order.master_seller_pubkey = None; + new_order.trade_index_seller = None; + } + + new_order +} + +async fn update_order_for_equal(new_max: i64, new_order: &mut Order, my_keys: &Keys) -> Result<()> { + let pool = db::connect().await?; + new_order.fiat_amount = new_max; + new_order.max_amount = None; + new_order.min_amount = None; + + let tags = crate::nip33::order_to_tags(new_order, None); + let event = crate::nip33::new_event(my_keys, "", new_order.id.to_string(), tags)?; + new_order.event_id = event.id.to_string(); + new_order.clone().create(&pool).await?; + NOSTR_CLIENT + .get() + .ok_or_else(|| anyhow::Error::msg("NOSTR_CLIENT not initialized"))? + .send_event(event) + .await + .map_err(|err| anyhow::Error::msg(err.to_string()))?; + + Ok(()) +} + +async fn update_order_for_greater( + new_max: i64, + new_order: &mut Order, + my_keys: &Keys, +) -> Result<()> { + let pool = db::connect().await?; + new_order.max_amount = Some(new_max); + new_order.fiat_amount = 0; + + let tags = crate::nip33::order_to_tags(new_order, None); + let event = crate::nip33::new_event(my_keys, "", new_order.id.to_string(), tags)?; + new_order.event_id = event.id.to_string(); + new_order.clone().create(&pool).await?; + NOSTR_CLIENT + .get() + .ok_or_else(|| anyhow::Error::msg("NOSTR_CLIENT not initialized"))? + .send_event(event) + .await + .map_err(|err| anyhow::Error::msg(err.to_string()))?; + + Ok(()) +} + +async fn notify_invalid_amount(order: &Order, request_id: Option) { + if let (Some(buyer_pubkey), Some(seller_pubkey)) = + (order.buyer_pubkey.as_ref(), order.seller_pubkey.as_ref()) + { + let buyer_pubkey = match PublicKey::from_str(buyer_pubkey) { + Ok(pk) => pk, + Err(e) => { + error!("Failed to parse buyer pubkey: {:?}", e); + return; + } + }; + let seller_pubkey = match PublicKey::from_str(seller_pubkey) { + Ok(pk) => pk, + Err(e) => { + error!("Failed to parse seller pubkey: {:?}", e); + return; + } + }; + + send_cant_do_msg( + None, + Some(order.id), + Some(CantDoReason::InvalidAmount), + &buyer_pubkey, + ) + .await; + + send_cant_do_msg( + request_id, + Some(order.id), + Some(CantDoReason::InvalidAmount), + &seller_pubkey, + ) + .await; + } +} diff --git a/src/app/take_buy.rs b/src/app/take_buy.rs index 5dc7e303..271ea88a 100644 --- a/src/app/take_buy.rs +++ b/src/app/take_buy.rs @@ -1,10 +1,9 @@ use crate::util::{ - get_fiat_amount_requested, get_market_amount_and_fee, send_cant_do_msg, send_new_order_msg, - show_hold_invoice, + get_fiat_amount_requested, get_market_amount_and_fee, send_cant_do_msg, show_hold_invoice, }; use anyhow::{Error, Result}; -use mostro_core::message::{Action, CantDoReason, Message}; +use mostro_core::message::{CantDoReason, Message}; use mostro_core::order::{Kind, Order, Status}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -69,15 +68,14 @@ pub async fn take_buy_action( match order_status { Status::Pending => {} _ => { - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::NotAllowedByStatus, - None, - &seller_pubkey, - None, + Some(CantDoReason::NotAllowedByStatus), + &event.rumor.pubkey, ) .await; + return Ok(()); } } @@ -86,15 +84,14 @@ pub async fn take_buy_action( if let Some(am) = get_fiat_amount_requested(&order, &msg) { order.fiat_amount = am; } else { - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::OutOfRangeFiatAmount, - None, + Some(CantDoReason::OutOfRangeFiatAmount), &event.rumor.pubkey, - None, ) .await; + return Ok(()); } diff --git a/src/app/take_sell.rs b/src/app/take_sell.rs index a5ab1700..24511f44 100644 --- a/src/app/take_sell.rs +++ b/src/app/take_sell.rs @@ -1,11 +1,11 @@ use crate::lightning::invoice::is_valid_invoice; use crate::util::{ - get_fiat_amount_requested, get_market_amount_and_fee, send_cant_do_msg, send_new_order_msg, + get_fiat_amount_requested, get_market_amount_and_fee, send_cant_do_msg, set_waiting_invoice_status, show_hold_invoice, update_order_event, }; use anyhow::{Error, Result}; -use mostro_core::message::{Action, CantDoReason, Message}; +use mostro_core::message::{CantDoReason, Message}; use mostro_core::order::{Kind, Order, Status}; use nostr::nips::nip59::UnwrappedGift; use nostr_sdk::prelude::*; @@ -102,15 +102,14 @@ pub async fn take_sell_action( match order_status { Status::Pending => {} _ => { - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::NotAllowedByStatus, - None, + Some(CantDoReason::NotAllowedByStatus), &buyer_trade_pubkey, - None, ) .await; + return Ok(()); } } @@ -119,15 +118,14 @@ pub async fn take_sell_action( if let Some(am) = get_fiat_amount_requested(&order, &msg) { order.fiat_amount = am; } else { - send_new_order_msg( + send_cant_do_msg( request_id, Some(order.id), - Action::OutOfRangeFiatAmount, - None, + Some(CantDoReason::OutOfRangeFiatAmount), &event.rumor.pubkey, - None, ) .await; + return Ok(()); }