Skip to content

Commit

Permalink
[Cli] Build tx with sequence number (#2633)
Browse files Browse the repository at this point in the history
  • Loading branch information
baichuan3 committed Sep 14, 2024
1 parent 5f62841 commit 197f636
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
23 changes: 18 additions & 5 deletions crates/rooch-rpc-client/src/wallet_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,27 @@ impl WalletContext {
sender: RoochAddress,
action: MoveAction,
max_gas_amount: Option<u64>,
) -> RoochResult<RoochTransactionData> {
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<u64>,
sequence_number: Option<u64>,
) -> RoochResult<RoochTransactionData> {
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(
Expand Down
4 changes: 4 additions & 0 deletions crates/rooch/src/cli_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,

/// Custom the transaction's gas limit.
/// [default: 1_000_000_000] [alias: "gas-limit"]
#[clap(long, alias = "gas-limit")]
Expand Down
3 changes: 2 additions & 1 deletion crates/rooch/src/commands/transaction/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl CommandAction<Option<FileOutput>> 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)?;
Expand All @@ -82,7 +83,7 @@ impl CommandAction<Option<FileOutput>> 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 =
Expand Down

0 comments on commit 197f636

Please sign in to comment.