mostro_client/util/
storage.rs1use anyhow::Result;
2use mostro_core::prelude::*;
3use nostr_sdk::prelude::*;
4use sqlx::SqlitePool;
5use uuid::Uuid;
6
7use crate::cli::send_msg::execute_send_msg;
8use crate::cli::{Commands, Context};
9use crate::db::{Order, User};
10
11pub async fn save_order(
12 order: SmallOrder,
13 trade_keys: &Keys,
14 request_id: u64,
15 trade_index: i64,
16 pool: &SqlitePool,
17) -> Result<()> {
18 if let Ok(order) = Order::new(pool, order, trade_keys, Some(request_id as i64)).await {
19 if let Some(order_id) = order.id {
20 println!("Order {} created", order_id);
21 } else {
22 println!("Warning: The newly created order has no ID.");
23 }
24
25 match User::get(pool).await {
26 Ok(mut user) => {
27 user.set_last_trade_index(trade_index);
28 if let Err(e) = user.save(pool).await {
29 println!("Failed to update user: {}", e);
30 }
31 }
32 Err(e) => println!("Failed to get user: {}", e),
33 }
34 }
35 Ok(())
36}
37
38pub async fn run_simple_order_msg(
39 command: Commands,
40 order_id: Option<Uuid>,
41 ctx: &Context,
42) -> Result<()> {
43 execute_send_msg(command, order_id, ctx, None).await
44}
45
46pub async fn admin_send_dm(ctx: &Context, msg: String) -> Result<()> {
47 super::messaging::send_dm(
48 &ctx.client,
49 Some(&ctx.context_keys),
50 &ctx.trade_keys,
51 &ctx.mostro_pubkey,
52 msg,
53 None,
54 false,
55 )
56 .await?;
57 Ok(())
58}