leo_lang/cli/commands/query/
transaction.rsuse super::*;
use clap::Parser;
#[derive(Parser, Debug)]
pub struct LeoTransaction {
#[clap(name = "ID", help = "The id of the transaction to fetch", required_unless_present_any = &["from_program", "from_transition", "from_io"])]
pub(crate) id: Option<String>,
#[arg(short, long, help = "Get the transaction only if it has been confirmed", default_value = "false", conflicts_with_all(["from_io", "from_transition", "from_program"]))]
pub(crate) confirmed: bool,
#[arg(value_name = "INPUT_OR_OUTPUT_ID", long, help = "Get the transition id that an input or output id occurred in", conflicts_with_all(["from_program", "from_transition", "confirmed"]))]
pub(crate) from_io: Option<String>,
#[arg(value_name = "TRANSITION_ID", long, help = "Get the id of the transaction containing the specified transition", conflicts_with_all(["from_io", "from_program", "confirmed"]))]
pub(crate) from_transition: Option<String>,
#[arg(value_name = "PROGRAM", long, help = "Get the id of the transaction id that the specified program was deployed in", conflicts_with_all(["from_io", "from_transition", "confirmed"]))]
pub(crate) from_program: Option<String>,
}
impl Command for LeoTransaction {
type Input = ();
type Output = String;
fn log_span(&self) -> Span {
tracing::span!(tracing::Level::INFO, "Leo")
}
fn prelude(&self, _context: Context) -> Result<Self::Input> {
Ok(())
}
fn apply(self, _context: Context, _: Self::Input) -> Result<Self::Output> {
let url = if let Some(io_id) = self.from_io {
let field = is_valid_field(&io_id)?;
format!("find/transitionID/{field}")
} else if let Some(transition) = self.from_transition {
is_valid_transition_id(&transition)?;
format!("find/transactionID/{transition}")
} else if let Some(program) = self.from_program {
format!("find/transactionID/deployment/{}", check_valid_program_name(program))
} else if let Some(id) = self.id {
is_valid_transaction_id(&id)?;
if self.confirmed { format!("transaction/confirmed/{}", id) } else { format!("transaction/{}", id) }
} else {
unreachable!("All command paths covered.")
};
Ok(url)
}
}