mostro_client/cli/
send_msg.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::cli::Commands;
use crate::util::send_order_id_cmd;

use anyhow::Result;
use log::info;
use mostro_core::message::{Action, Message, Payload};
use nostr_sdk::prelude::*;
use std::process;
use uuid::Uuid;

pub async fn execute_send_msg(
    command: Commands,
    order_id: Option<Uuid>,
    identity_keys: Option<&Keys>,
    trade_keys: &Keys,
    mostro_key: PublicKey,
    client: &Client,
    text: Option<&str>,
) -> Result<()> {
    // Get desised action based on command from CLI
    let requested_action = match command {
        Commands::FiatSent { order_id: _ } => Action::FiatSent,
        Commands::Release { order_id: _ } => Action::Release,
        Commands::Cancel { order_id: _ } => Action::Cancel,
        Commands::Dispute { order_id: _ } => Action::Dispute,
        Commands::AdmCancel { order_id: _ } => Action::AdminCancel,
        Commands::AdmSettle { order_id: _ } => Action::AdminSettle,
        Commands::AdmAddSolver { npubkey: _ } => Action::AdminAddSolver,
        _ => {
            println!("Not a valid command!");
            process::exit(0);
        }
    };

    println!(
        "Sending {} command for order {:?} to mostro pubId {}",
        requested_action,
        order_id,
        mostro_key.clone()
    );
    let mut payload = None;
    if let Some(t) = text {
        payload = Some(Payload::TextMessage(t.to_string()));
    }

    // Create message
    let message = Message::new_order(order_id, None, None, requested_action, payload)
        .as_json()
        .unwrap();
    info!("Sending message: {:#?}", message);
    send_order_id_cmd(
        client,
        identity_keys,
        trade_keys,
        mostro_key,
        message,
        false,
        false,
    )
    .await?;

    Ok(())
}