cuprate_txpool/ops/
tx_read.rs1use monero_serai::transaction::Transaction;
5
6use cuprate_database::{DatabaseRo, DbResult};
7use cuprate_types::{TransactionVerificationData, TxVersion};
8
9use crate::{
10 tables::{Tables, TransactionInfos},
11 types::{TransactionHash, TxStateFlags},
12};
13
14pub fn get_transaction_verification_data(
16 tx_hash: &TransactionHash,
17 tables: &impl Tables,
18) -> DbResult<TransactionVerificationData> {
19 let tx_blob = tables.transaction_blobs().get(tx_hash)?.0;
20
21 let tx_info = tables.transaction_infos().get(tx_hash)?;
22
23 let cached_verification_state = tables.cached_verification_state().get(tx_hash)?.into();
24
25 let tx =
26 Transaction::read(&mut tx_blob.as_slice()).expect("Tx in the tx-pool must be parseable");
27
28 Ok(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}
38
39pub fn in_stem_pool(
44 tx_hash: &TransactionHash,
45 tx_infos: &impl DatabaseRo<TransactionInfos>,
46) -> DbResult<bool> {
47 Ok(tx_infos
48 .get(tx_hash)?
49 .flags
50 .contains(TxStateFlags::STATE_STEM))
51}