Skip to content

Commit

Permalink
feat: add sim_only to print assembled transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal authored and gitbutler-client committed Mar 20, 2024
1 parent 616d669 commit 398a018
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl NetworkRunnable for Cmd {
)?;
self.fee.exit_if_build_only(&tx)?;
let txn = client.create_assembled_transaction(&tx).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
let txn = self.fee.apply_to_assembled_txn(txn)?;
client
.send_assembled_transaction(txn, &key, &[], network_passphrase, None, None)
.await?;
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl NetworkRunnable for Cmd {
) -> Result<String, Error> {
let config = config.unwrap_or(&self.config);
let wasm_hash = if let Some(wasm) = &self.wasm {
let mut fee = self.fee.clone();
let mut fee = self.fee.clone();
fee.build_only = false;
let hash = install::Cmd {
wasm: wasm::Args { wasm: wasm.clone() },
Expand Down Expand Up @@ -168,7 +168,7 @@ impl NetworkRunnable for Cmd {
)?;
self.fee.exit_if_build_only(&txn)?;
let txn = client.create_assembled_transaction(&txn).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
let txn = self.fee.apply_to_assembled_txn(txn)?;
client
.send_assembled_transaction(txn, &key, &[], &network.network_passphrase, None, None)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl NetworkRunnable for Cmd {
let txn = client
.create_assembled_transaction(&tx_without_preflight)
.await?;
let txn = self.fee.apply_to_assembled_txn(txn);
let txn = self.fee.apply_to_assembled_txn(txn)?;

// Currently internal errors are not returned if the contract code is expired
if let Some(TransactionResult {
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl NetworkRunnable for Cmd {
)?;
self.fee.exit_if_build_only(&tx)?;
let txn = client.create_assembled_transaction(&tx).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
let txn = self.fee.apply_to_assembled_txn(txn)?;
let (return_value, events) = if self.is_view() {
(
txn.sim_response().results()?[0].xdr.clone(),
Expand Down
20 changes: 17 additions & 3 deletions cmd/soroban-cli/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ pub struct Args {
/// Number of instructions to simulate
#[arg(long, help_heading = HEADING_RPC)]
pub instructions: Option<u32>,
/// Build the transaction only write the output to stdout
/// Build the transaction only write the base64 xdr to stdout
#[arg(long, help_heading = HEADING_RPC)]
pub build_only: bool,
/// Simulation the transaction only write the base64 to stdout
#[arg(long, help_heading = HEADING_RPC, conflicts_with = "build_only")]
pub sim_only: bool,
}

impl Args {
Expand All @@ -31,12 +34,22 @@ impl Args {
Ok(())
}

pub fn apply_to_assembled_txn(&self, txn: Assembled) -> Assembled {
if let Some(instructions) = self.instructions {
pub fn apply_to_assembled_txn(&self, txn: Assembled) -> Result<Assembled, xdr::Error> {
let simulated_txn = if let Some(instructions) = self.instructions {
txn.set_max_instructions(instructions)
} else {
add_padding_to_instructions(txn)
};
if self.sim_only {
println!(
"{}",
simulated_txn
.transaction()
.to_xdr_base64(xdr::Limits::none())?
);
std::process::exit(0);
}
Ok(simulated_txn)
}
}

Expand All @@ -60,6 +73,7 @@ impl Default for Args {
cost: false,
instructions: None,
build_only: false,
sim_only: false,
}
}
}
42 changes: 35 additions & 7 deletions docs/soroban-cli-full-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,11 @@ Deploy builtin Soroban Asset Contract
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the output to stdout
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 to stdout

Possible values: `true`, `false`

Expand Down Expand Up @@ -734,7 +738,11 @@ If no keys are specified the contract itself is extended.
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the output to stdout
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 to stdout

Possible values: `true`, `false`

Expand Down Expand Up @@ -770,7 +778,11 @@ Deploy a wasm contract
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the output to stdout
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 to stdout

Possible values: `true`, `false`

Expand Down Expand Up @@ -938,7 +950,11 @@ Install a WASM file to the ledger without creating a contract instance
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the output to stdout
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 to stdout

Possible values: `true`, `false`

Expand Down Expand Up @@ -991,7 +1007,11 @@ soroban contract invoke ... -- --help
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the output to stdout
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 to stdout

Possible values: `true`, `false`

Expand Down Expand Up @@ -1107,7 +1127,11 @@ If no keys are specificed the contract itself is restored.
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the output to stdout
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 to stdout

Possible values: `true`, `false`

Expand Down Expand Up @@ -1400,7 +1424,11 @@ Deploy a token contract to wrap an existing Stellar classic asset for smart cont
Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction only write the output to stdout
* `--build-only` — Build the transaction only write the base64 xdr to stdout

Possible values: `true`, `false`

* `--sim-only` — Simulation the transaction only write the base64 to stdout

Possible values: `true`, `false`

Expand Down

0 comments on commit 398a018

Please sign in to comment.