Skip to content

Commit

Permalink
Merge branch 'main' into interface-version-output
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Feb 28, 2024
2 parents 7bcaebf + c27f114 commit 3b39b01
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 32 deletions.
5 changes: 3 additions & 2 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 4 additions & 2 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,18 @@ 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,
&network.network_passphrase,
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())
}
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 @@ -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,
},
Expand Down
14 changes: 6 additions & 8 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 3 additions & 11 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ pub struct Cmd {
// For testing only
#[arg(skip)]
pub wasm: Option<std::path::PathBuf>,
/// Output the cost execution to stderr
#[arg(long = "cost")]
pub cost: bool,
/// Number of instructions to simulate
#[arg(long)]
pub instructions: Option<u32>,
/// Do not sign and submit transaction
#[arg(long, env = "SOROBAN_INVOKE_SIGN", env = "SYSTEM_TEST_VERBOSE_OUTPUT")]
pub is_view: bool,
Expand Down Expand Up @@ -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(),
Expand All @@ -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?;
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 @@ -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,
},
Expand Down
26 changes: 24 additions & 2 deletions cmd/soroban-cli/src/fee.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
use crate::commands::HEADING_RPC;
use clap::arg;
use soroban_rpc::Assembled;

use crate::commands::HEADING_RPC;

#[derive(Debug, clap::Args, Clone)]
#[group(skip)]
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<u32>,
}

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,
}
}
}
40 changes: 35 additions & 5 deletions docs/soroban-cli-full-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ Deploy builtin Soroban Asset Contract
* `--fee <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 <INSTRUCTIONS>` — Number of instructions to simulate



Expand Down Expand Up @@ -664,6 +669,11 @@ If no keys are specified the contract itself is extended.
* `--fee <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 <INSTRUCTIONS>` — Number of instructions to simulate



Expand Down Expand Up @@ -691,6 +701,11 @@ Deploy a wasm contract
* `--fee <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 <INSTRUCTIONS>` — Number of instructions to simulate
* `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts

Default value: `false`
Expand Down Expand Up @@ -850,6 +865,11 @@ Install a WASM file to the ledger without creating a contract instance
* `--fee <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 <INSTRUCTIONS>` — Number of instructions to simulate
* `--wasm <WASM>` — Path to wasm binary
* `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts

Expand Down Expand Up @@ -877,11 +897,6 @@ soroban contract invoke ... -- --help
###### **Options:**

* `--id <CONTRACT_ID>` — Contract ID to invoke
* `--cost` — Output the cost execution to stderr

Possible values: `true`, `false`

* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--is-view` — Do not sign and submit transaction

Possible values: `true`, `false`
Expand All @@ -899,6 +914,11 @@ soroban contract invoke ... -- --help
* `--fee <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 <INSTRUCTIONS>` — Number of instructions to simulate



Expand Down Expand Up @@ -1006,6 +1026,11 @@ If no keys are specificed the contract itself is restored.
* `--fee <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 <INSTRUCTIONS>` — Number of instructions to simulate



Expand Down Expand Up @@ -1290,6 +1315,11 @@ Deploy a token contract to wrap an existing Stellar classic asset for smart cont
* `--fee <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 <INSTRUCTIONS>` — Number of instructions to simulate



Expand Down

0 comments on commit 3b39b01

Please sign in to comment.