Skip to content

Commit

Permalink
feat: add option for max instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Dec 14, 2023
1 parent e9e6d71 commit bf12cc0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 17 additions & 0 deletions cmd/crates/soroban-rpc/src/txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,

/// Function name as subcommand, then arguments for that function as `--arg-name value`
#[arg(last = true, id = "CONTRACT_FN_AND_ARGS")]
pub slop: Vec<OsString>,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bf12cc0

Please sign in to comment.