Skip to content

Commit

Permalink
make compute_txid available on elements::Transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
RCasatta committed Jan 14, 2025
1 parent e497577 commit 67b465b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/elements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
4 changes: 2 additions & 2 deletions src/new_index/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Query {
}

pub fn lookup_tx_spends(&self, tx: Transaction) -> Vec<Option<SpendingInput>> {
let txid = tx.txid();
let txid = tx.compute_txid();

tx.output
.par_iter()
Expand Down
8 changes: 4 additions & 4 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -983,7 +983,7 @@ fn add_blocks(block_entries: &[BlockEntry], iconfig: &IndexerConfig) -> Vec<DBRo
.map(|b| {
let mut rows = vec![];
let blockhash = full_hash(&b.entry.hash()[..]);
let txids: Vec<Txid> = b.block.txdata.iter().map(|tx| tx.txid()).collect();
let txids: Vec<Txid> = 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);
}
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 67b465b

Please sign in to comment.