1//! Transaction read ops.
2//!
3//! This module handles reading full transaction data, like getting a transaction from the pool.
4use monero_serai::transaction::Transaction;
56use cuprate_database::{DatabaseRo, DbResult};
7use cuprate_types::{TransactionVerificationData, TxVersion};
89use crate::{
10 tables::{Tables, TransactionInfos},
11 types::{TransactionHash, TxStateFlags},
12};
1314/// Gets the [`TransactionVerificationData`] of a transaction in the tx-pool, leaving the tx in the pool.
15pub fn get_transaction_verification_data(
16 tx_hash: &TransactionHash,
17 tables: &impl Tables,
18) -> DbResult<TransactionVerificationData> {
19let tx_blob = tables.transaction_blobs().get(tx_hash)?.0;
2021let tx_info = tables.transaction_infos().get(tx_hash)?;
2223let cached_verification_state = tables.cached_verification_state().get(tx_hash)?.into();
2425let tx =
26 Transaction::read(&mut tx_blob.as_slice()).expect("Tx in the tx-pool must be parseable");
2728Ok(TransactionVerificationData {
29 version: TxVersion::from_raw(tx.version()).expect("Tx in tx-pool has invalid version"),
30 tx,
31 tx_blob,
32 tx_weight: tx_info.weight,
33 fee: tx_info.fee,
34 tx_hash: *tx_hash,
35 cached_verification_state,
36 })
37}
3839/// Returns `true` if the transaction with the given hash is in the stem pool.
40///
41/// # Errors
42/// This will return an [`Err`] if the transaction is not in the pool.
43pub fn in_stem_pool(
44 tx_hash: &TransactionHash,
45 tx_infos: &impl DatabaseRo<TransactionInfos>,
46) -> DbResult<bool> {
47Ok(tx_infos
48 .get(tx_hash)?
49.flags
50 .contains(TxStateFlags::STATE_STEM))
51}