From 197f636f5136c11ab1136de9bfb07449f58278cf Mon Sep 17 00:00:00 2001 From: Bai Chuan Date: Sat, 14 Sep 2024 20:35:08 +0800 Subject: [PATCH] [Cli] Build tx with sequence number (#2633) --- crates/rooch-rpc-client/src/wallet_context.rs | 23 +++++++++++++++---- crates/rooch/src/cli_types.rs | 4 ++++ .../commands/transaction/commands/build.rs | 3 ++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/rooch-rpc-client/src/wallet_context.rs b/crates/rooch-rpc-client/src/wallet_context.rs index fd55c7e925..a30429f316 100644 --- a/crates/rooch-rpc-client/src/wallet_context.rs +++ b/crates/rooch-rpc-client/src/wallet_context.rs @@ -193,14 +193,27 @@ impl WalletContext { sender: RoochAddress, action: MoveAction, max_gas_amount: Option, + ) -> RoochResult { + self.build_tx_data_with_sequence_number(sender, action, max_gas_amount, None) + .await + } + + pub async fn build_tx_data_with_sequence_number( + &self, + sender: RoochAddress, + action: MoveAction, + max_gas_amount: Option, + sequence_number: Option, ) -> RoochResult { let client = self.get_client().await?; let chain_id = client.rooch.get_chain_id().await?; - let sequence_number = client - .rooch - .get_sequence_number(sender) - .await - .map_err(RoochError::from)?; + let sequence_number = sequence_number.unwrap_or( + client + .rooch + .get_sequence_number(sender) + .await + .map_err(RoochError::from)?, + ); log::debug!("use sequence_number: {}", sequence_number); //TODO max gas amount from cli option or dry run estimate let tx_data = RoochTransactionData::new( diff --git a/crates/rooch/src/cli_types.rs b/crates/rooch/src/cli_types.rs index 52a0c5814f..336e219a01 100644 --- a/crates/rooch/src/cli_types.rs +++ b/crates/rooch/src/cli_types.rs @@ -85,6 +85,10 @@ pub struct TransactionOptions { #[clap(long, alias = "sender-account", value_parser=ParsedAddress::parse, default_value = "default")] pub(crate) sender: ParsedAddress, + /// Custom account's sequence number + #[clap(long)] + pub(crate) sequence_number: Option, + /// Custom the transaction's gas limit. /// [default: 1_000_000_000] [alias: "gas-limit"] #[clap(long, alias = "gas-limit")] diff --git a/crates/rooch/src/commands/transaction/commands/build.rs b/crates/rooch/src/commands/transaction/commands/build.rs index 28e8ad0d5b..965f527833 100644 --- a/crates/rooch/src/commands/transaction/commands/build.rs +++ b/crates/rooch/src/commands/transaction/commands/build.rs @@ -62,6 +62,7 @@ impl CommandAction> for BuildCommand { let context = self.context.build()?; let address_mapping = context.address_mapping(); let sender = context.resolve_address(self.tx_options.sender)?.into(); + let sequenc_number = self.tx_options.sequence_number; let max_gas_amount = self.tx_options.max_gas_amount; let function_id = self.function.into_function_id(&address_mapping)?; @@ -82,7 +83,7 @@ impl CommandAction> for BuildCommand { let action = MoveAction::new_function_call(function_id, type_args, args); let tx_data = context - .build_tx_data(sender, action, max_gas_amount) + .build_tx_data_with_sequence_number(sender, action, max_gas_amount, sequenc_number) .await?; let output =