use crate::api::{BitcoinDB, ConnectedBlock, ConnectedBlockIter, ConnectedTx, Txid};
use crate::parser::errors::{OpError, OpResult};
impl BitcoinDB {
pub fn get_connected_block<T: ConnectedBlock>(&self, height: usize) -> OpResult<T> {
if !self.tx_db.is_open() {
return Err(OpError::from("TxDB not open"));
}
let tx = self.get_block(height)?;
T::connect(tx, &self.tx_db, &self.block_index, &self.blk_file)
}
pub fn get_connected_transaction<T: ConnectedTx>(&self, txid: &Txid) -> OpResult<T> {
if !self.tx_db.is_open() {
return Err(OpError::from("TxDB not open"));
}
let tx = self.get_transaction(txid)?;
T::connect(tx, &self.tx_db, &self.block_index, &self.blk_file)
}
pub fn iter_connected_block<TBlock>(&self, end: usize) -> ConnectedBlockIter<TBlock>
where
TBlock: 'static + ConnectedBlock + Send,
{
ConnectedBlockIter::new(self, end)
}
}