mostro_client/cli/
dm_to_user.rs

1use crate::{db::Order, util::send_gift_wrap_dm};
2use anyhow::Result;
3use nostr_sdk::prelude::*;
4use sqlx::SqlitePool;
5use uuid::Uuid;
6
7pub async fn execute_dm_to_user(
8    receiver: PublicKey,
9    client: &Client,
10    order_id: &Uuid,
11    message: &str,
12    pool: &SqlitePool,
13) -> Result<()> {
14    // Get the order
15    let order = Order::get_by_id(pool, &order_id.to_string())
16        .await
17        .map_err(|_| anyhow::anyhow!("order {} not found", order_id))?;
18    // Get the trade keys
19    let trade_keys = match order.trade_keys.as_ref() {
20        Some(trade_keys) => Keys::parse(trade_keys)?,
21        None => anyhow::bail!("No trade_keys found for this order"),
22    };
23
24    // Send the DM
25    println!(
26        "SENDING DM with trade keys: {}",
27        trade_keys.public_key().to_hex()
28    );
29
30    send_gift_wrap_dm(client, &trade_keys, &receiver, message).await?;
31
32    Ok(())
33}