1use std::io::stderr;
2
3use soroban_rpc::GetTransactionResponse;
4
5use crate::assembled::Assembled;
6use crate::commands::tx::fetch;
7use crate::commands::tx::fetch::fee::FeeTable;
8use crate::commands::HEADING_RPC;
9
10#[derive(Debug, clap::Args, Clone, Default)]
11#[group(skip)]
12pub struct Args {
13 #[arg(long, env = "STELLAR_RESOURCE_FEE", value_parser = clap::value_parser!(i64).range(0..u32::MAX.into()), help_heading = HEADING_RPC)]
15 pub resource_fee: Option<i64>,
16 #[arg(long, help_heading = HEADING_RPC)]
18 pub instructions: Option<u32>,
19 #[arg(long, help_heading = HEADING_RPC)]
21 pub instruction_leeway: Option<u64>,
22 #[arg(long, help_heading = HEADING_RPC)]
24 pub cost: bool,
25}
26
27impl Args {
28 pub fn apply_to_assembled_txn(&self, txn: Assembled) -> Assembled {
30 if let Some(instructions) = self.instructions {
31 txn.set_max_instructions(instructions)
32 } else {
33 txn
34 }
35 }
36
37 pub fn resource_config(&self) -> Option<soroban_rpc::ResourceConfig> {
38 self.instruction_leeway
39 .map(|instruction_leeway| soroban_rpc::ResourceConfig { instruction_leeway })
40 }
41
42 pub fn print_cost_info(&self, res: &GetTransactionResponse) -> Result<(), fetch::Error> {
43 if !self.cost {
44 return Ok(());
45 }
46
47 let fee_table = FeeTable::new_from_transaction_response(res)?;
48
49 fee_table.table().print(&mut stderr())?;
50
51 Ok(())
52 }
53}