fn find_tx_by_hash(&self, hash: &[u8]) -> QueryResult<Option<TxByHashResponse>> {
        // TODO: Maybe move the transformations to api_server?
        let query_result = executed_transactions::table
            .filter(executed_transactions::tx_hash.eq(hash))
            .first::<StoredExecutedTransaction>(self.0.conn())
            .optional()?;

        if let Some(tx) = query_result {
            let block_number = tx.block_number;
            let fail_reason = tx.fail_reason.clone();
            let created_at = tx.created_at.format("%Y-%m-%dT%H:%M:%S%.6f").to_string();
            let operation = &tx.tx;

            let tx_token = operation["token"].as_i64().unwrap_or(-1);
            let tx_type = operation["type"].as_str().unwrap_or("unknown tx_type");
            let tx_amount = operation["amount"].as_str().unwrap_or("unknown amount");
            let nonce = operation["nonce"].as_i64().unwrap_or(-1);
            let (tx_from, tx_to, tx_fee) = match tx_type {
                "Withdraw" | "Transfer" | "TransferToNew" => (
                    operation["from"]
                        .as_str()
                        .unwrap_or("unknown from")
                        .to_string(),
                    operation["to"].as_str().unwrap_or("unknown to").to_string(),
                    operation["fee"].as_str().map(|v| v.to_string()),
                ),
                "ChangePubKey" | "ChangePubKeyOffchain" => (
                    operation["account"]
                        .as_str()
                        .unwrap_or("unknown from")
                        .to_string(),
                    operation["newPkHash"]
                        .as_str()
                        .unwrap_or("unknown to")
                        .to_string(),
                    None,
                ),
                &_ => (
                    "unknown from".to_string(),
                    "unknown to".to_string(),
                    Some("unknown fee".to_string()),
                ),
            };

            let tx_type_user = if tx_type == "TransferToNew" {
                "Transfer"
            } else {
                tx_type
            };

            return Ok(Some(TxByHashResponse {
                tx_type: tx_type_user.to_string(),
                from: tx_from,
                to: tx_to,
                token: tx_token as i32,
                amount: tx_amount.to_string(),
                fee: tx_fee,
                block_number,
                nonce,
                created_at,
                fail_reason,
                tx: tx.tx,
            }));
        };

        Ok(None)
    }
/// Helper method for `get_tx_by_hash` which attempts to find a transaction
/// in the list of executed operations.
Helper method for `get_tx_by_hash` which attempts to find a transaction
in the list of executed operations.
Helper method for ` get_tx_by_hash ` which attempts to find a transaction in the list of executed operations .
fn find_tx_by_hash(&self, hash: &[u8]) -> QueryResult<Option<TxByHashResponse>> {
        // TODO: Maybe move the transformations to api_server?
        let query_result = executed_transactions::table
            .filter(executed_transactions::tx_hash.eq(hash))
            .first::<StoredExecutedTransaction>(self.0.conn())
            .optional()?;
        if let Some(tx) = query_result {
            let block_number = tx.block_number;
            let fail_reason = tx.fail_reason.clone();
            let created_at = tx.created_at.format("%Y-%m-%dT%H:%M:%S%.6f").to_string();
            let operation = &tx.tx;
            let tx_token = operation["token"].as_i64().unwrap_or(-1);
            let tx_type = operation["type"].as_str().unwrap_or("unknown tx_type");
            let tx_amount = operation["amount"].as_str().unwrap_or("unknown amount");
            let nonce = operation["nonce"].as_i64().unwrap_or(-1);
            let (tx_from, tx_to, tx_fee) = match tx_type {
                "Withdraw" | "Transfer" | "TransferToNew" => (
                    operation["from"]
                        .as_str()
                        .unwrap_or("unknown from")
                        .to_string(),
                    operation["to"].as_str().unwrap_or("unknown to").to_string(),
                    operation["fee"].as_str().map(|v| v.to_string()),
                ),
                "ChangePubKey" | "ChangePubKeyOffchain" => (
                    operation["account"]
                        .as_str()
                        .unwrap_or("unknown from")
                        .to_string(),
                    operation["newPkHash"]
                        .as_str()
                        .unwrap_or("unknown to")
                        .to_string(),
                    None,
                ),
                &_ => (
                    "unknown from".to_string(),
                    "unknown to".to_string(),
                    Some("unknown fee".to_string()),
                ),
            };
            let tx_type_user = if tx_type == "TransferToNew" {
                "Transfer"
            } else {
                tx_type
            };
            return Ok(Some(TxByHashResponse {
                tx_type: tx_type_user.to_string(),
                from: tx_from,
                to: tx_to,
                token: tx_token as i32,
                amount: tx_amount.to_string(),
                fee: tx_fee,
                block_number,
                nonce,
                created_at,
                fail_reason,
                tx: tx.tx,
            }));
        };
        Ok(None)
    }
fn find_tx_by_hash ( & self , hash : & [ u8 ] ) -> QueryResult < Option < TxByHashResponse > > { // TODO: Maybe move the transformations to api_server? let query_result = executed_transactions :: table . filter ( executed_transactions :: tx_hash . eq ( hash ) ) . first :: < StoredExecutedTransaction > ( self . 0 . conn ( ) ) . optional ( ) ? ; if let Some ( tx ) = query_result { let block_number = tx . block_number ; let fail_reason = tx . fail_reason . clone ( ) ; let created_at = tx . created_at . format ( " " ) . to_string ( ) ; let operation = & tx . tx ; let tx_token = operation [ " " ] . as_i64 ( ) . unwrap_or ( - 1 ) ; let tx_type = operation [ " " ] . as_str ( ) . unwrap_or ( " " ) ; let tx_amount = operation [ " " ] . as_str ( ) . unwrap_or ( " " ) ; let nonce = operation [ " " ] . as_i64 ( ) . unwrap_or ( - 1 ) ; let ( tx_from , tx_to , tx_fee ) = match tx_type { " " | " " | " " => ( operation [ " " ] . as_str ( ) . unwrap_or ( " " ) . to_string ( ) , operation [ " " ] . as_str ( ) . unwrap_or ( " " ) . to_string ( ) , operation [ " " ] . as_str ( ) . map ( | v | v . to_string ( ) ) , ) , " " | " " => ( operation [ " " ] . as_str ( ) . unwrap_or ( " " ) . to_string ( ) , operation [ " " ] . as_str ( ) . unwrap_or ( " " ) . to_string ( ) , None , ) , & _ => ( " " . to_string ( ) , " " . to_string ( ) , Some ( " " . to_string ( ) ) , ) , } ; let tx_type_user = if tx_type == " " { " " } else { tx_type } ; return Ok ( Some ( TxByHashResponse { tx_type : tx_type_user . to_string ( ) , from : tx_from , to : tx_to , token : tx_token as i32 , amount : tx_amount . to_string ( ) , fee : tx_fee , block_number , nonce , created_at , fail_reason , tx : tx . tx , } ) ) ; } ; Ok ( None ) }
Helper method for `get_tx_by_hash` which attempts to find a transaction
in the list of executed operations.
Helper method for ` get_tx_by_hash ` which attempts to find a transaction in the list of executed operations .
&self
hash
&[u8]