From 826b3a8a2be1b9ba8f436b76f263e8c537eabca3 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Wed, 11 Sep 2024 15:11:36 +0800 Subject: [PATCH] Add clear_tx_verify_queue subcommand Signed-off-by: Eval EXEC --- src/subcommands/rpc.rs | 13 +++++++++++++ src/utils/completer.rs | 17 ++++++++--------- src/utils/rpc/client.rs | 7 +++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/subcommands/rpc.rs b/src/subcommands/rpc.rs index e6455b28..8313160d 100644 --- a/src/subcommands/rpc.rs +++ b/src/subcommands/rpc.rs @@ -305,6 +305,7 @@ impl<'a> RpcSubCommand<'a> { .about("Hash of a transaction"), ), App::new("tx_pool_info").about("Get transaction pool information"), + App::new("clear_tx_verify_queue").about("Clear TxPool verify_queue"), App::new("test_tx_pool_accept") .about("Test if transaction can be accepted by Tx Pool") .arg( @@ -1095,6 +1096,18 @@ impl<'a> CliSubCommand for RpcSubCommand<'a> { Ok(Output::new_output(resp)) } } + ("clear_tx_verify_queue", Some(m)) => { + let is_raw_data = is_raw_data || m.is_present("raw-data"); + if is_raw_data { + self.raw_rpc_client + .clear_tx_verify_queue() + .map_err(|err| err.to_string())?; + Ok(Output::new_output(())) + } else { + let _ = self.rpc_client.clear_tx_verify_queue(); + Ok(Output::new_output(())) + } + } ("test_tx_pool_accept", Some(m)) => { let tx_file: PathBuf = FilePathParser::new(false).from_matches(m, "tx-file")?; diff --git a/src/utils/completer.rs b/src/utils/completer.rs index 51757e86..c31e2366 100644 --- a/src/utils/completer.rs +++ b/src/utils/completer.rs @@ -1,7 +1,6 @@ use std::borrow::Cow::{self, Owned}; use std::collections::HashSet; use std::iter; -use std::sync::Arc; use ansi_term::Colour::{Green, Red}; use rustyline::completion::{extract_word, Completer, FilenameCompleter, Pair}; @@ -31,7 +30,7 @@ static ESCAPE_CHAR: Option = None; #[derive(Helper)] pub struct CkbCompleter<'a> { - clap_app: Arc>, + clap_app: clap::App<'a>, completer: FilenameCompleter, validator: MatchingBracketValidator, } @@ -39,13 +38,13 @@ pub struct CkbCompleter<'a> { impl<'a> CkbCompleter<'a> { pub fn new(clap_app: clap::App<'a>) -> Self { CkbCompleter { - clap_app: Arc::new(clap_app), + clap_app, completer: FilenameCompleter::new(), validator: MatchingBracketValidator::new(), } } - pub fn get_completions(app: &Arc>, args: &[String]) -> Vec<(String, String)> { + pub fn get_completions(app: &clap::App<'a>, args: &[String]) -> Vec<(String, String)> { let args_set = args.iter().collect::>(); let switched_completions = |short: Option, long: Option<&str>, multiple: bool, required: bool| { @@ -95,18 +94,18 @@ impl<'a> CkbCompleter<'a> { } pub fn find_subcommand<'s, Iter: iter::Iterator>( - app: Arc>, + app: clap::App<'a>, mut prefix_names: iter::Peekable, - ) -> Option>> { + ) -> Option> { if let Some(name) = prefix_names.next() { for inner_app in app.get_subcommands().iter() { if inner_app.get_name() == name || inner_app.get_all_aliases().any(|alias| alias == name) { return if prefix_names.peek().is_none() { - Some(Arc::new(inner_app.to_owned())) + Some(inner_app.to_owned()) } else { - Self::find_subcommand(Arc::new(inner_app.to_owned()), prefix_names) + Self::find_subcommand(inner_app.to_owned(), prefix_names) }; } } @@ -132,7 +131,7 @@ impl<'a> Completer for CkbCompleter<'a> { let args = shell_words::split(&line[..pos]).unwrap(); let word_lower = word.to_lowercase(); let tmp_pair = Self::find_subcommand( - Arc::clone(&self.clap_app), + self.clap_app.to_owned(), args.iter().map(String::as_str).peekable(), ) .map(|current_app| Self::get_completions(¤t_app, &args)) diff --git a/src/utils/rpc/client.rs b/src/utils/rpc/client.rs index 7ac26222..bdd19f44 100644 --- a/src/utils/rpc/client.rs +++ b/src/utils/rpc/client.rs @@ -376,6 +376,13 @@ impl HttpRpcClient { .map(Into::into) .map_err(|err| err.to_string()) } + pub fn clear_tx_verify_queue(&mut self) -> Result<(), String> { + self.client + .clear_tx_verify_queue() + .map(Into::into) + .map_err(|err| err.to_string()) + } + pub fn test_tx_pool_accept( &mut self, tx: packed::Transaction,