From fd0f71e02b5bafad0dc5c4dc4068fe088230f162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Calder=C3=B3n?= Date: Wed, 3 May 2023 18:41:57 -0300 Subject: [PATCH] Cancel order by admin support --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/cli.rs | 29 ++++++++++++++++------------- src/cli/send_msg.rs | 6 +++++- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0fe54cd..91fd079 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1130,9 +1130,9 @@ dependencies = [ [[package]] name = "mostro-core" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1012d6da673aab46596b6fa8a1be92b50fd26c900de0183e1ba2d76b99724feb" +checksum = "1321cbbf2a2ae864e9ddd627be429f7639f0586145e95c196ba8328cc5c44ff9" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index ddd16cf..473f4a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,5 +40,5 @@ uuid = { version = "1.3.0", features = [ dotenvy = "0.15.6" lightning-invoice = "0.23.0" reqwest = { version = "0.11", features = ["json"] } -mostro-core = "0.2.4" +mostro-core = "0.2.6" bitcoin_hashes = "0.12.0" diff --git a/src/cli.rs b/src/cli.rs index 6878bd4..c5f7efd 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -7,18 +7,6 @@ pub mod send_msg; pub mod take_buy; pub mod take_sell; -use clap::{Parser, Subcommand}; - -use mostro_core::{Kind, Status}; -use uuid::Uuid; - -use std::env::{set_var, var}; - -use anyhow::Result; - -use nostr_sdk::prelude::FromBech32; -use nostr_sdk::secp256k1::XOnlyPublicKey; - use crate::cli::add_invoice::execute_add_invoice; use crate::cli::get_dm::execute_get_dm; use crate::cli::list_orders::execute_list_orders; @@ -29,6 +17,14 @@ use crate::cli::take_buy::execute_take_buy; use crate::cli::take_sell::execute_take_sell; use crate::util; +use anyhow::Result; +use clap::{Parser, Subcommand}; +use mostro_core::{Kind, Status}; +use nostr_sdk::prelude::FromBech32; +use nostr_sdk::secp256k1::XOnlyPublicKey; +use std::env::{set_var, var}; +use uuid::Uuid; + #[derive(Parser)] #[command( name = "mostro-cli", @@ -157,12 +153,18 @@ pub enum Commands { #[arg(short, long)] rating: u8, }, - /// Send dispute message to start a dispute + /// Start a dispute Dispute { /// Order id number #[arg(short, long)] order_id: Uuid, }, + /// Cancel an order (only admin) + AdminCancel { + /// Order id number + #[arg(short, long)] + order_id: Uuid, + }, } /// Check range simple version for just a single value @@ -212,6 +214,7 @@ pub async fn run() -> Result<()> { Commands::FiatSent { order_id } | Commands::Release { order_id } | Commands::Dispute { order_id } + | Commands::AdminCancel { order_id } | Commands::Cancel { order_id } => { execute_send_msg(cmd.clone(), order_id, &my_key, mostro_key, &client).await? } diff --git a/src/cli/send_msg.rs b/src/cli/send_msg.rs index 1e85703..bc71807 100644 --- a/src/cli/send_msg.rs +++ b/src/cli/send_msg.rs @@ -1,7 +1,9 @@ use crate::cli::Commands; use crate::util::get_keys; use crate::util::send_order_id_cmd; + use anyhow::Result; +use log::info; use mostro_core::Action; use mostro_core::Message as MostroMessage; use nostr_sdk::prelude::ToBech32; @@ -23,6 +25,7 @@ pub async fn execute_send_msg( Commands::Release { order_id: _ } => Action::Release, Commands::Cancel { order_id: _ } => Action::Cancel, Commands::Dispute { order_id: _ } => Action::Dispute, + Commands::AdminCancel { order_id: _ } => Action::AdminCancel, _ => { println!("Not a valid command!"); process::exit(0); @@ -48,7 +51,8 @@ pub async fn execute_send_msg( ) .as_json() .unwrap(); - + info!("Sending message: {}", message); send_order_id_cmd(client, my_key, mostro_key, message, false).await?; + Ok(()) }