Skip to content

Commit

Permalink
Add clear_tx_verify_queue subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <[email protected]>
  • Loading branch information
eval-exec committed Sep 12, 2024
1 parent cbd911b commit d616aaa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/subcommands/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")?;

Expand Down
17 changes: 8 additions & 9 deletions src/utils/completer.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -31,21 +30,21 @@ static ESCAPE_CHAR: Option<char> = None;

#[derive(Helper)]
pub struct CkbCompleter<'a> {
clap_app: Arc<clap::App<'a>>,
clap_app: clap::App<'a>,
completer: FilenameCompleter,
validator: MatchingBracketValidator,
}

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<clap::App<'a>>, args: &[String]) -> Vec<(String, String)> {
pub fn get_completions(app: &clap::App<'a>, args: &[String]) -> Vec<(String, String)> {
let args_set = args.iter().collect::<HashSet<&String>>();
let switched_completions =
|short: Option<char>, long: Option<&str>, multiple: bool, required: bool| {
Expand Down Expand Up @@ -95,18 +94,18 @@ impl<'a> CkbCompleter<'a> {
}

pub fn find_subcommand<'s, Iter: iter::Iterator<Item = &'s str>>(
app: Arc<clap::App<'a>>,
app: clap::App<'a>,
mut prefix_names: iter::Peekable<Iter>,
) -> Option<Arc<clap::App<'a>>> {
) -> Option<clap::App<'a>> {
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)
};
}
}
Expand All @@ -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(&current_app, &args))
Expand Down
7 changes: 7 additions & 0 deletions src/utils/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d616aaa

Please sign in to comment.