@@ -19,6 +19,7 @@ use aligned_sdk::verification_layer::estimate_fee;
1919use aligned_sdk:: verification_layer:: get_chain_id;
2020use aligned_sdk:: verification_layer:: get_nonce_from_batcher;
2121use aligned_sdk:: verification_layer:: get_nonce_from_ethereum;
22+ use aligned_sdk:: verification_layer:: lock_balance_in_aligned;
2223use aligned_sdk:: verification_layer:: unlock_balance_in_aligned;
2324use aligned_sdk:: verification_layer:: withdraw_balance_from_aligned;
2425use aligned_sdk:: verification_layer:: { deposit_to_aligned, get_balance_in_aligned} ;
@@ -43,6 +44,7 @@ use crate::AlignedCommands::GetUserBalance;
4344use crate :: AlignedCommands :: GetUserNonce ;
4445use crate :: AlignedCommands :: GetUserNonceFromEthereum ;
4546use crate :: AlignedCommands :: GetVkCommitment ;
47+ use crate :: AlignedCommands :: LockFunds ;
4648use crate :: AlignedCommands :: Submit ;
4749use crate :: AlignedCommands :: UnlockFunds ;
4850use crate :: AlignedCommands :: VerifyProofOnchain ;
@@ -70,7 +72,9 @@ pub enum AlignedCommands {
7072 ) ]
7173 DepositToBatcher ( DepositToBatcherArgs ) ,
7274 #[ clap( about = "Unlocks funds from the batcher" , name = "unlock-funds" ) ]
73- UnlockFunds ( UnlockFundsArgs ) ,
75+ UnlockFunds ( LockUnlockFundsArgs ) ,
76+ #[ clap( about = "Lock funds in the batcher" , name = "unlock-funds" ) ]
77+ LockFunds ( LockUnlockFundsArgs ) ,
7478 #[ clap( about = "Withdraw funds from the batcher" , name = "withdraw-funds" ) ]
7579 WithdrawFunds ( WithdrawFundsArgs ) ,
7680 #[ clap( about = "Get user balance from the batcher" , name = "get-user-balance" ) ]
@@ -218,7 +222,7 @@ pub struct DepositToBatcherArgs {
218222
219223#[ derive( Parser , Debug ) ]
220224#[ command( version, about, long_about = None ) ]
221- pub struct UnlockFundsArgs {
225+ pub struct LockUnlockFundsArgs {
222226 #[ command( flatten) ]
223227 private_key_type : PrivateKeyType ,
224228 #[ arg(
@@ -836,6 +840,50 @@ async fn main() -> Result<(), AlignedError> {
836840 }
837841 }
838842 }
843+ LockFunds ( args) => {
844+ let eth_rpc_url = args. eth_rpc_url ;
845+ let eth_rpc_provider =
846+ Provider :: < Http > :: try_from ( eth_rpc_url. clone ( ) ) . map_err ( |e| {
847+ SubmitError :: EthereumProviderError ( format ! (
848+ "Error while connecting to Ethereum: {}" ,
849+ e
850+ ) )
851+ } ) ?;
852+
853+ let keystore_path = & args. private_key_type . keystore_path ;
854+ let private_key = & args. private_key_type . private_key ;
855+
856+ let mut wallet = if let Some ( keystore_path) = keystore_path {
857+ let password = rpassword:: prompt_password ( "Please enter your keystore password:" )
858+ . map_err ( |e| SubmitError :: GenericError ( e. to_string ( ) ) ) ?;
859+ Wallet :: decrypt_keystore ( keystore_path, password)
860+ . map_err ( |e| SubmitError :: GenericError ( e. to_string ( ) ) ) ?
861+ } else if let Some ( private_key) = private_key {
862+ private_key
863+ . parse :: < LocalWallet > ( )
864+ . map_err ( |e| SubmitError :: GenericError ( e. to_string ( ) ) ) ?
865+ } else {
866+ warn ! ( "Missing keystore or private key used for payment." ) ;
867+ return Ok ( ( ) ) ;
868+ } ;
869+
870+ let chain_id = get_chain_id ( eth_rpc_url. as_str ( ) ) . await ?;
871+ wallet = wallet. with_chain_id ( chain_id) ;
872+
873+ let client = SignerMiddleware :: new ( eth_rpc_provider, wallet) ;
874+
875+ match lock_balance_in_aligned ( & client, args. network . into ( ) ) . await {
876+ Ok ( receipt) => {
877+ info ! (
878+ "Funds in batcher locked successfully. Receipt: 0x{:x}" ,
879+ receipt. transaction_hash
880+ ) ;
881+ }
882+ Err ( e) => {
883+ error ! ( "Transaction failed: {:?}" , e) ;
884+ }
885+ }
886+ }
839887 WithdrawFunds ( args) => {
840888 if !args. amount . ends_with ( "ether" ) {
841889 error ! ( "Amount should be in the format XX.XXether" ) ;
0 commit comments