@@ -14,6 +14,7 @@ use aligned_sdk::core::{
1414use aligned_sdk:: sdk:: estimate_fee;
1515use aligned_sdk:: sdk:: get_chain_id;
1616use aligned_sdk:: sdk:: get_nonce_from_batcher;
17+ use aligned_sdk:: sdk:: get_nonce_from_ethereum;
1718use aligned_sdk:: sdk:: { deposit_to_aligned, get_balance_in_aligned} ;
1819use aligned_sdk:: sdk:: { get_vk_commitment, is_proof_verified, save_response, submit_multiple} ;
1920use clap:: Args ;
@@ -25,13 +26,16 @@ use ethers::prelude::*;
2526use ethers:: utils:: format_ether;
2627use ethers:: utils:: hex;
2728use ethers:: utils:: parse_ether;
29+ use futures_util:: future;
2830use log:: warn;
2931use log:: { error, info} ;
3032use transaction:: eip2718:: TypedTransaction ;
3133
3234use crate :: AlignedCommands :: DepositToBatcher ;
35+ use crate :: AlignedCommands :: GetUserAmountOfQueuedProofs ;
3336use crate :: AlignedCommands :: GetUserBalance ;
3437use crate :: AlignedCommands :: GetUserNonce ;
38+ use crate :: AlignedCommands :: GetUserNonceFromEthereum ;
3539use crate :: AlignedCommands :: GetVkCommitment ;
3640use crate :: AlignedCommands :: Submit ;
3741use crate :: AlignedCommands :: VerifyProofOnchain ;
@@ -59,8 +63,21 @@ pub enum AlignedCommands {
5963 DepositToBatcher ( DepositToBatcherArgs ) ,
6064 #[ clap( about = "Get user balance from the batcher" , name = "get-user-balance" ) ]
6165 GetUserBalance ( GetUserBalanceArgs ) ,
62- #[ clap( about = "Get user nonce from the batcher" , name = "get-user-nonce" ) ]
66+ #[ clap(
67+ about = "Gets user current nonce from the batcher. This is the nonce you should send in your next proof." ,
68+ name = "get-user-nonce"
69+ ) ]
6370 GetUserNonce ( GetUserNonceArgs ) ,
71+ #[ clap(
72+ about = "Gets the user nonce directly from the BatcherPaymentService contract. Useful for validating the on-chain state and check if your transactions are pending in the batcher." ,
73+ name = "get-user-nonce-from-ethereum"
74+ ) ]
75+ GetUserNonceFromEthereum ( GetUserNonceFromEthereumArgs ) ,
76+ #[ clap(
77+ about = "Gets the number of proofs a user has queued in the Batcher." ,
78+ name = "get-user-amount-of-queued-proofs"
79+ ) ]
80+ GetUserAmountOfQueuedProofs ( GetUserAmountOfQueuedProofsArgs ) ,
6481}
6582
6683#[ derive( Parser , Debug ) ]
@@ -225,8 +242,46 @@ pub struct GetUserNonceArgs {
225242 address : String ,
226243}
227244
245+ #[ derive( Parser , Debug ) ]
246+ #[ command( version, about, long_about = None ) ]
247+ pub struct GetUserNonceFromEthereumArgs {
248+ #[ arg(
249+ name = "Ethereum RPC provider address" ,
250+ long = "rpc_url" ,
251+ default_value = "http://localhost:8545"
252+ ) ]
253+ eth_rpc_url : String ,
254+ #[ arg(
255+ name = "The user's Ethereum address" ,
256+ long = "user_addr" ,
257+ required = true
258+ ) ]
259+ address : String ,
260+ #[ clap( flatten) ]
261+ network : NetworkArg ,
262+ }
263+
264+ #[ derive( Parser , Debug ) ]
265+ #[ command( version, about, long_about = None ) ]
266+ pub struct GetUserAmountOfQueuedProofsArgs {
267+ #[ arg(
268+ name = "Ethereum RPC provider address" ,
269+ long = "rpc_url" ,
270+ default_value = "http://localhost:8545"
271+ ) ]
272+ eth_rpc_url : String ,
273+ #[ arg(
274+ name = "The user's Ethereum address" ,
275+ long = "user_addr" ,
276+ required = true
277+ ) ]
278+ address : String ,
279+ #[ clap( flatten) ]
280+ network : NetworkArg ,
281+ }
282+
228283#[ derive( Args , Debug ) ]
229- #[ group( required = true , multiple = false ) ]
284+ #[ group( multiple = false ) ]
230285pub struct PrivateKeyType {
231286 #[ arg( name = "path_to_keystore" , long = "keystore_path" ) ]
232287 keystore_path : Option < PathBuf > ,
@@ -642,6 +697,40 @@ async fn main() -> Result<(), AlignedError> {
642697 }
643698 }
644699 }
700+ GetUserNonceFromEthereum ( args) => {
701+ let address = H160 :: from_str ( & args. address ) . unwrap ( ) ;
702+ let network = args. network . into ( ) ;
703+ match get_nonce_from_ethereum ( & args. eth_rpc_url , address, network) . await {
704+ Ok ( nonce) => {
705+ info ! (
706+ "Nonce for address {} in BatcherPaymentService contract is {}" ,
707+ address, nonce
708+ ) ;
709+ }
710+ Err ( e) => {
711+ error ! ( "Error while getting nonce: {:?}" , e) ;
712+ return Ok ( ( ) ) ;
713+ }
714+ }
715+ }
716+ GetUserAmountOfQueuedProofs ( args) => {
717+ let address = H160 :: from_str ( & args. address ) . unwrap ( ) ;
718+ let network: Network = args. network . into ( ) ;
719+ let Ok ( ( ethereum_nonce, batcher_nonce) ) = future:: try_join (
720+ get_nonce_from_ethereum ( & args. eth_rpc_url , address, network. clone ( ) ) ,
721+ get_nonce_from_batcher ( network, address) ,
722+ )
723+ . await
724+ . map_err ( |e| error ! ( "Error while getting nonce: {:?}" , e) ) else {
725+ return Ok ( ( ) ) ;
726+ } ;
727+ info ! (
728+ "User {} has {} proofs in the batcher queue" ,
729+ address,
730+ batcher_nonce - ethereum_nonce
731+ ) ;
732+ return Ok ( ( ) ) ;
733+ }
645734 }
646735
647736 Ok ( ( ) )
0 commit comments