From afb74162c78b655b330dc2bc9d4ef3570fa791b0 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 5 Nov 2024 12:34:36 -0500 Subject: [PATCH 1/2] feat: add seq_num as an option for transactions --- FULL_HELP_DOCS.md | 14 ++++++++++++++ cmd/soroban-cli/src/assembled.rs | 7 +++++++ cmd/soroban-cli/src/commands/tx/args.rs | 11 +++++++---- cmd/soroban-cli/src/fee.rs | 10 +++++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index 8c151cb84..9e4026a1a 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -148,6 +148,7 @@ Deploy builtin Soroban Asset Contract * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout @@ -379,6 +380,7 @@ If no keys are specified the contract itself is extended. * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout @@ -408,6 +410,7 @@ Deploy a wasm contract * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts @@ -689,6 +692,7 @@ Install a WASM file to the ledger without creating a contract instance * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--wasm ` — Path to wasm binary * `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts @@ -729,6 +733,7 @@ stellar contract invoke ... -- --help * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--send ` — Whether or not to send a transaction @@ -843,6 +848,7 @@ If no keys are specificed the contract itself is restored. * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout @@ -1422,6 +1428,7 @@ Transfers the XLM balance of an account to another account and removes the sourc * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1449,6 +1456,7 @@ Bumps forward the sequence number of the source account to the given sequence nu * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1476,6 +1484,7 @@ Creates, updates, or deletes a trustline Learn more about trustlines https://dev * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1506,6 +1515,7 @@ Creates and funds a new account with the specified starting balance * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1536,6 +1546,7 @@ Sets, modifies, or deletes a data entry (name/value pair) that is attached to an * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1564,6 +1575,7 @@ Sends an amount in a specific asset to a destination account * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1595,6 +1607,7 @@ Set option for an account such as flags, inflation destination, signers, home do * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1637,6 +1650,7 @@ Allows issuing account to configure authorization and trustline flags to an asse * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout +* `--sequence-number ` * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider diff --git a/cmd/soroban-cli/src/assembled.rs b/cmd/soroban-cli/src/assembled.rs index 312863d52..312c4771b 100644 --- a/cmd/soroban-cli/src/assembled.rs +++ b/cmd/soroban-cli/src/assembled.rs @@ -1,4 +1,5 @@ use sha2::{Digest, Sha256}; +use soroban_sdk::xdr::SequenceNumber; use stellar_xdr::curr::{ self as xdr, ExtensionPoint, Hash, InvokeHostFunctionOp, LedgerFootprint, Limits, Memo, Operation, OperationBody, Preconditions, ReadXdr, RestoreFootprintOp, @@ -102,6 +103,12 @@ impl Assembled { self } + #[must_use] + pub fn set_seq_num(mut self, seq_num: impl Into) -> Self { + self.txn.seq_num = seq_num.into(); + self + } + /// /// # Errors #[must_use] diff --git a/cmd/soroban-cli/src/commands/tx/args.rs b/cmd/soroban-cli/src/commands/tx/args.rs index 7e032fd53..5c85a1fd4 100644 --- a/cmd/soroban-cli/src/commands/tx/args.rs +++ b/cmd/soroban-cli/src/commands/tx/args.rs @@ -37,10 +37,13 @@ pub enum Error { impl Args { pub async fn tx(&self, body: impl Into) -> Result { let source_account = self.source_account()?; - let seq_num = self - .config - .next_sequence_number(&source_account.to_string()) - .await?; + let seq_num = if let Some(seq_num) = self.fee.sequence_number { + seq_num.into() + } else { + self.config + .next_sequence_number(&source_account.to_string()) + .await? + }; // Once we have a way to add operations this will be updated to allow for a different source account let operation = xdr::Operation { source_account: None, diff --git a/cmd/soroban-cli/src/fee.rs b/cmd/soroban-cli/src/fee.rs index ea968870f..024638da9 100644 --- a/cmd/soroban-cli/src/fee.rs +++ b/cmd/soroban-cli/src/fee.rs @@ -24,6 +24,8 @@ pub struct Args { /// Build the transaction and only write the base64 xdr to stdout #[arg(long, help_heading = HEADING_RPC)] pub build_only: bool, + #[arg(long, visible_alias = "seq-num", help_heading = HEADING_RPC)] + pub sequence_number: Option, /// (Deprecated) simulate the transaction and only write the base64 xdr to stdout #[arg( long, @@ -37,10 +39,15 @@ pub struct Args { impl Args { pub fn apply_to_assembled_txn(&self, txn: Assembled) -> Assembled { - if let Some(instructions) = self.instructions { + let txn = if let Some(instructions) = self.instructions { txn.set_max_instructions(instructions) } else { add_padding_to_instructions(txn) + }; + if let Some(sequence_number) = self.sequence_number { + txn.set_seq_num(sequence_number) + } else { + txn } } } @@ -66,6 +73,7 @@ impl Default for Args { instructions: None, build_only: false, sim_only: false, + sequence_number: None, } } } From 53c62ddd609067e4db63725071851fb53a991068 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 5 Nov 2024 15:49:04 -0500 Subject: [PATCH 2/2] fix: add help doc --- FULL_HELP_DOCS.md | 28 ++++++++++++++-------------- cmd/soroban-cli/src/fee.rs | 1 + 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index 9e4026a1a..2d4123fc6 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -148,7 +148,7 @@ Deploy builtin Soroban Asset Contract * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout @@ -380,7 +380,7 @@ If no keys are specified the contract itself is extended. * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout @@ -410,7 +410,7 @@ Deploy a wasm contract * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts @@ -692,7 +692,7 @@ Install a WASM file to the ledger without creating a contract instance * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--wasm ` — Path to wasm binary * `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts @@ -733,7 +733,7 @@ stellar contract invoke ... -- --help * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--send ` — Whether or not to send a transaction @@ -848,7 +848,7 @@ If no keys are specificed the contract itself is restored. * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout @@ -1428,7 +1428,7 @@ Transfers the XLM balance of an account to another account and removes the sourc * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1456,7 +1456,7 @@ Bumps forward the sequence number of the source account to the given sequence nu * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1484,7 +1484,7 @@ Creates, updates, or deletes a trustline Learn more about trustlines https://dev * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1515,7 +1515,7 @@ Creates and funds a new account with the specified starting balance * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1546,7 +1546,7 @@ Sets, modifies, or deletes a data entry (name/value pair) that is attached to an * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1575,7 +1575,7 @@ Sends an amount in a specific asset to a destination account * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1607,7 +1607,7 @@ Set option for an account such as flags, inflation destination, signers, home do * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider @@ -1650,7 +1650,7 @@ Allows issuing account to configure authorization and trustline flags to an asse * `--cost` — Output the cost execution to stderr * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout -* `--sequence-number ` +* `--sequence-number ` — Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout * `--rpc-url ` — RPC server endpoint * `--rpc-header ` — RPC Header(s) to include in requests to the RPC provider diff --git a/cmd/soroban-cli/src/fee.rs b/cmd/soroban-cli/src/fee.rs index 024638da9..119142de7 100644 --- a/cmd/soroban-cli/src/fee.rs +++ b/cmd/soroban-cli/src/fee.rs @@ -25,6 +25,7 @@ pub struct Args { #[arg(long, help_heading = HEADING_RPC)] pub build_only: bool, #[arg(long, visible_alias = "seq-num", help_heading = HEADING_RPC)] + /// Optionally set the sequence number for the transaction; default is the current sequence number of the source account incremented by one pub sequence_number: Option, /// (Deprecated) simulate the transaction and only write the base64 xdr to stdout #[arg(