leo_lang/cli/commands/query/
mempool.rs

1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use super::*;
18
19use crate::cli::context::Context;
20use clap::Parser;
21
22// Query transactions and transmissions from the memory pool.
23#[derive(Parser, Debug)]
24pub struct LeoMempool {
25    #[arg(
26        long,
27        help = "Get the memory pool transactions",
28        default_value = "false",
29        required_unless_present = "transmissions",
30        conflicts_with("transmissions")
31    )]
32    pub(crate) transactions: bool,
33    #[arg(
34        long,
35        help = "Get the memory pool transmissions",
36        default_value = "false",
37        required_unless_present = "transactions",
38        conflicts_with("transactions")
39    )]
40    pub(crate) transmissions: bool,
41}
42
43impl Command for LeoMempool {
44    type Input = ();
45    type Output = String;
46
47    fn log_span(&self) -> Span {
48        tracing::span!(tracing::Level::INFO, "Leo")
49    }
50
51    fn prelude(&self, _context: Context) -> Result<Self::Input> {
52        Ok(())
53    }
54
55    fn apply(self, _context: Context, _input: Self::Input) -> Result<Self::Output> {
56        // Build custom url to fetch from based on the flags and user's input.
57        let url = if self.transactions {
58            "memoryPool/transactions".to_string()
59        } else if self.transmissions {
60            "memoryPool/transmissions".to_string()
61        } else {
62            unreachable!("All cases are covered")
63        };
64
65        Ok(url)
66    }
67}