fn submit_batches(
        &self,
        filename: String,
        wait: Option<Duration>,
        size_limit: usize,
    ) -> Result<Vec<String>, SawtoothClientError> {
        let mut url = format!("{}/batches", &self.url);
        if let Some(wait_time) = wait {
            url = url + &format!("?wait={}", wait_time.as_secs().to_string());
        }

        let mut batch_file = File::open(filename).map_err(|err| {
            SawtoothClientError::new_with_source("failed to open batch file", err.into())
        })?;

        let batch_list: BatchList = Message::parse_from_reader(&mut batch_file).map_err(|err| {
            SawtoothClientError::new_with_source("unable to parse file contents", err.into())
        })?;
        let len = batch_list.batches.len();
        let batch_ids = batch_list
            .batches
            .iter()
            .map(|batch| batch.header_signature.clone())
            .collect();

        let batch_lists = split_batches(batch_list, size_limit);

        let start = Instant::now();

        for list in batch_lists.into_iter() {
            let submit_list = list.write_to_bytes().map_err(|err| {
                SawtoothClientError::new_with_source(
                    "failed to get bytes from batch list",
                    err.into(),
                )
            })?;
            let mut request = Client::new()
                .post(&url)
                .header(header::CONTENT_TYPE, "application/octet-stream")
                .body(submit_list);
            if let Some(ref auth) = &self.auth {
                request = request.header("Authorization", format!("Basic {}", encode(auth)));
            }
            let response = request.send().map_err(|err| {
                SawtoothClientError::new_with_source("request failed", err.into())
            })?;
            if response.status().as_u16() == 401 {
                return Err(SawtoothClientError::new(&format!(
                    "{}, {}",
                    response.status(),
                    "failed to authenticate"
                )));
            }
            if response.status().as_u16() != 202 {
                let status = response.status();
                let msg: ErrorResponse = response.json().map_err(|err| {
                    SawtoothClientError::new_with_source(
                        "failed to deserialize error response body",
                        err.into(),
                    )
                })?;
                return Err(SawtoothClientError::new(&format!("{} {}", status, msg)));
            }
        }
        info!(
            "batches: {},  batch/sec: {}",
            len,
            if len == 0 {
                0.0f64
            } else {
                len as f64 / (((start.elapsed()).as_millis() as f64) / 1000f64)
            }
        );
        Ok(batch_ids)
    }
/// Send one or more batches to the sawtooth REST API to be submitted to the validator
Send one or more batches to the sawtooth REST API to be submitted to the validator
Send one or more batches to the sawtooth REST API to be submitted to the validator
fn submit_batches(
        &self,
        filename: String,
        wait: Option<Duration>,
        size_limit: usize,
    ) -> Result<Vec<String>, SawtoothClientError> {
        let mut url = format!("{}/batches", &self.url);
        if let Some(wait_time) = wait {
            url = url + &format!("?wait={}", wait_time.as_secs().to_string());
        }
        let mut batch_file = File::open(filename).map_err(|err| {
            SawtoothClientError::new_with_source("failed to open batch file", err.into())
        })?;
        let batch_list: BatchList = Message::parse_from_reader(&mut batch_file).map_err(|err| {
            SawtoothClientError::new_with_source("unable to parse file contents", err.into())
        })?;
        let len = batch_list.batches.len();
        let batch_ids = batch_list
            .batches
            .iter()
            .map(|batch| batch.header_signature.clone())
            .collect();
        let batch_lists = split_batches(batch_list, size_limit);
        let start = Instant::now();
        for list in batch_lists.into_iter() {
            let submit_list = list.write_to_bytes().map_err(|err| {
                SawtoothClientError::new_with_source(
                    "failed to get bytes from batch list",
                    err.into(),
                )
            })?;
            let mut request = Client::new()
                .post(&url)
                .header(header::CONTENT_TYPE, "application/octet-stream")
                .body(submit_list);
            if let Some(ref auth) = &self.auth {
                request = request.header("Authorization", format!("Basic {}", encode(auth)));
            }
            let response = request.send().map_err(|err| {
                SawtoothClientError::new_with_source("request failed", err.into())
            })?;
            if response.status().as_u16() == 401 {
                return Err(SawtoothClientError::new(&format!(
                    "{}, {}",
                    response.status(),
                    "failed to authenticate"
                )));
            }
            if response.status().as_u16() != 202 {
                let status = response.status();
                let msg: ErrorResponse = response.json().map_err(|err| {
                    SawtoothClientError::new_with_source(
                        "failed to deserialize error response body",
                        err.into(),
                    )
                })?;
                return Err(SawtoothClientError::new(&format!("{} {}", status, msg)));
            }
        }
        info!(
            "batches: {},  batch/sec: {}",
            len,
            if len == 0 {
                0.0f64
            } else {
                len as f64 / (((start.elapsed()).as_millis() as f64) / 1000f64)
            }
        );
        Ok(batch_ids)
    }
fn submit_batches ( & self , filename : String , wait : Option < Duration > , size_limit : usize , ) -> Result < Vec < String > , SawtoothClientError > { let mut url = format ! ( " " self url ) ; if let Some ( wait_time ) = wait { url = url + & format ! ( " " wait_time as_secs ( ) to_string ( ) ) ; } let mut batch_file = File :: open ( filename ) . map_err ( | err | { SawtoothClientError :: new_with_source ( " " , err . into ( ) ) } ) ? ; let batch_list : BatchList = Message :: parse_from_reader ( & mut batch_file ) . map_err ( | err | { SawtoothClientError :: new_with_source ( " " , err . into ( ) ) } ) ? ; let len = batch_list . batches . len ( ) ; let batch_ids = batch_list . batches . iter ( ) . map ( | batch | batch . header_signature . clone ( ) ) . collect ( ) ; let batch_lists = split_batches ( batch_list , size_limit ) ; let start = Instant :: now ( ) ; for list in batch_lists . into_iter ( ) { let submit_list = list . write_to_bytes ( ) . map_err ( | err | { SawtoothClientError :: new_with_source ( " " , err . into ( ) , ) } ) ? ; let mut request = Client :: new ( ) . post ( & url ) . header ( header :: CONTENT_TYPE , " " ) . body ( submit_list ) ; if let Some ( ref auth ) = & self . auth { request = request . header ( " " , format ! ( " " encode ( auth ) ) ) ; } let response = request . send ( ) . map_err ( | err | { SawtoothClientError :: new_with_source ( " " , err . into ( ) ) } ) ? ; if response . status ( ) . as_u16 ( ) == 401 { return Err ( SawtoothClientError :: new ( & format ! ( " " response status ( ) " " ) ) ) ; } if response . status ( ) . as_u16 ( ) != 202 { let status = response . status ( ) ; let msg : ErrorResponse = response . json ( ) . map_err ( | err | { SawtoothClientError :: new_with_source ( " " , err . into ( ) , ) } ) ? ; return Err ( SawtoothClientError :: new ( & format ! ( " " status msg ) ) ) ; } } info ! ( " " len if len 0 { 0.0f64 } else { len as f64 ( ( ( start elapsed ( ) ) as_millis ( ) as f64 ) 1000f64 ) } ) ; Ok ( batch_ids ) }
Send one or more batches to the sawtooth REST API to be submitted to the validator
Send one or more batches to the sawtooth REST API to be submitted to the validator
&self
filename
String
wait
Option<Duration>
size_limit
usize
&self
filename
String
wait
Option<Duration>
size_limit
usize