diff --git a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs index c10bf8164..173e9b06f 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs @@ -90,9 +90,10 @@ impl Cmd { network_passphrase, &key, )?; - + let txn = client.create_assembled_transaction(&tx).await?; + let txn = self.fee.apply_to_assembled_txn(txn); client - .prepare_and_send_transaction(&tx, &key, &[], network_passphrase, None, None) + .send_assembled_transaction(txn, &key, &[], network_passphrase, None, None) .await?; Ok(stellar_strkey::Contract(contract_id.0).to_string()) diff --git a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs index 76c130173..0797ac175 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs @@ -147,7 +147,7 @@ impl Cmd { let account_details = client.get_account(&public_strkey).await?; let sequence: i64 = account_details.seq_num.into(); - let (tx, contract_id) = build_create_contract_tx( + let (txn, contract_id) = build_create_contract_tx( wasm_hash, sequence + 1, self.fee.fee, @@ -155,8 +155,10 @@ impl Cmd { salt, &key, )?; + let txn = client.create_assembled_transaction(&txn).await?; + let txn = self.fee.apply_to_assembled_txn(txn); client - .prepare_and_send_transaction(&tx, &key, &[], &network.network_passphrase, None, None) + .send_assembled_transaction(txn, &key, &[], &network.network_passphrase, None, None) .await?; Ok(stellar_strkey::Contract(contract_id.0).to_string()) } diff --git a/cmd/soroban-cli/src/commands/contract/extend.rs b/cmd/soroban-cli/src/commands/contract/extend.rs index 86ea23b55..965eae4fe 100644 --- a/cmd/soroban-cli/src/commands/contract/extend.rs +++ b/cmd/soroban-cli/src/commands/contract/extend.rs @@ -136,7 +136,7 @@ impl Cmd { read_only: keys.clone().try_into()?, read_write: vec![].try_into()?, }, - instructions: 0, + instructions: self.fee.instructions.unwrap_or_default(), read_bytes: 0, write_bytes: 0, }, diff --git a/cmd/soroban-cli/src/commands/contract/install.rs b/cmd/soroban-cli/src/commands/contract/install.rs index c2fa6d889..21743a6ee 100644 --- a/cmd/soroban-cli/src/commands/contract/install.rs +++ b/cmd/soroban-cli/src/commands/contract/install.rs @@ -111,19 +111,17 @@ impl Cmd { let (tx_without_preflight, hash) = build_install_contract_code_tx(contract, sequence + 1, self.fee.fee, &key)?; + let txn = client + .create_assembled_transaction(&tx_without_preflight) + .await?; + 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 { result: TransactionResultResult::TxInternalError, .. }) = client - .prepare_and_send_transaction( - &tx_without_preflight, - &key, - &[], - &network.network_passphrase, - None, - None, - ) + .send_assembled_transaction(txn, &key, &[], &network.network_passphrase, None, None) .await? .result .as_ref() diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index 720c3c6f8..c8692eca0 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -41,12 +41,6 @@ pub struct Cmd { // For testing only #[arg(skip)] pub wasm: Option, - /// Output the cost execution to stderr - #[arg(long = "cost")] - pub cost: bool, - /// Number of instructions to simulate - #[arg(long)] - pub instructions: Option, /// Do not sign and submit transaction #[arg(long, env = "SOROBAN_INVOKE_SIGN", env = "SYSTEM_TEST_VERBOSE_OUTPUT")] pub is_view: bool, @@ -300,10 +294,8 @@ impl Cmd { self.fee.fee, &key, )?; - let mut txn = client.create_assembled_transaction(&tx).await?; - if let Some(instructions) = self.instructions { - txn = txn.set_max_instructions(instructions); - } + 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 { ( txn.sim_response().results()?[0].xdr.clone(), @@ -317,7 +309,7 @@ impl Cmd { &signers, &network.network_passphrase, Some(log_events), - (global_args.verbose || global_args.very_verbose || self.cost) + (global_args.verbose || global_args.very_verbose || self.fee.cost) .then_some(log_resources), ) .await?; diff --git a/cmd/soroban-cli/src/commands/contract/restore.rs b/cmd/soroban-cli/src/commands/contract/restore.rs index 6ed39f892..1385068cc 100644 --- a/cmd/soroban-cli/src/commands/contract/restore.rs +++ b/cmd/soroban-cli/src/commands/contract/restore.rs @@ -140,7 +140,7 @@ impl Cmd { read_only: vec![].try_into()?, read_write: entry_keys.try_into()?, }, - instructions: 0, + instructions: self.fee.instructions.unwrap_or_default(), read_bytes: 0, write_bytes: 0, }, diff --git a/cmd/soroban-cli/src/fee.rs b/cmd/soroban-cli/src/fee.rs index ee8b9614a..70f427bb9 100644 --- a/cmd/soroban-cli/src/fee.rs +++ b/cmd/soroban-cli/src/fee.rs @@ -1,5 +1,7 @@ -use crate::commands::HEADING_RPC; use clap::arg; +use soroban_rpc::Assembled; + +use crate::commands::HEADING_RPC; #[derive(Debug, clap::Args, Clone)] #[group(skip)] @@ -7,10 +9,30 @@ pub struct Args { /// fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm #[arg(long, default_value = "100", env = "SOROBAN_FEE", help_heading = HEADING_RPC)] pub fee: u32, + /// Output the cost execution to stderr + #[arg(long = "cost", help_heading = HEADING_RPC)] + pub cost: bool, + /// Number of instructions to simulate + #[arg(long, help_heading = HEADING_RPC)] + pub instructions: Option, +} + +impl Args { + pub fn apply_to_assembled_txn(&self, txn: Assembled) -> Assembled { + if let Some(instructions) = self.instructions { + txn.set_max_instructions(instructions) + } else { + txn + } + } } impl Default for Args { fn default() -> Self { - Self { fee: 100 } + Self { + fee: 100, + cost: false, + instructions: None, + } } } diff --git a/docs/soroban-cli-full-docs.md b/docs/soroban-cli-full-docs.md index 578d2ac40..4f6d8cd34 100644 --- a/docs/soroban-cli-full-docs.md +++ b/docs/soroban-cli-full-docs.md @@ -518,6 +518,11 @@ Deploy builtin Soroban Asset Contract * `--fee ` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm Default value: `100` +* `--cost` — Output the cost execution to stderr + + Possible values: `true`, `false` + +* `--instructions ` — Number of instructions to simulate @@ -664,6 +669,11 @@ If no keys are specified the contract itself is extended. * `--fee ` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm Default value: `100` +* `--cost` — Output the cost execution to stderr + + Possible values: `true`, `false` + +* `--instructions ` — Number of instructions to simulate @@ -691,6 +701,11 @@ Deploy a wasm contract * `--fee ` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm Default value: `100` +* `--cost` — Output the cost execution to stderr + + Possible values: `true`, `false` + +* `--instructions ` — Number of instructions to simulate * `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts Default value: `false` @@ -850,6 +865,11 @@ Install a WASM file to the ledger without creating a contract instance * `--fee ` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm Default value: `100` +* `--cost` — Output the cost execution to stderr + + Possible values: `true`, `false` + +* `--instructions ` — Number of instructions to simulate * `--wasm ` — Path to wasm binary * `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts @@ -877,11 +897,6 @@ soroban contract invoke ... -- --help ###### **Options:** * `--id ` — Contract ID to invoke -* `--cost` — Output the cost execution to stderr - - Possible values: `true`, `false` - -* `--instructions ` — Number of instructions to simulate * `--is-view` — Do not sign and submit transaction Possible values: `true`, `false` @@ -899,6 +914,11 @@ soroban contract invoke ... -- --help * `--fee ` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm Default value: `100` +* `--cost` — Output the cost execution to stderr + + Possible values: `true`, `false` + +* `--instructions ` — Number of instructions to simulate @@ -1006,6 +1026,11 @@ If no keys are specificed the contract itself is restored. * `--fee ` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm Default value: `100` +* `--cost` — Output the cost execution to stderr + + Possible values: `true`, `false` + +* `--instructions ` — Number of instructions to simulate @@ -1290,6 +1315,11 @@ Deploy a token contract to wrap an existing Stellar classic asset for smart cont * `--fee ` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm Default value: `100` +* `--cost` — Output the cost execution to stderr + + Possible values: `true`, `false` + +* `--instructions ` — Number of instructions to simulate