Skip to content

Commit

Permalink
feat: manually specify transaction nonces
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Oct 19, 2023
1 parent d0e96eb commit e853927
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/subcommands/account/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct Deploy {
signer: SignerArgs,
#[clap(flatten)]
fee: FeeArgs,
#[clap(long, help = "Provide transaction nonce manually")]
nonce: Option<FieldElement>,
#[clap(
long,
env = "STARKNET_POLL_INTERVAL",
Expand Down Expand Up @@ -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())
Expand Down
12 changes: 12 additions & 0 deletions src/subcommands/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct Declare {
casm: CasmArgs,
#[clap(flatten)]
fee: FeeArgs,
#[clap(long, help = "Provide transaction nonce manually")]
nonce: Option<FieldElement>,
#[clap(long, help = "Wait for the transaction to confirm")]
watch: bool,
#[clap(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/subcommands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct Deploy {
fee: FeeArgs,
#[clap(long, help = "Use the given salt to compute contract deploy address")]
salt: Option<String>,
#[clap(long, help = "Provide transaction nonce manually")]
nonce: Option<FieldElement>,
#[clap(long, help = "Wait for the transaction to confirm")]
watch: bool,
#[clap(
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions src/subcommands/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub struct Invoke {
account: AccountArgs,
#[clap(flatten)]
fee: FeeArgs,
#[clap(long, help = "Provide transaction nonce manually")]
nonce: Option<FieldElement>,
#[clap(long, help = "Wait for the transaction to confirm")]
watch: bool,
#[clap(
Expand Down Expand Up @@ -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: {}",
Expand Down

0 comments on commit e853927

Please sign in to comment.