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 seq_num as an option for transactions #1702

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Deploy builtin Soroban Asset Contract
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout


Expand Down Expand Up @@ -379,6 +380,7 @@ If no keys are specified the contract itself is extended.
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout


Expand Down Expand Up @@ -408,6 +410,7 @@ Deploy a wasm contract
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <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

Expand Down Expand Up @@ -689,6 +692,7 @@ Install a WASM file to the ledger without creating a contract instance
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--wasm <WASM>` — Path to wasm binary
* `-i`, `--ignore-checks` — Whether to ignore safety checks when deploying contracts
Expand Down Expand Up @@ -729,6 +733,7 @@ stellar contract invoke ... -- --help
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--send <SEND>` — Whether or not to send a transaction

Expand Down Expand Up @@ -843,6 +848,7 @@ If no keys are specificed the contract itself is restored.
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout


Expand Down Expand Up @@ -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 <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -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 <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1476,6 +1484,7 @@ Creates, updates, or deletes a trustline Learn more about trustlines https://dev
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1506,6 +1515,7 @@ Creates and funds a new account with the specified starting balance
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -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 <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1564,6 +1575,7 @@ Sends an amount in a specific asset to a destination account
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -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 <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down Expand Up @@ -1637,6 +1650,7 @@ Allows issuing account to configure authorization and trustline flags to an asse
* `--cost` — Output the cost execution to stderr
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
* `--sequence-number <SEQUENCE_NUMBER>`
* `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout
* `--rpc-url <RPC_URL>` — RPC server endpoint
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
Expand Down
7 changes: 7 additions & 0 deletions cmd/soroban-cli/src/assembled.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -102,6 +103,12 @@ impl Assembled {
self
}

#[must_use]
pub fn set_seq_num(mut self, seq_num: impl Into<SequenceNumber>) -> Self {
self.txn.seq_num = seq_num.into();
self
}

///
/// # Errors
#[must_use]
Expand Down
11 changes: 7 additions & 4 deletions cmd/soroban-cli/src/commands/tx/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ pub enum Error {
impl Args {
pub async fn tx(&self, body: impl Into<xdr::OperationBody>) -> Result<xdr::Transaction, Error> {
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,
Expand Down
10 changes: 9 additions & 1 deletion cmd/soroban-cli/src/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
willemneal marked this conversation as resolved.
Show resolved Hide resolved
pub sequence_number: Option<i64>,
/// (Deprecated) simulate the transaction and only write the base64 xdr to stdout
#[arg(
long,
Expand All @@ -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
}
}
}
Expand All @@ -66,6 +73,7 @@ impl Default for Args {
instructions: None,
build_only: false,
sim_only: false,
sequence_number: None,
}
}
}
Loading