Skip to content

Commit 9a62d14

Browse files
PatStilesMarcosNicolau
authored andcommitted
add get_first_nonce command
1 parent f0d9115 commit 9a62d14

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

batcher/aligned/src/main.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use aligned_sdk::core::{
1212
};
1313
use aligned_sdk::sdk::get_chain_id;
1414
use aligned_sdk::sdk::get_nonce_from_batcher;
15+
use aligned_sdk::sdk::get_nonce_from_ethereum;
1516
use aligned_sdk::sdk::{deposit_to_aligned, get_balance_in_aligned};
1617
use aligned_sdk::sdk::{get_vk_commitment, is_proof_verified, save_response, submit_multiple};
1718
use clap::Parser;
@@ -29,6 +30,7 @@ use transaction::eip2718::TypedTransaction;
2930
use crate::AlignedCommands::DepositToBatcher;
3031
use crate::AlignedCommands::GetUserBalance;
3132
use crate::AlignedCommands::GetUserNonce;
33+
use crate::AlignedCommands::GetUserFirstNonce;
3234
use crate::AlignedCommands::GetVkCommitment;
3335
use crate::AlignedCommands::Submit;
3436
use crate::AlignedCommands::VerifyProofOnchain;
@@ -58,6 +60,8 @@ pub enum AlignedCommands {
5860
GetUserBalance(GetUserBalanceArgs),
5961
#[clap(about = "Get user nonce from the batcher", name = "get-user-nonce")]
6062
GetUserNonce(GetUserNonceArgs),
63+
#[clap(about = "Get the first user nonce from ethereum", name = "get-user-first-nonce")]
64+
GetUserFirstNonce(GetUserFirstNonceArgs),
6165
}
6266

6367
#[derive(Parser, Debug)]
@@ -218,6 +222,29 @@ pub struct GetUserNonceArgs {
218222
address: String,
219223
}
220224

225+
#[derive(Parser, Debug)]
226+
#[command(version, about, long_about = None)]
227+
pub struct GetUserFirstNonceArgs {
228+
#[arg(
229+
name = "Ethereum RPC provider address",
230+
long = "rpc_url",
231+
default_value = "http://localhost:8545"
232+
)]
233+
eth_rpc_url: String,
234+
#[arg(
235+
name = "The user's Ethereum address",
236+
long = "user_addr",
237+
required = true
238+
)]
239+
address: String,
240+
#[arg(
241+
name = "The working network's name",
242+
long = "network",
243+
default_value = "devnet"
244+
)]
245+
network: NetworkArg,
246+
}
247+
221248
#[derive(Debug, Clone, ValueEnum, Copy)]
222249
enum NetworkArg {
223250
Devnet,
@@ -528,6 +555,20 @@ async fn main() -> Result<(), AlignedError> {
528555
}
529556
}
530557
}
558+
GetUserFirstNonce(args) => {
559+
let address = H160::from_str(&args.address).unwrap();
560+
let network = args.network.into();
561+
match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await {
562+
Ok(nonce) => {
563+
let first_nonce = nonce + 1;
564+
info!("Nonce for address {} is {}", address, first_nonce);
565+
}
566+
Err(e) => {
567+
error!("Error while getting nonce: {:?}", e);
568+
return Ok(());
569+
}
570+
}
571+
}
531572
}
532573

533574
Ok(())

0 commit comments

Comments
 (0)