1use clap::arg;
2
3use crate::assembled::Assembled;
4use crate::xdr;
5
6use crate::commands::HEADING_RPC;
7#[cfg(feature = "version_lt_23")]
8use crate::deprecated_arg;
9
10#[cfg(feature = "version_lt_23")]
11const DEPRECATION_MESSAGE: &str = "--sim-only is deprecated and will be removed \
12in the future versions of CLI. The same functionality is offered by `tx simulate` command. To \
13replicate the behaviour, run `stellar <command> --build only | stellar tx simulate`";
14
15#[derive(Debug, clap::Args, Clone)]
16#[group(skip)]
17pub struct Args {
18 #[arg(long, default_value = "100", env = "STELLAR_FEE", help_heading = HEADING_RPC)]
20 pub fee: u32,
21 #[arg(long = "cost", help_heading = HEADING_RPC)]
23 pub cost: bool,
24 #[arg(long, help_heading = HEADING_RPC)]
26 pub instructions: Option<u32>,
27 #[arg(long, help_heading = HEADING_RPC)]
29 pub build_only: bool,
30 #[cfg(feature = "version_lt_23")]
31 #[arg(
33 long,
34 help_heading = HEADING_RPC,
35 conflicts_with = "build_only",
36 display_order = 100,
37 value_parser = deprecated_arg!(bool, DEPRECATION_MESSAGE))
38 ]
39 pub sim_only: bool,
40}
41
42impl Args {
43 pub fn apply_to_assembled_txn(&self, txn: Assembled) -> Assembled {
44 if let Some(instructions) = self.instructions {
45 txn.set_max_instructions(instructions)
46 } else {
47 add_padding_to_instructions(txn)
48 }
49 }
50}
51
52pub fn add_padding_to_instructions(txn: Assembled) -> Assembled {
53 let xdr::TransactionExt::V1(xdr::SorobanTransactionData {
54 resources: xdr::SorobanResources { instructions, .. },
55 ..
56 }) = txn.transaction().ext
57 else {
58 return txn;
59 };
60 let instructions = (instructions.checked_mul(150 / 100)).unwrap_or(instructions);
62 txn.set_max_instructions(instructions)
63}
64
65impl Default for Args {
66 fn default() -> Self {
67 Self {
68 fee: 100,
69 cost: false,
70 instructions: None,
71 build_only: false,
72 #[cfg(feature = "version_lt_23")]
73 sim_only: false,
74 }
75 }
76}