Skip to content

Commit 67b465b

Browse files
committed
make compute_txid available on elements::Transaction
1 parent e497577 commit 67b465b

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/elements/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,13 @@ pub mod ebcompact {
9494
self.is_v1_p2tr()
9595
}
9696
}
97+
98+
pub trait TxidCompat {
99+
fn compute_txid(&self) -> elements::Txid;
100+
}
101+
impl TxidCompat for elements::Transaction {
102+
fn compute_txid(&self) -> elements::Txid {
103+
self.txid()
104+
}
105+
}
97106
}

src/new_index/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::util::{is_spendable, BlockId, Bytes, TransactionStatus};
1414
#[cfg(feature = "liquid")]
1515
use crate::{
1616
chain::AssetId,
17-
elements::{lookup_asset, AssetRegistry, AssetSorting, LiquidAsset},
17+
elements::{ebcompact::TxidCompat, lookup_asset, AssetRegistry, AssetSorting, LiquidAsset},
1818
};
1919

2020
const FEE_ESTIMATES_TTL: u64 = 60; // seconds
@@ -133,7 +133,7 @@ impl Query {
133133
}
134134

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

138138
tx.output
139139
.par_iter()

src/new_index/schema.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::new_index::db::{DBFlush, DBRow, ReverseScanIterator, ScanIterator, DB
3737
use crate::new_index::fetch::{start_fetcher, BlockEntry, FetchFrom};
3838

3939
#[cfg(feature = "liquid")]
40-
use crate::elements::{asset, peg};
40+
use crate::elements::{asset, ebcompact::TxidCompat, peg};
4141

4242
#[cfg(feature = "liquid")]
4343
use elements::encode::VarInt;
@@ -836,7 +836,7 @@ impl ChainQuery {
836836
let _timer = self.start_timer("lookup_txn");
837837
self.lookup_raw_txn(txid, blockhash).map(|rawtx| {
838838
let txn: Transaction = deserialize(&rawtx).expect("failed to parse Transaction");
839-
assert_eq!(*txid, txn.txid());
839+
assert_eq!(*txid, txn.compute_txid());
840840
txn
841841
})
842842
}
@@ -983,7 +983,7 @@ fn add_blocks(block_entries: &[BlockEntry], iconfig: &IndexerConfig) -> Vec<DBRo
983983
.map(|b| {
984984
let mut rows = vec![];
985985
let blockhash = full_hash(&b.entry.hash()[..]);
986-
let txids: Vec<Txid> = b.block.txdata.iter().map(|tx| tx.txid()).collect();
986+
let txids: Vec<Txid> = b.block.txdata.iter().map(|tx| tx.compute_txid()).collect();
987987
for (tx, txid) in b.block.txdata.iter().zip(txids.iter()) {
988988
add_transaction(*txid, tx, blockhash, &mut rows, iconfig);
989989
}
@@ -1089,7 +1089,7 @@ fn index_transaction(
10891089
// H{funding-scripthash}{spending-height}S{spending-txid:vin}{funding-txid:vout} → ""
10901090
// persist "edges" for fast is-this-TXO-spent check
10911091
// S{funding-txid:vout}{spending-txid:vin} → ""
1092-
let txid = full_hash(&tx.txid()[..]);
1092+
let txid = full_hash(&tx.compute_txid()[..]);
10931093
for (txo_index, txo) in tx.output.iter().enumerate() {
10941094
if is_spendable(txo) || iconfig.index_unspendables {
10951095
let history = TxHistoryRow::new(

src/rest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl TransactionValue {
158158
let weight = weight.to_wu();
159159

160160
TransactionValue {
161-
txid: tx.txid(),
161+
txid: tx.compute_txid(),
162162
#[cfg(not(feature = "liquid"))]
163163
version: tx.version.0 as u32,
164164
#[cfg(feature = "liquid")]

0 commit comments

Comments
 (0)