pub fn find_block_by_height_or_hash(&self, query: String) -> Option<BlockDetails> {
        // Adapt the SQL query based on the input data format.
        let mut where_condition = String::new();

        // If the input looks like hash, add the hash lookup part.
        if let Some(hex_query) = self.try_parse_hex(&query) {
            let hash_lookup = format!(
                " \
                or committed.tx_hash = decode('{hex_query}', 'hex') \
                or verified.tx_hash = decode('{hex_query}', 'hex') \
                or blocks.root_hash = decode('{hex_query}', 'hex') \
                ",
                hex_query = hex_query
            );

            where_condition += &hash_lookup;
        };

        // If the input can be interpreted as integer, add the block number lookup part.
        if let Ok(int_query) = query.parse::<i64>() {
            let block_lookup = format!("or blocks.number = {}", int_query);

            where_condition += &block_lookup;
        }

        // If `where` condition is empty (input doesn't look like hash or integer), no query
        // should be performed.
        if where_condition.is_empty() {
            return None;
        }

        // This query does the following:
        // - joins the `operations` and `eth_tx_hashes` (using the intermediate `eth_ops_binding` table)
        //   tables to collect the data:
        //   block number, ethereum transaction hash, action type and action creation timestamp;
        // - joins the `blocks` table with result of the join twice: once for committed operations
        //   and verified operations;
        // - takes the only block that satisfies one of the following criteria
        //   + query equals to the ETH commit transaction hash (in form of `0x00{..}00`);
        //   + query equals to the ETH verify transaction hash (in form of `0x00{..}00`);
        //   + query equals to the state hash obtained in the block (in form of `sync-bl:00{..}00`);
        //   + query equals to the number of the block.
        let sql_query = format!(
            " \
            with eth_ops as ( \
                select distinct on (block_number, action_type) \
                    operations.block_number, \
                    eth_tx_hashes.tx_hash, \
                    operations.action_type, \
                    operations.created_at, \
                    confirmed \
                from operations \
                    left join eth_ops_binding on eth_ops_binding.op_id = operations.id \
                    left join eth_tx_hashes on eth_tx_hashes.eth_op_id = eth_ops_binding.eth_op_id \
                order by block_number desc, action_type, confirmed \
            ) \
            select \
                blocks.number as block_number, \
                blocks.root_hash as new_state_root, \
                blocks.block_size as block_size, \
                committed.tx_hash as commit_tx_hash, \
                verified.tx_hash as verify_tx_hash, \
                committed.created_at as committed_at, \
                verified.created_at as verified_at \
            from blocks \
            inner join eth_ops committed on \
                committed.block_number = blocks.number and committed.action_type = 'COMMIT' \
            left join eth_ops verified on \
                verified.block_number = blocks.number and verified.action_type = 'VERIFY' and verified.confirmed = true \
            where false \
                {where_condition} \
            order by blocks.number desc \
            limit 1; \
            ",
            where_condition = where_condition
        );

        diesel::sql_query(sql_query).get_result(self.0.conn()).ok()
    }
/// Performs a database search with an uncertain query, which can be either of:
/// - Hash of commit/verify Ethereum transaction for the block.
/// - The state root hash of the block.
/// - The number of the block.
///
/// Will return `None` if the query is malformed or there is no block that matches
/// the query.
Performs a database search with an uncertain query, which can be either of:
Hash of commit/verify Ethereum transaction for the block.
The state root hash of the block.
The number of the block.

Will return `None` if the query is malformed or there is no block that matches
the query.
Performs a database search with an uncertain query which can be either of : Hash of commit / verify Ethereum transaction for the block . The state root hash of the block . The number of the block . Will return ` None ` if the query is malformed or there is no block that matches the query .
pub fn find_block_by_height_or_hash(&self, query: String) -> Option<BlockDetails> {
        // Adapt the SQL query based on the input data format.
        let mut where_condition = String::new();
        // If the input looks like hash, add the hash lookup part.
        if let Some(hex_query) = self.try_parse_hex(&query) {
            let hash_lookup = format!(
                " \
                or committed.tx_hash = decode('{hex_query}', 'hex') \
                or verified.tx_hash = decode('{hex_query}', 'hex') \
                or blocks.root_hash = decode('{hex_query}', 'hex') \
                ",
                hex_query = hex_query
            );
            where_condition += &hash_lookup;
        };
        // If the input can be interpreted as integer, add the block number lookup part.
        if let Ok(int_query) = query.parse::<i64>() {
            let block_lookup = format!("or blocks.number = {}", int_query);
            where_condition += &block_lookup;
        }
        // If `where` condition is empty (input doesn't look like hash or integer), no query
        // should be performed.
        if where_condition.is_empty() {
            return None;
        }
        // This query does the following:
        // - joins the `operations` and `eth_tx_hashes` (using the intermediate `eth_ops_binding` table)
        //   tables to collect the data:
        //   block number, ethereum transaction hash, action type and action creation timestamp;
        // - joins the `blocks` table with result of the join twice: once for committed operations
        //   and verified operations;
        // - takes the only block that satisfies one of the following criteria
        //   + query equals to the ETH commit transaction hash (in form of `0x00{..}00`);
        //   + query equals to the ETH verify transaction hash (in form of `0x00{..}00`);
        //   + query equals to the state hash obtained in the block (in form of `sync-bl:00{..}00`);
        //   + query equals to the number of the block.
        let sql_query = format!(
            " \
            with eth_ops as ( \
                select distinct on (block_number, action_type) \
                    operations.block_number, \
                    eth_tx_hashes.tx_hash, \
                    operations.action_type, \
                    operations.created_at, \
                    confirmed \
                from operations \
                    left join eth_ops_binding on eth_ops_binding.op_id = operations.id \
                    left join eth_tx_hashes on eth_tx_hashes.eth_op_id = eth_ops_binding.eth_op_id \
                order by block_number desc, action_type, confirmed \
            ) \
            select \
                blocks.number as block_number, \
                blocks.root_hash as new_state_root, \
                blocks.block_size as block_size, \
                committed.tx_hash as commit_tx_hash, \
                verified.tx_hash as verify_tx_hash, \
                committed.created_at as committed_at, \
                verified.created_at as verified_at \
            from blocks \
            inner join eth_ops committed on \
                committed.block_number = blocks.number and committed.action_type = 'COMMIT' \
            left join eth_ops verified on \
                verified.block_number = blocks.number and verified.action_type = 'VERIFY' and verified.confirmed = true \
            where false \
                {where_condition} \
            order by blocks.number desc \
            limit 1; \
            ",
            where_condition = where_condition
        );
        diesel::sql_query(sql_query).get_result(self.0.conn()).ok()
    }
pub fn find_block_by_height_or_hash ( & self , query : String ) -> Option < BlockDetails > { // Adapt the SQL query based on the input data format. let mut where_condition = String :: new ( ) ; // If the input looks like hash, add the hash lookup part. if let Some ( hex_query ) = self . try_parse_hex ( & query ) { let hash_lookup = format ! ( " \
 \
 \
 \
 " hex_query hex_query ) ; where_condition += & hash_lookup ; } ; // If the input can be interpreted as integer, add the block number lookup part. if let Ok ( int_query ) = query . parse :: < i64 > ( ) { let block_lookup = format ! ( " " int_query ) ; where_condition += & block_lookup ; } // If `where` condition is empty (input doesn't look like hash or integer), no query // should be performed. if where_condition . is_empty ( ) { return None ; } // This query does the following: // - joins the `operations` and `eth_tx_hashes` (using the intermediate `eth_ops_binding` table) //   tables to collect the data: //   block number, ethereum transaction hash, action type and action creation timestamp; // - joins the `blocks` table with result of the join twice: once for committed operations //   and verified operations; // - takes the only block that satisfies one of the following criteria //   + query equals to the ETH commit transaction hash (in form of `0x00{..}00`); //   + query equals to the ETH verify transaction hash (in form of `0x00{..}00`); //   + query equals to the state hash obtained in the block (in form of `sync-bl:00{..}00`); //   + query equals to the number of the block. let sql_query = format ! ( " \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 \
 " where_condition where_condition ) ; diesel :: sql_query ( sql_query ) . get_result ( self . 0 . conn ( ) ) . ok ( ) }
Performs a database search with an uncertain query, which can be either of:
 Hash of commit/verify Ethereum transaction for the block.
Performs a database search with an uncertain query which can be either of : Hash of commit / verify Ethereum transaction for the block .
&self
query
String