use soroban_rpc::GetTransactionResponse;
use crate::assembled::Assembled;
use crate::commands::tx::fetch;
use crate::commands::tx::fetch::fee::FeeTable;
use crate::commands::HEADING_RPC;
#[derive(Debug, clap::Args, Clone, Default)]
#[group(skip)]
pub struct Args {
#[arg(long, env = "STELLAR_RESOURCE_FEE", value_parser = clap::value_parser!(i64).range(0..i64::MAX), help_heading = HEADING_RPC)]
pub resource_fee: Option<i64>,
#[arg(long, help_heading = HEADING_RPC)]
pub instructions: Option<u32>,
#[arg(long, help_heading = HEADING_RPC)]
pub instruction_leeway: Option<u64>,
#[arg(long, help_heading = HEADING_RPC)]
pub cost: bool,
}
impl Args {
pub fn apply_to_assembled_txn(&self, txn: Assembled) -> Assembled {
if let Some(instructions) = self.instructions {
txn.set_max_instructions(instructions)
} else {
txn
}
}
pub fn resource_config(&self) -> Option<soroban_rpc::ResourceConfig> {
self.instruction_leeway
.map(|instruction_leeway| soroban_rpc::ResourceConfig { instruction_leeway })
}
pub fn print_cost_info(&self, res: &GetTransactionResponse) -> Result<(), fetch::Error> {
if !self.cost {
return Ok(());
}
let fee_table = FeeTable::new_from_transaction_response(res)?;
eprint!("{}", fee_table.table());
Ok(())
}
}