Skip to main content

soroban_cli/
resources.rs

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    /// Set the fee for smart contract resource consumption, in stroops. 1 stroop = 0.0000001 xlm. Overrides the simulated resource fee
12    #[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    /// ⚠️ Deprecated, use `--instruction-leeway` to increase instructions. Number of instructions to allocate for the transaction
15    #[arg(long, help_heading = HEADING_RPC)]
16    pub instructions: Option<u32>,
17    /// Allow this many extra instructions when budgeting resources with transaction simulation
18    #[arg(long, help_heading = HEADING_RPC)]
19    pub instruction_leeway: Option<u64>,
20    /// Output the cost execution to stderr
21    #[arg(long, help_heading = HEADING_RPC)]
22    pub cost: bool,
23}
24
25impl Args {
26    // TODO: Remove once `--instructions` is fully removed
27    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}