@@ -5,7 +5,7 @@ use crate::{
55 DEFAULT_MAX_FEE_BATCH_SIZE , GAS_PRICE_PERCENTAGE_MULTIPLIER ,
66 INSTANT_MAX_FEE_BATCH_SIZE , PERCENTAGE_DIVIDER ,
77 } ,
8- errors:: { self , GetNonceError } ,
8+ errors:: { self , GetNonceError , PaymentError } ,
99 types:: {
1010 AlignedVerificationData , ClientMessage , FeeEstimationType , GetNonceResponseMessage ,
1111 Network , ProvingSystemId , VerificationData ,
@@ -19,7 +19,7 @@ use crate::{
1919 } ,
2020 eth:: {
2121 aligned_service_manager:: aligned_service_manager,
22- batcher_payment_service:: batcher_payment_service,
22+ batcher_payment_service:: { batcher_payment_service, BatcherPaymentServiceWithSigner } ,
2323 } ,
2424} ;
2525
@@ -750,6 +750,73 @@ pub async fn get_balance_in_aligned(
750750 }
751751}
752752
753+ pub async fn unlock_balance_in_aligned (
754+ signer : & SignerMiddleware < Provider < Http > , LocalWallet > ,
755+ network : Network ,
756+ ) -> Result < ethers:: types:: TransactionReceipt , errors:: PaymentError > {
757+ let payment_service_address = network. get_batcher_payment_service_address ( ) ;
758+ let payment_service =
759+ BatcherPaymentServiceWithSigner :: new ( payment_service_address, signer. clone ( ) . into ( ) ) ;
760+
761+ let receipt = payment_service
762+ . unlock ( )
763+ . send ( )
764+ . await
765+ . map_err ( |e| PaymentError :: SendError ( e. to_string ( ) ) ) ?
766+ . await
767+ . map_err ( |e| PaymentError :: SubmitError ( e. to_string ( ) ) ) ?;
768+
769+ match receipt {
770+ Some ( hash) => Ok ( hash) ,
771+ None => Err ( PaymentError :: SubmitError ( "" . into ( ) ) ) ,
772+ }
773+ }
774+
775+ pub async fn lock_balance_in_aligned (
776+ signer : & SignerMiddleware < Provider < Http > , LocalWallet > ,
777+ network : Network ,
778+ ) -> Result < ethers:: types:: TransactionReceipt , errors:: PaymentError > {
779+ let payment_service_address = network. get_batcher_payment_service_address ( ) ;
780+ let payment_service =
781+ BatcherPaymentServiceWithSigner :: new ( payment_service_address, signer. clone ( ) . into ( ) ) ;
782+
783+ let receipt = payment_service
784+ . lock ( )
785+ . send ( )
786+ . await
787+ . map_err ( |e| PaymentError :: SendError ( e. to_string ( ) ) ) ?
788+ . await
789+ . map_err ( |e| PaymentError :: SubmitError ( e. to_string ( ) ) ) ?;
790+
791+ match receipt {
792+ Some ( hash) => Ok ( hash) ,
793+ None => Err ( PaymentError :: SubmitError ( "" . into ( ) ) ) ,
794+ }
795+ }
796+
797+ pub async fn withdraw_balance_from_aligned (
798+ signer : & SignerMiddleware < Provider < Http > , LocalWallet > ,
799+ network : Network ,
800+ amount : U256 ,
801+ ) -> Result < ethers:: types:: TransactionReceipt , errors:: PaymentError > {
802+ let payment_service_address = network. get_batcher_payment_service_address ( ) ;
803+ let payment_service =
804+ BatcherPaymentServiceWithSigner :: new ( payment_service_address, signer. clone ( ) . into ( ) ) ;
805+
806+ let receipt = payment_service
807+ . withdraw ( amount)
808+ . send ( )
809+ . await
810+ . map_err ( |e| PaymentError :: SendError ( e. to_string ( ) ) ) ?
811+ . await
812+ . map_err ( |e| PaymentError :: SubmitError ( e. to_string ( ) ) ) ?;
813+
814+ match receipt {
815+ Some ( hash) => Ok ( hash) ,
816+ None => Err ( PaymentError :: SubmitError ( "" . into ( ) ) ) ,
817+ }
818+ }
819+
753820/// Saves AlignedVerificationData in a file.
754821///
755822/// # Arguments
0 commit comments