From e8539274b0160f57a2fdd385c58c3db959245c1d Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Thu, 19 Oct 2023 06:55:19 +0000 Subject: [PATCH] feat: manually specify transaction nonces --- src/subcommands/account/deploy.rs | 7 +++++++ src/subcommands/declare.rs | 12 ++++++++++++ src/subcommands/deploy.rs | 7 +++++++ src/subcommands/invoke.rs | 7 +++++++ 4 files changed, 33 insertions(+) diff --git a/src/subcommands/account/deploy.rs b/src/subcommands/account/deploy.rs index 7219819..c7f5e88 100644 --- a/src/subcommands/account/deploy.rs +++ b/src/subcommands/account/deploy.rs @@ -32,6 +32,8 @@ pub struct Deploy { signer: SignerArgs, #[clap(flatten)] fee: FeeArgs, + #[clap(long, help = "Provide transaction nonce manually")] + nonce: Option, #[clap( long, env = "STARKNET_POLL_INTERVAL", @@ -245,6 +247,11 @@ impl Deploy { eprint!("Press [ENTER] once you've funded the address."); std::io::stdin().read_line(&mut String::new())?; + let account_deployment = match self.nonce { + Some(nonce) => account_deployment.nonce(nonce), + None => account_deployment, + }; + // TODO: add option to check ETH balance before sending out tx let account_deployment_tx = account_deployment .max_fee(max_fee.max_fee()) diff --git a/src/subcommands/declare.rs b/src/subcommands/declare.rs index 45a29cc..5a55104 100644 --- a/src/subcommands/declare.rs +++ b/src/subcommands/declare.rs @@ -32,6 +32,8 @@ pub struct Declare { casm: CasmArgs, #[clap(flatten)] fee: FeeArgs, + #[clap(long, help = "Provide transaction nonce manually")] + nonce: Option, #[clap(long, help = "Wait for the transaction to confirm")] watch: bool, #[clap( @@ -153,6 +155,11 @@ impl Declare { } }; + let declaration = match self.nonce { + Some(nonce) => declaration.nonce(nonce), + None => declaration, + }; + ( class_hash, declaration.max_fee(max_fee).send().await?.transaction_hash, @@ -208,6 +215,11 @@ impl Declare { } }; + let declaration = match self.nonce { + Some(nonce) => declaration.nonce(nonce), + None => declaration, + }; + ( class_hash, declaration.max_fee(max_fee).send().await?.transaction_hash, diff --git a/src/subcommands/deploy.rs b/src/subcommands/deploy.rs index 11c777b..9fc2101 100644 --- a/src/subcommands/deploy.rs +++ b/src/subcommands/deploy.rs @@ -35,6 +35,8 @@ pub struct Deploy { fee: FeeArgs, #[clap(long, help = "Use the given salt to compute contract deploy address")] salt: Option, + #[clap(long, help = "Provide transaction nonce manually")] + nonce: Option, #[clap(long, help = "Wait for the transaction to confirm")] watch: bool, #[clap( @@ -115,6 +117,11 @@ impl Deploy { format!("{:#064x}", deployed_address).bright_yellow() ); + let contract_deployment = match self.nonce { + Some(nonce) => contract_deployment.nonce(nonce), + None => contract_deployment, + }; + let deployment_tx = contract_deployment .max_fee(max_fee) .send() diff --git a/src/subcommands/invoke.rs b/src/subcommands/invoke.rs index 3cca7ce..d5f9cf1 100644 --- a/src/subcommands/invoke.rs +++ b/src/subcommands/invoke.rs @@ -26,6 +26,8 @@ pub struct Invoke { account: AccountArgs, #[clap(flatten)] fee: FeeArgs, + #[clap(long, help = "Provide transaction nonce manually")] + nonce: Option, #[clap(long, help = "Wait for the transaction to confirm")] watch: bool, #[clap( @@ -120,6 +122,11 @@ impl Invoke { } }; + let execution = match self.nonce { + Some(nonce) => execution.nonce(nonce), + None => execution, + }; + let invoke_tx = execution.max_fee(max_fee).send().await?.transaction_hash; eprintln!( "Invoke transaction: {}",