@@ -14,6 +14,7 @@ use aligned_sdk::sdk::get_chain_id;
1414use aligned_sdk:: sdk:: get_nonce_from_batcher;
1515use aligned_sdk:: sdk:: { deposit_to_aligned, get_balance_in_aligned} ;
1616use aligned_sdk:: sdk:: { get_vk_commitment, is_proof_verified, save_response, submit_multiple} ;
17+ use clap:: Args ;
1718use clap:: Parser ;
1819use clap:: Subcommand ;
1920use clap:: ValueEnum ;
@@ -103,10 +104,8 @@ pub struct SubmitArgs {
103104 default_value = "./aligned_verification_data/"
104105 ) ]
105106 batch_inclusion_data_directory_path : String ,
106- #[ arg( name = "Path to local keystore" , long = "keystore_path" ) ]
107- keystore_path : Option < PathBuf > ,
108- #[ arg( name = "Private key" , long = "private_key" ) ]
109- private_key : Option < String > ,
107+ #[ command( flatten) ]
108+ private_key_type : PrivateKeyType ,
110109 #[ arg(
111110 name = "Max Fee (ether)" ,
112111 long = "max_fee" ,
@@ -126,18 +125,14 @@ pub struct SubmitArgs {
126125#[ derive( Parser , Debug ) ]
127126#[ command( version, about, long_about = None ) ]
128127pub struct DepositToBatcherArgs {
129- #[ arg(
130- name = "Path to local keystore" ,
131- long = "keystore_path" ,
132- required = true
133- ) ]
134- keystore_path : Option < PathBuf > ,
135128 #[ arg(
136129 name = "Ethereum RPC provider address" ,
137130 long = "rpc_url" ,
138131 default_value = "http://localhost:8545"
139132 ) ]
140133 eth_rpc_url : String ,
134+ #[ command( flatten) ]
135+ private_key_type : PrivateKeyType ,
141136 #[ arg(
142137 name = "The working network's name" ,
143138 long = "network" ,
@@ -218,6 +213,15 @@ pub struct GetUserNonceArgs {
218213 address : String ,
219214}
220215
216+ #[ derive( Args , Debug ) ]
217+ #[ group( required = true , multiple = false ) ]
218+ pub struct PrivateKeyType {
219+ #[ arg( name = "path_to_keystore" , long = "keystore_path" ) ]
220+ keystore_path : Option < PathBuf > ,
221+ #[ arg( name = "private_key" , long = "private_key" ) ]
222+ private_key : Option < String > ,
223+ }
224+
221225#[ derive( Debug , Clone , ValueEnum , Copy ) ]
222226enum NetworkArg {
223227 Devnet ,
@@ -293,13 +297,8 @@ async fn main() -> Result<(), AlignedError> {
293297 let repetitions = submit_args. repetitions ;
294298 let connect_addr = submit_args. batcher_url . clone ( ) ;
295299
296- let keystore_path = & submit_args. keystore_path ;
297- let private_key = & submit_args. private_key ;
298-
299- if keystore_path. is_some ( ) && private_key. is_some ( ) {
300- warn ! ( "Can't have a keystore path and a private key as input. Please use only one" ) ;
301- return Ok ( ( ) ) ;
302- }
300+ let keystore_path = & submit_args. private_key_type . keystore_path ;
301+ let private_key = & submit_args. private_key_type . private_key ;
303302
304303 let mut wallet = if let Some ( keystore_path) = keystore_path {
305304 let password = rpassword:: prompt_password ( "Please enter your keystore password:" )
@@ -311,7 +310,7 @@ async fn main() -> Result<(), AlignedError> {
311310 . parse :: < LocalWallet > ( )
312311 . map_err ( |e| SubmitError :: GenericError ( e. to_string ( ) ) ) ?
313312 } else {
314- warn ! ( "Missing keystore used for payment. This proof will not be included if sent to Eth Mainnet" ) ;
313+ warn ! ( "Missing keystore or private key used for payment. This proof will not be included if sent to Eth Mainnet" ) ;
315314 match LocalWallet :: from_str ( ANVIL_PRIVATE_KEY ) {
316315 Ok ( wallet) => wallet,
317316 Err ( e) => {
@@ -473,15 +472,20 @@ async fn main() -> Result<(), AlignedError> {
473472 ) )
474473 } ) ?;
475474
476- let keystore_path = & deposit_to_batcher_args. keystore_path ;
475+ let keystore_path = & deposit_to_batcher_args. private_key_type . keystore_path ;
476+ let private_key = & deposit_to_batcher_args. private_key_type . private_key ;
477477
478478 let mut wallet = if let Some ( keystore_path) = keystore_path {
479479 let password = rpassword:: prompt_password ( "Please enter your keystore password:" )
480480 . map_err ( |e| SubmitError :: GenericError ( e. to_string ( ) ) ) ?;
481481 Wallet :: decrypt_keystore ( keystore_path, password)
482482 . map_err ( |e| SubmitError :: GenericError ( e. to_string ( ) ) ) ?
483+ } else if let Some ( private_key) = private_key {
484+ private_key
485+ . parse :: < LocalWallet > ( )
486+ . map_err ( |e| SubmitError :: GenericError ( e. to_string ( ) ) ) ?
483487 } else {
484- warn ! ( "Missing keystore used for payment." ) ;
488+ warn ! ( "Missing keystore or private key used for payment." ) ;
485489 return Ok ( ( ) ) ;
486490 } ;
487491
0 commit comments