diff --git a/src/elements/mod.rs b/src/elements/mod.rs index 34b08f839..e0d044c2b 100644 --- a/src/elements/mod.rs +++ b/src/elements/mod.rs @@ -94,4 +94,13 @@ pub mod ebcompact { self.is_v1_p2tr() } } + + pub trait TxidCompat { + fn compute_txid(&self) -> elements::Txid; + } + impl TxidCompat for elements::Transaction { + fn compute_txid(&self) -> elements::Txid { + self.txid() + } + } } diff --git a/src/new_index/query.rs b/src/new_index/query.rs index 26d983734..140658570 100644 --- a/src/new_index/query.rs +++ b/src/new_index/query.rs @@ -14,7 +14,7 @@ use crate::util::{is_spendable, BlockId, Bytes, TransactionStatus}; #[cfg(feature = "liquid")] use crate::{ chain::AssetId, - elements::{lookup_asset, AssetRegistry, AssetSorting, LiquidAsset}, + elements::{ebcompact::TxidCompat, lookup_asset, AssetRegistry, AssetSorting, LiquidAsset}, }; const FEE_ESTIMATES_TTL: u64 = 60; // seconds @@ -133,7 +133,7 @@ impl Query { } pub fn lookup_tx_spends(&self, tx: Transaction) -> Vec> { - let txid = tx.txid(); + let txid = tx.compute_txid(); tx.output .par_iter() diff --git a/src/new_index/schema.rs b/src/new_index/schema.rs index 600ebae95..138ec0a5b 100644 --- a/src/new_index/schema.rs +++ b/src/new_index/schema.rs @@ -37,7 +37,7 @@ use crate::new_index::db::{DBFlush, DBRow, ReverseScanIterator, ScanIterator, DB use crate::new_index::fetch::{start_fetcher, BlockEntry, FetchFrom}; #[cfg(feature = "liquid")] -use crate::elements::{asset, peg}; +use crate::elements::{asset, ebcompact::TxidCompat, peg}; #[cfg(feature = "liquid")] use elements::encode::VarInt; @@ -836,7 +836,7 @@ impl ChainQuery { let _timer = self.start_timer("lookup_txn"); self.lookup_raw_txn(txid, blockhash).map(|rawtx| { let txn: Transaction = deserialize(&rawtx).expect("failed to parse Transaction"); - assert_eq!(*txid, txn.txid()); + assert_eq!(*txid, txn.compute_txid()); txn }) } @@ -983,7 +983,7 @@ fn add_blocks(block_entries: &[BlockEntry], iconfig: &IndexerConfig) -> Vec = b.block.txdata.iter().map(|tx| tx.txid()).collect(); + let txids: Vec = b.block.txdata.iter().map(|tx| tx.compute_txid()).collect(); for (tx, txid) in b.block.txdata.iter().zip(txids.iter()) { add_transaction(*txid, tx, blockhash, &mut rows, iconfig); } @@ -1089,7 +1089,7 @@ fn index_transaction( // H{funding-scripthash}{spending-height}S{spending-txid:vin}{funding-txid:vout} → "" // persist "edges" for fast is-this-TXO-spent check // S{funding-txid:vout}{spending-txid:vin} → "" - let txid = full_hash(&tx.txid()[..]); + let txid = full_hash(&tx.compute_txid()[..]); for (txo_index, txo) in tx.output.iter().enumerate() { if is_spendable(txo) || iconfig.index_unspendables { let history = TxHistoryRow::new( diff --git a/src/rest.rs b/src/rest.rs index 9b82e01d0..ca94afa68 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -158,7 +158,7 @@ impl TransactionValue { let weight = weight.to_wu(); TransactionValue { - txid: tx.txid(), + txid: tx.compute_txid(), #[cfg(not(feature = "liquid"))] version: tx.version.0 as u32, #[cfg(feature = "liquid")]