From c9ed9b2647e4fb6a9dbbb761363e4dc8fa07c4e8 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 13 Dec 2023 11:15:21 -0500 Subject: [PATCH] feat: add option for max instructions --- cmd/crates/soroban-rpc/src/txn.rs | 17 +++++++++++++++++ cmd/soroban-cli/src/commands/contract/invoke.rs | 11 +++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) 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 a4cb0dd94a..de05937e90 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,