rrelayer_core 0.7.0

Core types and functionality for rrelayer - a powerful blockchain transaction relay service
Documentation
use std::sync::Arc;

use super::{
    cache::{get_transaction_cache, set_transaction_cache},
    types::{Transaction, TransactionId},
};
use crate::{
    postgres::{PostgresClient, PostgresError},
    shared::cache::Cache,
};

pub async fn get_transaction_by_id(
    cache: &Arc<Cache>,
    db: &PostgresClient,
    id: TransactionId,
) -> Result<Option<Transaction>, PostgresError> {
    if let Some(cached_transaction) = get_transaction_cache(cache, &id).await {
        return Ok(Some(cached_transaction));
    }

    let transaction = db.get_transaction(&id).await?;

    set_transaction_cache(cache, &id, &transaction).await;

    Ok(transaction)
}