Skip to content

Commit 9b0ecb2

Browse files
committed
fix: correct keys used for send_dm command
1 parent 5236ed6 commit 9b0ecb2

4 files changed

Lines changed: 50 additions & 16 deletions

File tree

src/cli.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use crate::cli::conversation_key::execute_conversation_key;
2222
use crate::cli::dm_to_user::execute_dm_to_user;
2323
use crate::cli::get_dm::execute_get_dm;
2424
use crate::cli::get_dm_user::execute_get_dm_user;
25-
use crate::cli::last_trade_index::execute_last_trade_index;
25+
use crate::cli::last_trade_index::{
26+
execute_last_trade_index, execute_last_trade_index_private_key,
27+
};
2628
use crate::cli::list_disputes::execute_list_disputes;
2729
use crate::cli::list_orders::execute_list_orders;
2830
use crate::cli::new_order::execute_new_order;
@@ -200,9 +202,9 @@ pub enum Commands {
200202
/// Order id
201203
#[arg(short, long)]
202204
order_id: Uuid,
203-
/// Message to send
204-
#[arg(short, long)]
205-
message: String,
205+
/// Message to send (spaces allowed; use quotes or multiple -m/--message)
206+
#[arg(short, long, num_args = 1..)]
207+
message: Vec<String>,
206208
},
207209
/// Send gift wrapped direct message to a user
208210
DmToUser {
@@ -212,9 +214,9 @@ pub enum Commands {
212214
/// Order id to get ephemeral keys
213215
#[arg(short, long)]
214216
order_id: Uuid,
215-
/// Message to send
216-
#[arg(short, long)]
217-
message: String,
217+
/// Message to send (spaces allowed; use quotes or multiple -m/--message)
218+
#[arg(short, long, num_args = 1..)]
219+
message: Vec<String>,
218220
},
219221
/// Send fiat sent message to confirm payment to other user
220222
FiatSent {
@@ -282,9 +284,9 @@ pub enum Commands {
282284
/// Pubkey of the recipient
283285
#[arg(short, long)]
284286
pubkey: String,
285-
/// Message to send
286-
#[arg(short, long)]
287-
message: String,
287+
/// Message to send (spaces allowed; use quotes or multiple -m/--message)
288+
#[arg(short, long, num_args = 1..)]
289+
message: Vec<String>,
288290
},
289291
/// Get the conversation key for direct messaging with a user
290292
ConversationKey {
@@ -294,6 +296,8 @@ pub enum Commands {
294296
},
295297
/// Get last trade index of user
296298
GetLastTradeIndex {},
299+
/// Get private key of last trade index public key
300+
GetLastTradePrivkey {},
297301
/// Request detailed information for specific orders
298302
OrdersInfo {
299303
/// Order IDs to request information for
@@ -460,28 +464,34 @@ impl Commands {
460464
Commands::GetLastTradeIndex {} => {
461465
execute_last_trade_index(&ctx.identity_keys, ctx.mostro_pubkey, ctx).await
462466
}
467+
Commands::GetLastTradePrivkey {} => execute_last_trade_index_private_key(ctx).await,
463468
// DM commands with pubkey parsing
464469
Commands::SendDm {
465470
pubkey,
466471
order_id,
467472
message,
468-
} => execute_send_dm(PublicKey::from_str(pubkey)?, ctx, order_id, message).await,
473+
} => {
474+
let msg = message.join(" ");
475+
execute_send_dm(PublicKey::from_str(pubkey)?, ctx, order_id, &msg).await
476+
}
469477
Commands::DmToUser {
470478
pubkey,
471479
order_id,
472480
message,
473481
} => {
482+
let msg = message.join(" ");
474483
execute_dm_to_user(
475484
PublicKey::from_str(pubkey)?,
476485
&ctx.client,
477486
order_id,
478-
message,
487+
&msg,
479488
&ctx.pool,
480489
)
481490
.await
482491
}
483492
Commands::AdmSendDm { pubkey, message } => {
484-
execute_adm_send_dm(PublicKey::from_str(pubkey)?, ctx, message).await
493+
let msg = message.join(" ");
494+
execute_adm_send_dm(PublicKey::from_str(pubkey)?, ctx, &msg).await
485495
}
486496
Commands::ConversationKey { pubkey } => {
487497
execute_conversation_key(&ctx.trade_keys, PublicKey::from_str(pubkey)?).await

src/cli/last_trade_index.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use nostr_sdk::prelude::*;
44

55
use crate::{
66
cli::Context,
7-
parser::common::{print_key_value, print_section_header},
7+
db::User,
8+
parser::common::{
9+
print_key_value, print_section_header, print_success_message, print_trade_index,
10+
},
811
parser::{dms::print_commands_results, parse_dm_events},
912
util::{send_dm, wait_for_dm},
1013
};
@@ -60,3 +63,24 @@ pub async fn execute_last_trade_index(
6063

6164
Ok(())
6265
}
66+
67+
/// Print the private key corresponding to the last trade index
68+
/// stored locally for this user.
69+
pub async fn execute_last_trade_index_private_key(ctx: &Context) -> Result<()> {
70+
// Get the last known trade index from the local database
71+
let last_trade_index = User::get_last_trade_index(ctx.pool.clone()).await?;
72+
73+
print_section_header("🔑 Last Trade Index Private Key");
74+
print_trade_index(last_trade_index as u64);
75+
76+
// Derive the trade keys for this index from the user's mnemonic
77+
let trade_keys = User::get_trade_keys(&ctx.pool, last_trade_index).await?;
78+
let sk_hex = trade_keys.secret_key().to_secret_hex();
79+
let pk_str = trade_keys.public_key().to_string();
80+
81+
print_key_value("🔐", "Private Key (hex)", &sk_hex);
82+
print_key_value("🔓", "Public Key", &pk_str);
83+
print_success_message("Derived last trade index keypair from local mnemonic.");
84+
85+
Ok(())
86+
}

src/cli/send_dm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub async fn execute_send_dm(
5555

5656
send_dm(
5757
&ctx.client,
58-
None,
58+
Some(&trade_keys),
5959
&trade_keys,
6060
&receiver,
6161
message,

src/util/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn uppercase_first(s: &str) -> String {
1010

1111
pub fn get_mcli_path() -> String {
1212
let home_dir = dirs::home_dir().expect("Couldn't get home directory");
13-
let mcli_path = format!("{}/.mcli", home_dir.display());
13+
let mcli_path = format!("{}/.mcliUserA", home_dir.display());
1414
if !Path::new(&mcli_path).exists() {
1515
match fs::create_dir(&mcli_path) {
1616
Ok(_) => println!("Directory {} created.", mcli_path),

0 commit comments

Comments
 (0)