Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tx set #1760

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 87 additions & 59 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1455,30 +1455,12 @@ Sign, Simulate, and Send transactions

###### **Subcommands:**

* `simulate` — Simulate a transaction envelope from stdin
* `hash` — Calculate the hash of a transaction envelope from stdin
* `sign` — Sign a transaction envelope appending the signature to the envelope
* `send` — Send a transaction envelope to the network
* `new` — Create a new transaction



## `stellar tx simulate`

Simulate a transaction envelope from stdin

**Usage:** `stellar tx simulate [OPTIONS] --source-account <SOURCE_ACCOUNT>`

###### **Options:**

* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
* `--source-account <SOURCE_ACCOUNT>` — Account that where transaction originates from. Alias `source`. Can be an identity (--source alice), a public key (--source GDKW...), a muxed account (--source MDA…), a secret key (--source SC36…), or a seed phrase (--source "kite urban…"). If `--build-only` or `--sim-only` flags were NOT provided, this key will also be used to sign the final transaction. In that case, trying to sign with public key will fail
* `--hd-path <HD_PATH>` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0`
* `--global` — Use global config
* `--config-dir <CONFIG_DIR>` — Location of config directory, default is "."
* `send` — Send a transaction envelope to the network
* `set` — Set various options for a transaction
* `simulate` — Simulate a transaction envelope from stdin
* `sign` — Sign a transaction envelope appending the signature to the envelope



Expand All @@ -1497,43 +1479,6 @@ Calculate the hash of a transaction envelope from stdin



## `stellar tx sign`

Sign a transaction envelope appending the signature to the envelope

**Usage:** `stellar tx sign [OPTIONS]`

###### **Options:**

* `--sign-with-key <SIGN_WITH_KEY>` — Sign with a local key. Can be an identity (--sign-with-key alice), a secret key (--sign-with-key SC36…), or a seed phrase (--sign-with-key "kite urban…"). If using seed phrase, `--hd-path` defaults to the `0` path
* `--hd-path <HD_PATH>` — If using a seed phrase to sign, sets which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0`
* `--sign-with-lab` — Sign with https://lab.stellar.org
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
* `--global` — Use global config
* `--config-dir <CONFIG_DIR>` — Location of config directory, default is "."



## `stellar tx send`

Send a transaction envelope to the network

**Usage:** `stellar tx send [OPTIONS]`

###### **Options:**

* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
* `--global` — Use global config
* `--config-dir <CONFIG_DIR>` — Location of config directory, default is "."



## `stellar tx new`

Create a new transaction
Expand Down Expand Up @@ -1802,6 +1747,89 @@ Allows issuing account to configure authorization and trustline flags to an asse



## `stellar tx send`

Send a transaction envelope to the network

**Usage:** `stellar tx send [OPTIONS]`

###### **Options:**

* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
* `--global` — Use global config
* `--config-dir <CONFIG_DIR>` — Location of config directory, default is "."



## `stellar tx set`

Set various options for a transaction

**Usage:** `stellar tx set [OPTIONS]`

###### **Options:**

* `--sequence-number <SEQUENCE_NUMBER>` — Set the transactions sequence number
* `--fee <FEE>` — Set the transactions fee
* `--memo-text <MEMO_TEXT>` — Set the transactions memo text
* `--memo-id <MEMO_ID>` — Set the transactions memo id
* `--memo-hash <MEMO_HASH>` — Set the transactions memo hash
* `--memo-return <MEMO_RETURN>` — Set the transactions memo return
* `--source-account <SOURCE_ACCOUNT>` — Change the source account for the transaction
* `--max-time-bound <MAX_TIME_BOUND>` — Set the transactions max time bound
* `--min-time-bound <MIN_TIME_BOUND>` — Set the transactions min time bound
* `--min-ledger <MIN_LEDGER>` — Set the minimum ledger that the transaction is valid
* `--max-ledger <MAX_LEDGER>` — Set the max ledger that the transaction is valid. 0 or not present means to max
* `--min-seq-num <MIN_SEQ_NUM>` — set mimimum sequence number
* `--min-seq-age <MIN_SEQ_AGE>`
* `--min-seq-ledger-gap <MIN_SEQ_LEDGER_GAP>` — min sequeence ledger gap
* `--extra-signers <EXTRA_SIGNERS>` — Extra signers
* `--no-preconditions` — Set precondition to None
Comment on lines +1767 to +1790
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playing around with this interface I think some design discussion is required for this sub-command.

When we previously discussed this (#1643 (comment)) I had suggested we could have one sub-command per field to set, but I think this arrangement is also reasonable, but looks like there's missing functionality as it is, so we need that design to flesh out all the use cases.

For example, it looks like we can clear all the preconditions with 'no-preconditions', but it's not obvious to a user which fields are being cleared because the options are bundled in a single command the relationship between all the options appear equal / related, when they are not.

Another example, there's no way to remove a memo, or some precondition fields without clearing all preconditions.

I've started a design discussion on the issue:




## `stellar tx simulate`

Simulate a transaction envelope from stdin

**Usage:** `stellar tx simulate [OPTIONS] --source-account <SOURCE_ACCOUNT>`

###### **Options:**

* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
* `--source-account <SOURCE_ACCOUNT>` — Account that where transaction originates from. Alias `source`. Can be an identity (--source alice), a public key (--source GDKW...), a muxed account (--source MDA…), a secret key (--source SC36…), or a seed phrase (--source "kite urban…"). If `--build-only` or `--sim-only` flags were NOT provided, this key will also be used to sign the final transaction. In that case, trying to sign with public key will fail
* `--hd-path <HD_PATH>` — If using a seed phrase, which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0`
* `--global` — Use global config
* `--config-dir <CONFIG_DIR>` — Location of config directory, default is "."



## `stellar tx sign`

Sign a transaction envelope appending the signature to the envelope

**Usage:** `stellar tx sign [OPTIONS]`

###### **Options:**

* `--sign-with-key <SIGN_WITH_KEY>` — Sign with a local key. Can be an identity (--sign-with-key alice), a secret key (--sign-with-key SC36…), or a seed phrase (--sign-with-key "kite urban…"). If using seed phrase, `--hd-path` defaults to the `0` path
* `--hd-path <HD_PATH>` — If using a seed phrase to sign, sets which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0`
* `--sign-with-lab` — Sign with https://lab.stellar.org
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
* `--network <NETWORK>` — Name of network to use from config
* `--global` — Use global config
* `--config-dir <CONFIG_DIR>` — Location of config directory, default is "."



## `stellar xdr`

Decode and encode XDR
Expand Down
5 changes: 2 additions & 3 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use predicates::boolean::PredicateBooleanExt;
use soroban_cli::{
commands::{
contract::{self, fetch},
txn_result::TxnResult,
},
config::{address::Address, locator, secret},
config::{locator, secret},
};
use soroban_rpc::GetLatestLedgerResponse;
use soroban_test::{AssertExt, TestEnv, LOCAL_NETWORK_PASSPHRASE};
Expand All @@ -19,7 +18,7 @@ async fn invoke_view_with_non_existent_source_account() {
let sandbox = &TestEnv::new();
let id = deploy_hello(sandbox).await;
let world = "world";
let mut cmd = hello_world_cmd(&id, world);
let cmd = hello_world_cmd(&id, world);
let res = sandbox.run_cmd_with(cmd, "").await.unwrap();
assert_eq!(res, TxnResult::Res(format!(r#"["Hello",{world:?}]"#)));
}
Expand Down
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/integration/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use soroban_test::{AssertExt, TestEnv};
use crate::integration::util::{deploy_contract, DeployKind, HELLO_WORLD};

mod operations;
mod set;

#[tokio::test]
async fn simulate() {
Expand Down
34 changes: 34 additions & 0 deletions cmd/crates/soroban-test/tests/it/integration/tx/set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use soroban_cli::xdr::{Limits, ReadXdr, TransactionEnvelope};
use soroban_test::{AssertExt, TestEnv};

use crate::integration::util::HELLO_WORLD;

#[tokio::test]
async fn build_simulate_sign_send() {
let sandbox = &TestEnv::new();
let tx_base64 = sandbox
.new_assert_cmd("contract")
.arg("install")
.args([
"--wasm",
HELLO_WORLD.path().as_os_str().to_str().unwrap(),
"--build-only",
])
.assert()
.success()
.stdout_as_str();
let tx_env = TransactionEnvelope::from_xdr_base64(&tx_base64, Limits::none()).unwrap();
// set transaction options set fee
let new_tx = sandbox
.new_assert_cmd("tx")
.arg("set")
.arg("--fee")
.arg("10000")
.write_stdin(tx_base64.as_bytes())
.assert()
.success()
.stdout_as_str();
let tx_env_two = TransactionEnvelope::from_xdr_base64(&new_tx, Limits::none()).unwrap();
let tx = soroban_cli::commands::tx::xdr::unwrap_envelope_v1(tx_env_two).unwrap();
assert_eq!(tx.fee, 10000);
}
1 change: 1 addition & 0 deletions cmd/crates/soroban-test/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ mod init;
#[cfg(feature = "it")]
mod integration;
mod plugin;
mod tx;
mod util;
mod version;
31 changes: 31 additions & 0 deletions cmd/crates/soroban-test/tests/it/tx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use soroban_cli::xdr::{Limits, ReadXdr, TransactionEnvelope};
use soroban_test::{AssertExt, TestEnv};

const SOURCE: &str = "GBZXN7PIRZGNMHGA7MUUUF4GWPY5AYPV6LY4UV2GL6VJGIQRXFDNMADI";

#[tokio::test]
async fn build_simulate_sign_send() {
let sandbox = &TestEnv::new();
let tx_base64 = sandbox
.new_assert_cmd("tx")
.args(["new", "payment", "--destination", SOURCE, "--amount", "222"])
.assert()
.success()
.stdout_as_str();
let tx_env = TransactionEnvelope::from_xdr_base64(&tx_base64, Limits::none()).unwrap();
let tx = soroban_cli::commands::tx::xdr::unwrap_envelope_v1(tx_env).unwrap();
assert_eq!(tx.fee, 100);
// set transaction options set fee
let new_tx = sandbox
.new_assert_cmd("tx")
.arg("set")
.arg("--fee")
.arg("10000")
.write_stdin(tx_base64.as_bytes())
.assert()
.success()
.stdout_as_str();
let tx_env_two = TransactionEnvelope::from_xdr_base64(&new_tx, Limits::none()).unwrap();
let tx = soroban_cli::commands::tx::xdr::unwrap_envelope_v1(tx_env_two).unwrap();
assert_eq!(tx.fee, 10000);
}
19 changes: 13 additions & 6 deletions cmd/soroban-cli/src/commands/tx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use super::global;

pub mod args;

pub mod hash;
pub mod new;
pub mod send;
pub mod set;
pub mod sign;
pub mod simulate;
pub mod xdr;
Expand All @@ -12,17 +14,19 @@ pub use args::Args;

#[derive(Debug, clap::Subcommand)]
pub enum Cmd {
/// Simulate a transaction envelope from stdin
Simulate(simulate::Cmd),
/// Calculate the hash of a transaction envelope from stdin
Hash(hash::Cmd),
/// Sign a transaction envelope appending the signature to the envelope
Sign(sign::Cmd),
/// Send a transaction envelope to the network
Send(send::Cmd),
/// Create a new transaction
#[command(subcommand)]
New(new::Cmd),
/// Send a transaction envelope to the network
Send(send::Cmd),
/// Set various options for a transaction
Set(set::Cmd),
/// Simulate a transaction envelope from stdin
Simulate(simulate::Cmd),
/// Sign a transaction envelope appending the signature to the envelope
Sign(sign::Cmd),
Comment on lines +22 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we organise these commands by order of likely to use next? i.e.:

  • New
  • Set
  • Simulate
  • Sign
  • Send

}

#[derive(thiserror::Error, Debug)]
Expand All @@ -37,6 +41,8 @@ pub enum Error {
Sign(#[from] sign::Error),
#[error(transparent)]
Send(#[from] send::Error),
#[error(transparent)]
Set(#[from] set::Error),
}

impl Cmd {
Expand All @@ -47,6 +53,7 @@ impl Cmd {
Cmd::New(cmd) => cmd.run(global_args).await?,
Cmd::Sign(cmd) => cmd.run(global_args).await?,
Cmd::Send(cmd) => cmd.run(global_args).await?,
Cmd::Set(cmd) => cmd.run(global_args)?,
};
Ok(())
}
Expand Down
Loading