fn process_get_block<'a, I: Iterator<Item = &'a str>>(&self, mut args: I) {
        // let command_arg = args.take(4).collect::<Vec<&str>>();
        let height = args.next();
        if height.is_none() {
            self.print_help("get-block".split(' '));
            return;
        }
        let height = match height.unwrap().parse::<u64>().ok() {
            Some(height) => height,
            None => {
                println!("Invalid block height provided. Height must be an integer.");
                self.print_help("get-block".split(' '));
                return;
            },
        };
        enum Format {
            Json,
            Text,
        }
        let format = match args.next() {
            Some(v) if v.to_ascii_lowercase() == "json" => Format::Json,
            Some(v) if v.to_ascii_lowercase() == "text" => Format::Text,
            None => Format::Text,
            Some(_) => {
                println!("Unrecognized format sspecifier");
                self.print_help("get-block".split(' '));
                return;
            },
        };
        let mut handler = self.node_service.clone();
        self.executor.spawn(async move {
            match handler.get_blocks(vec![height]).await {
                Err(err) => {
                    println!("Failed to retrieve blocks: {:?}", err);
                    warn!(
                        target: LOG_TARGET,
                        "Error communicating with local base node: {:?}", err,
                    );
                    return;
                },
                Ok(mut data) => match (data.pop(), format) {
                    (Some(historical_block), Format::Text) => println!("{}", historical_block.block),
                    (Some(historical_block), Format::Json) => println!(
                        "{}",
                        historical_block
                            .block
                            .to_json()
                            .unwrap_or_else(|_| "Error deserializing block".into())
                    ),
                    (None, _) => println!("Block not found at height {}", height),
                },
            };
        });
    }
/// Function to process the get-block command
Function to process the get-block command
Function to process the get - block command
fn process_get_block<'a, I: Iterator<Item = &'a str>>(&self, mut args: I) {
        // let command_arg = args.take(4).collect::<Vec<&str>>();
        let height = args.next();
        if height.is_none() {
            self.print_help("get-block".split(' '));
            return;
        }
        let height = match height.unwrap().parse::<u64>().ok() {
            Some(height) => height,
            None => {
                println!("Invalid block height provided. Height must be an integer.");
                self.print_help("get-block".split(' '));
                return;
            },
        };
        enum Format {
            Json,
            Text,
        }
        let format = match args.next() {
            Some(v) if v.to_ascii_lowercase() == "json" => Format::Json,
            Some(v) if v.to_ascii_lowercase() == "text" => Format::Text,
            None => Format::Text,
            Some(_) => {
                println!("Unrecognized format sspecifier");
                self.print_help("get-block".split(' '));
                return;
            },
        };
        let mut handler = self.node_service.clone();
        self.executor.spawn(async move {
            match handler.get_blocks(vec![height]).await {
                Err(err) => {
                    println!("Failed to retrieve blocks: {:?}", err);
                    warn!(
                        target: LOG_TARGET,
                        "Error communicating with local base node: {:?}", err,
                    );
                    return;
                },
                Ok(mut data) => match (data.pop(), format) {
                    (Some(historical_block), Format::Text) => println!("{}", historical_block.block),
                    (Some(historical_block), Format::Json) => println!(
                        "{}",
                        historical_block
                            .block
                            .to_json()
                            .unwrap_or_else(|_| "Error deserializing block".into())
                    ),
                    (None, _) => println!("Block not found at height {}", height),
                },
            };
        });
    }
fn process_get_block < ' a , I : Iterator < Item = & ' a str > > ( & self , mut args : I ) { // let command_arg = args.take(4).collect::<Vec<&str>>(); let height = args . next ( ) ; if height . is_none ( ) { self . print_help ( " " . split ( ' ' ) ) ; return ; } let height = match height . unwrap ( ) . parse :: < u64 > ( ) . ok ( ) { Some ( height ) => height , None => { println ! ( " " ) ; self . print_help ( " " . split ( ' ' ) ) ; return ; } , } ; enum Format { Json , Text , } let format = match args . next ( ) { Some ( v ) if v . to_ascii_lowercase ( ) == " " => Format :: Json , Some ( v ) if v . to_ascii_lowercase ( ) == " " => Format :: Text , None => Format :: Text , Some ( _ ) => { println ! ( " " ) ; self . print_help ( " " . split ( ' ' ) ) ; return ; } , } ; let mut handler = self . node_service . clone ( ) ; self . executor . spawn ( async move { match handler . get_blocks ( vec ! [ height ] ) . await { Err ( err ) => { println ! ( " " err ) ; warn ! ( target LOG_TARGET " " err ) ; return ; } , Ok ( mut data ) => match ( data . pop ( ) , format ) { ( Some ( historical_block ) , Format :: Text ) => println ! ( " " historical_block block ) , ( Some ( historical_block ) , Format :: Json ) => println ! ( " " historical_block block to_json ( ) unwrap_or_else ( " " into ( ) ) ) , ( None , _ ) => println ! ( " " height ) , } , } ; } ) ; }
Function to process the get-block command
Function to process the get - block command
&self
args
I
&self
args
I