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