use clap::arg;
use soroban_env_host::xdr;
use soroban_rpc::Assembled;
use crate::commands::HEADING_RPC;
#[derive(Debug, clap::Args, Clone)]
#[group(skip)]
pub struct Args {
#[arg(long, default_value = "100", env = "STELLAR_FEE", help_heading = HEADING_RPC)]
pub fee: u32,
#[arg(long = "cost", help_heading = HEADING_RPC)]
pub cost: bool,
#[arg(long, help_heading = HEADING_RPC)]
pub instructions: Option<u32>,
#[arg(long, help_heading = HEADING_RPC)]
pub build_only: bool,
#[arg(long, help_heading = HEADING_RPC, conflicts_with = "build_only")]
pub sim_only: 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 {
add_padding_to_instructions(txn)
}
}
}
pub fn add_padding_to_instructions(txn: Assembled) -> Assembled {
let xdr::TransactionExt::V1(xdr::SorobanTransactionData {
resources: xdr::SorobanResources { instructions, .. },
..
}) = txn.transaction().ext
else {
return txn;
};
let instructions = (instructions.checked_mul(150 / 100)).unwrap_or(instructions);
txn.set_max_instructions(instructions)
}
impl Default for Args {
fn default() -> Self {
Self {
fee: 100,
cost: false,
instructions: None,
build_only: false,
sim_only: false,
}
}
}