From 3fb9d57acf05aa059e25995d7443e30d8ec824cc Mon Sep 17 00:00:00 2001 From: Arkanoider Date: Sun, 12 Mar 2023 23:10:28 +0100 Subject: [PATCH 1/3] New management of takesell --- src/main.rs | 8 ++++---- src/types.rs | 1 + src/util.rs | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index e82186c..b859adc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,7 +102,7 @@ async fn main() -> Result<()> { match valid_invoice { Ok(_) => { - send_order_id_cmd(&client, &my_key, mostro_key, takesell_message).await?; + send_order_id_cmd(&client, &my_key, mostro_key, takesell_message, true).await?; std::process::exit(0); } Err(e) => println!("{}", e), @@ -122,7 +122,7 @@ async fn main() -> Result<()> { .as_json() .unwrap(); - send_order_id_cmd(&client, &my_key, mostro_key, takebuy_message).await?; + send_order_id_cmd(&client, &my_key, mostro_key, takebuy_message, false).await?; std::process::exit(0); } Some(cli::Commands::GetDm { since }) => { @@ -158,7 +158,7 @@ async fn main() -> Result<()> { .as_json() .unwrap(); - send_order_id_cmd(&client, &my_key, mostro_key, message).await?; + send_order_id_cmd(&client, &my_key, mostro_key, message, false).await?; std::process::exit(0); } Some(cli::Commands::Neworder { @@ -214,7 +214,7 @@ async fn main() -> Result<()> { .as_json() .unwrap(); - send_order_id_cmd(&client, &my_key, mostro_key, message).await?; + send_order_id_cmd(&client, &my_key, mostro_key, message, false).await?; std::process::exit(0); } None => {} diff --git a/src/types.rs b/src/types.rs index d591df5..cb2a667 100644 --- a/src/types.rs +++ b/src/types.rs @@ -100,6 +100,7 @@ pub struct Message { pub enum Content { Order(Order), PaymentRequest(String), + PayHoldInvoice(Order, String), } #[allow(dead_code)] diff --git a/src/util.rs b/src/util.rs index 002cf9e..d28de36 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,6 @@ +use crate::types::Content; use crate::types::Kind as Orderkind; +use crate::types::Message; use crate::types::Order; use crate::types::Status; use anyhow::{Error, Result}; @@ -30,7 +32,7 @@ pub async fn send_dm( info!("Sending event: {event:#?}"); // This will update relay send event to wait for tranmission. if let Some(_wait_mes) = wait_for_connection { - let opts = Options::new().wait_for_send(true); + let opts = Options::new().wait_for_send(false); client.update_opts(opts); } client.send_event(event).await?; @@ -71,7 +73,7 @@ pub async fn connect_nostr() -> Result { for r in relays.into_iter() { client.add_relay(r, None).await?; } - let opts = Options::new().wait_for_connection(true); + let opts = Options::new().wait_for_connection(false); client.update_opts(opts); // Connect to relays and keep connection alive @@ -85,14 +87,39 @@ pub async fn send_order_id_cmd( my_key: &Keys, mostro_pubkey: XOnlyPublicKey, message: String, + wait_for_dm_ans: bool, ) -> Result<()> { // Send dm to mostro pub id - send_dm(client, my_key, &mostro_pubkey, message, Some(true)).await?; + send_dm(client, my_key, &mostro_pubkey, message, Some(false)).await?; let mut notifications = client.notifications(); while let Ok(notification) = notifications.recv().await { - if let RelayPoolNotification::Message( + if wait_for_dm_ans { + let dm = get_direct_messages(client, mostro_pubkey, my_key, 1).await; + + for el in dm.iter() { + match Message::from_json(&el.0) { + Ok(m) => { + if let Some(Content::PayHoldInvoice(ord, inv)) = m.content { + println!("NEW MESSAGE:"); + println!( + "Mostro sent you this hold invoice for order id: {}", + ord.id.unwrap() + ); + println!(); + println!("Copy this string --> {}", inv); + println!(); + println!(); + } + } + Err(_) => { + println!("Mostro sent you this message --> {}", el.0); + } + } + } + break; + } else if let RelayPoolNotification::Message( _, RelayMessage::Ok { event_id: _, From cb6f91222a5baeda0237d0e2aab9dc714ee12d48 Mon Sep 17 00:00:00 2001 From: Arkanoider Date: Sun, 12 Mar 2023 23:24:44 +0100 Subject: [PATCH 2/3] Small typo fix --- src/util.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util.rs b/src/util.rs index d28de36..7b57ae9 100644 --- a/src/util.rs +++ b/src/util.rs @@ -109,12 +109,13 @@ pub async fn send_order_id_cmd( ); println!(); println!("Copy this string --> {}", inv); - println!(); - println!(); + println!();println!(); } } Err(_) => { + println!("NEW MESSAGE:"); println!("Mostro sent you this message --> {}", el.0); + println!();println!(); } } } From b030e80185b9d29f1f83793252a57e3d0e871f11 Mon Sep 17 00:00:00 2001 From: Arkanoider Date: Sun, 12 Mar 2023 23:39:16 +0100 Subject: [PATCH 3/3] small fix on comment string --- src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index 7b57ae9..916ebd7 100644 --- a/src/util.rs +++ b/src/util.rs @@ -108,7 +108,7 @@ pub async fn send_order_id_cmd( ord.id.unwrap() ); println!(); - println!("Copy this string --> {}", inv); + println!("Pay this invoice --> {}", inv); println!();println!(); } }