Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115590
D13768.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D13768.diff
View Options
diff --git a/chronik/chronik-indexer/src/query/txs.rs b/chronik/chronik-indexer/src/query/txs.rs
--- a/chronik/chronik-indexer/src/query/txs.rs
+++ b/chronik/chronik-indexer/src/query/txs.rs
@@ -4,8 +4,6 @@
//! Module for [`QueryTxs`], to query txs from mempool/db.
-use std::borrow::Cow;
-
use abc_rust_error::{Result, WrapErr};
use bitcoinsuite_core::tx::{Tx, TxId};
use chronik_bridge::ffi;
@@ -51,40 +49,37 @@
impl<'a> QueryTxs<'a> {
/// Query a tx by txid from the mempool or DB.
pub fn tx_by_id(&self, txid: TxId) -> Result<proto::Tx> {
- let (tx, time_first_seen, is_coinbase, block) =
- match self.mempool.tx(&txid) {
- Some(tx) => {
- (Cow::Borrowed(&tx.tx), tx.time_first_seen, false, None)
- }
- None => {
- let tx_reader = TxReader::new(self.db)?;
- let block_tx =
- tx_reader.tx_by_txid(&txid)?.ok_or(TxNotFound(txid))?;
- let tx_entry = block_tx.entry;
- let block_reader = BlockReader::new(self.db)?;
- let block = block_reader
- .by_height(block_tx.block_height)?
- .ok_or(DbTxHasNoBlock(txid))?;
- let tx = ffi::load_tx(
- block.file_num,
- tx_entry.data_pos,
- tx_entry.undo_pos,
- )
- .wrap_err(ReadFailure(txid))?;
- (
- Cow::Owned(Tx::from(tx)),
- tx_entry.time_first_seen,
- tx_entry.is_coinbase,
- Some(block),
- )
- }
- };
- Ok(make_tx_proto(
- &tx,
- time_first_seen,
- is_coinbase,
- block.as_ref(),
- self.avalanche,
- ))
+ match self.mempool.tx(&txid) {
+ Some(tx) => Ok(make_tx_proto(
+ &tx.tx,
+ tx.time_first_seen,
+ false,
+ None,
+ self.avalanche,
+ )),
+ None => {
+ let tx_reader = TxReader::new(self.db)?;
+ let block_tx =
+ tx_reader.tx_by_txid(&txid)?.ok_or(TxNotFound(txid))?;
+ let tx_entry = block_tx.entry;
+ let block_reader = BlockReader::new(self.db)?;
+ let block = block_reader
+ .by_height(block_tx.block_height)?
+ .ok_or(DbTxHasNoBlock(txid))?;
+ let tx = ffi::load_tx(
+ block.file_num,
+ tx_entry.data_pos,
+ tx_entry.undo_pos,
+ )
+ .wrap_err(ReadFailure(txid))?;
+ Ok(make_tx_proto(
+ &Tx::from(tx),
+ tx_entry.time_first_seen,
+ tx_entry.is_coinbase,
+ Some(&block),
+ self.avalanche,
+ ))
+ }
+ }
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 11:28 (9 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5184258
Default Alt Text
D13768.diff (3 KB)
Attached To
D13768: [Chronik] Refactor `QueryTxs::tx_by_id`: remove Cow etc.
Event Timeline
Log In to Comment