diff --git a/cmd/crates/soroban-rpc/src/txn.rs b/cmd/crates/soroban-rpc/src/txn.rs index 7f94919b1d..41cb43d399 100644 --- a/cmd/crates/soroban-rpc/src/txn.rs +++ b/cmd/crates/soroban-rpc/src/txn.rs @@ -178,6 +178,23 @@ impl Assembled { }; !self.requires_auth() } + + #[must_use] + pub fn set_max_instructions(mut self, instructions: u32) -> Self { + if let TransactionExt::V1(SorobanTransactionData { + resources: + SorobanResources { + instructions: ref mut i, + .. + }, + .. + }) = &mut self.txn.ext + { + tracing::trace!("setting max instructions to {instructions} from {i}"); + *i = instructions; + } + self + } } // Apply the result of a simulateTransaction onto a transaction envelope, preparing it for diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index 393bdf0d4a..80b8e0402f 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -45,6 +45,11 @@ pub struct Cmd { /// Output the cost execution to stderr #[arg(long = "cost")] pub cost: bool, + + /// Number of instructions to simulate + #[arg(long)] + pub instructions: Option, + /// Function name as subcommand, then arguments for that function as `--arg-name value` #[arg(last = true, id = "CONTRACT_FN_AND_ARGS")] pub slop: Vec, @@ -296,14 +301,16 @@ impl Cmd { &key, )?; - let txn = client.create_assembled_transaction(&tx).await?; - + let mut txn = client.create_assembled_transaction(&tx).await?; let (return_value, events) = if txn.is_view() { ( txn.sim_res().results()?[0].xdr.clone(), txn.sim_res().events()?, ) } else { + if let Some(instructions) = self.instructions { + txn = txn.set_max_instructions(instructions); + } let res = client .send_assembled_transaction( txn, diff --git a/docs/soroban-cli-full-docs.md b/docs/soroban-cli-full-docs.md index 259aaa6939..424d5b5b41 100644 --- a/docs/soroban-cli-full-docs.md +++ b/docs/soroban-cli-full-docs.md @@ -383,6 +383,7 @@ soroban contract invoke ... -- --help * `--id ` — Contract ID to invoke * `--cost` — Output the cost execution to stderr +* `--instructions ` — Number of instructions to simulate * `--rpc-url ` — RPC server endpoint * `--network-passphrase ` — Network passphrase to sign the transaction sent to the rpc server * `--network ` — Name of network to use from config