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 Jan 11, 2024
1 parent dc01a01 commit 19e64a8
Show file tree
Hide file tree
Showing 3 changed files with 27 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
1 change: 1 addition & 0 deletions docs/soroban-cli-full-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ soroban contract invoke ... -- --help

* `--id <CONTRACT_ID>` — Contract ID to invoke
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
Expand Down

0 comments on commit 19e64a8

Please sign in to comment.