@@ -10,10 +10,10 @@ use crate::{
1010 ADDITIONAL_SUBMISSION_GAS_COST_PER_PROOF , CONSTANT_GAS_COST ,
1111 MAX_FEE_BATCH_PROOF_NUMBER , MAX_FEE_DEFAULT_PROOF_NUMBER ,
1212 } ,
13- errors:: { self , GetNonceError } ,
13+ errors:: { self , BumpError , GetNonceError } ,
1414 types:: {
15- AlignedVerificationData , ClientMessage , GetNonceResponseMessage , Network ,
16- PriceEstimate , ProvingSystemId , VerificationData ,
15+ AlignedVerificationData , BumpFeeResponseMessage , BumpUnit , ClientMessage ,
16+ GetNonceResponseMessage , Network , PriceEstimate , ProvingSystemId , VerificationData ,
1717 } ,
1818 } ,
1919 eth:: {
@@ -466,6 +466,64 @@ pub async fn submit(
466466 }
467467}
468468
469+ pub async fn bump_user_fees (
470+ network : Network ,
471+ bump_unit : BumpUnit ,
472+ bump_amount : U256 ,
473+ proof_qty : usize , // Number of proofs to bump fees, from oldest to newest
474+ // maybe also i will need a signature here
475+ ) -> Result < ( ) , errors:: BumpError > {
476+ // let batcher_url = network.get_batcher_url(); // This is in a PR
477+ let batcher_url = "network.get_batcher_url()" ;
478+ // let (ws_stream, _) = match connect_async(batcher_url).await {
479+ // Ok((ws_stream, response)) => (ws_stream, response),
480+ // Err(e) => return Err(BumpError::WebSocketConnectionError(e)),
481+ // };
482+ let ( ws_stream, _) = connect_async ( batcher_url)
483+ . await
484+ . map_err ( |e| BumpError :: WebSocketConnectionError ( e) ) ?;
485+ debug ! ( "WebSocket handshake has been successfully completed" ) ;
486+ let ( mut ws_write, ws_read) = ws_stream. split ( ) ;
487+
488+ let msg = ClientMessage :: BumpFee ( bump_unit, bump_amount, proof_qty) ;
489+
490+ let msg_bin = cbor_serialize ( & msg)
491+ . map_err ( |_| BumpError :: SerializationError ( "Failed to serialize msg" . to_string ( ) ) ) ?;
492+
493+ ws_write
494+ . send ( Message :: Binary ( msg_bin. clone ( ) ) )
495+ . await
496+ . map_err ( |_| {
497+ BumpError :: ConnectionFailed (
498+ "Ws connection failed to send message to batcher" . to_string ( ) ,
499+ )
500+ } ) ?;
501+
502+ let mut response_stream: ResponseStream =
503+ ws_read. try_filter ( |msg| futures_util:: future:: ready ( msg. is_binary ( ) ) ) ;
504+
505+ let response_msg = match response_stream. next ( ) . await {
506+ Some ( Ok ( msg) ) => msg,
507+ _ => {
508+ return Err ( BumpError :: ConnectionFailed (
509+ "Connection was closed without close message before receiving all messages"
510+ . to_string ( ) ,
511+ ) ) ;
512+ }
513+ } ;
514+
515+ let _ = ws_write. close ( ) . await ;
516+
517+ match cbor_deserialize ( response_msg. into_data ( ) . as_slice ( ) ) {
518+ Ok ( BumpFeeResponseMessage :: Ok ( ) ) => Ok ( ( ) ) ,
519+ Ok ( BumpFeeResponseMessage :: EthRpcError ( e) ) => Err ( BumpError :: EthRpcError ( e) ) ,
520+ Ok ( BumpFeeResponseMessage :: InvalidRequest ( e) ) => Err ( BumpError :: InvalidRequest ( e) ) ,
521+ Err ( _) => Err ( BumpError :: SerializationError (
522+ "Failed to deserialize batcher response message" . to_string ( ) ,
523+ ) ) ,
524+ }
525+ }
526+
469527/// Checks if the proof has been verified with Aligned and is included in the batch.
470528/// # Arguments
471529/// * `aligned_verification_data` - The aligned verification data obtained when submitting the proofs.
0 commit comments