Skip to content

Commit

Permalink
feat: return with xdr if --build-only for all commands that build tra…
Browse files Browse the repository at this point in the history
…nsactions
  • Loading branch information
willemneal authored and gitbutler-client committed Mar 20, 2024
1 parent dc2e10d commit 616d669
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl NetworkRunnable for Cmd {
network_passphrase,
&key,
)?;
self.fee.exit_if_build_only(&tx)?;
let txn = client.create_assembled_transaction(&tx).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
client
Expand Down
5 changes: 4 additions & 1 deletion cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ 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();
fee.build_only = false;
let hash = install::Cmd {
wasm: wasm::Args { wasm: wasm.clone() },
config: config.clone(),
fee: self.fee.clone(),
fee,
ignore_checks: self.ignore_checks,
}
.run_against_rpc_server(global_args, Some(config))
Expand Down Expand Up @@ -164,6 +166,7 @@ impl NetworkRunnable for Cmd {
salt,
&key,
)?;
self.fee.exit_if_build_only(&txn)?;
let txn = client.create_assembled_transaction(&txn).await?;
let txn = self.fee.apply_to_assembled_txn(txn);
client
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl NetworkRunnable for Cmd {
resource_fee: 0,
}),
};

self.fee.exit_if_build_only(&tx)?;
let res = client
.prepare_and_send_transaction(&tx, &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 @@ -119,13 +119,13 @@ impl NetworkRunnable for Cmd {
let (tx_without_preflight, hash) =
build_install_contract_code_tx(&contract, sequence + 1, self.fee.fee, &key)?;

self.fee.exit_if_build_only(&tx_without_preflight)?;
let code_key =
xdr::LedgerKey::ContractCode(xdr::LedgerKeyContractCode { hash: hash.clone() });
let contract_data = client.get_ledger_entries(&[code_key]).await?;
if !contract_data.entries.unwrap_or_default().is_empty() {
return Ok(hash);
}

let txn = client
.create_assembled_transaction(&tx_without_preflight)
.await?;
Expand Down
1 change: 1 addition & 0 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ impl NetworkRunnable for Cmd {
self.fee.fee,
&key,
)?;
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 (return_value, events) = if self.is_view() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl NetworkRunnable for Cmd {
resource_fee: 0,
}),
};

self.fee.exit_if_build_only(&tx)?;
let res = client
.prepare_and_send_transaction(&tx, &key, &[], &network.network_passphrase, None, None)
.await?;
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub struct Args {
pub instructions: Option<u32>,
/// Build the transaction only write the output to stdout
#[arg(long, help_heading = HEADING_RPC)]
build_only: bool,
pub build_only: bool,
}

impl Args {
pub fn build_only(&self, txn: &xdr::Transaction) -> Result<(), xdr::Error> {
pub fn exit_if_build_only(&self, txn: &xdr::Transaction) -> Result<(), xdr::Error> {
if self.build_only {
println!("{}", txn.to_xdr_base64(xdr::Limits::none())?);
std::process::exit(0);
Expand Down
28 changes: 28 additions & 0 deletions docs/soroban-cli-full-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ 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

Possible values: `true`, `false`




Expand Down Expand Up @@ -730,6 +734,10 @@ 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

Possible values: `true`, `false`




Expand Down Expand Up @@ -762,6 +770,10 @@ 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

Possible values: `true`, `false`

* `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts

Default value: `false`
Expand Down Expand Up @@ -926,6 +938,10 @@ 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

Possible values: `true`, `false`

* `--wasm <WASM>` — Path to wasm binary
* `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts

Expand Down Expand Up @@ -975,6 +991,10 @@ 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

Possible values: `true`, `false`




Expand Down Expand Up @@ -1087,6 +1107,10 @@ 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

Possible values: `true`, `false`




Expand Down Expand Up @@ -1376,6 +1400,10 @@ 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

Possible values: `true`, `false`




Expand Down

0 comments on commit 616d669

Please sign in to comment.