adds a `spending_transaction_hash()` read fn for the new column family
This commit is contained in:
parent
5281565713
commit
445a929efb
|
@ -68,8 +68,7 @@ impl ZebraDb {
|
||||||
|
|
||||||
/// Returns the [`TransactionLocation`] for a transaction that spent the output
|
/// Returns the [`TransactionLocation`] for a transaction that spent the output
|
||||||
/// at the provided [`OutputLocation`], if it is in the finalized state.
|
/// at the provided [`OutputLocation`], if it is in the finalized state.
|
||||||
#[allow(clippy::unwrap_in_result)]
|
pub fn tx_location_by_spent_output_location(
|
||||||
pub fn tx_loc_by_spent_output_loc(
|
|
||||||
&self,
|
&self,
|
||||||
output_location: &OutputLocation,
|
output_location: &OutputLocation,
|
||||||
) -> Option<TransactionLocation> {
|
) -> Option<TransactionLocation> {
|
||||||
|
@ -123,6 +122,15 @@ impl ZebraDb {
|
||||||
self.utxo_by_location(output_location)
|
self.utxo_by_location(output_location)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the [`transaction::Hash`] of the transaction that spent the given
|
||||||
|
/// [`transparent::OutPoint`], if it is unspent in the finalized state.
|
||||||
|
pub fn spending_tx_id(&self, outpoint: &transparent::OutPoint) -> Option<transaction::Hash> {
|
||||||
|
let output_location = self.output_location(outpoint)?;
|
||||||
|
let spending_tx_location = self.tx_location_by_spent_output_location(&output_location)?;
|
||||||
|
|
||||||
|
self.transaction_hash(spending_tx_location)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the transparent output for an [`OutputLocation`],
|
/// Returns the transparent output for an [`OutputLocation`],
|
||||||
/// if it is unspent in the finalized state.
|
/// if it is unspent in the finalized state.
|
||||||
#[allow(clippy::unwrap_in_result)]
|
#[allow(clippy::unwrap_in_result)]
|
||||||
|
|
|
@ -1256,11 +1256,15 @@ impl Chain {
|
||||||
///
|
///
|
||||||
/// UTXOs are returned regardless of whether they have been spent.
|
/// UTXOs are returned regardless of whether they have been spent.
|
||||||
pub fn created_utxo(&self, outpoint: &transparent::OutPoint) -> Option<transparent::Utxo> {
|
pub fn created_utxo(&self, outpoint: &transparent::OutPoint) -> Option<transparent::Utxo> {
|
||||||
if let Some(utxo) = self.created_utxos.get(outpoint) {
|
self.created_utxos
|
||||||
return Some(utxo.utxo.clone());
|
.get(outpoint)
|
||||||
}
|
.map(|utxo| utxo.utxo.clone())
|
||||||
|
}
|
||||||
|
|
||||||
None
|
/// Returns the [`transaction::Hash`] of the transaction that spent the given
|
||||||
|
/// [`transparent::OutPoint`], if it was spent by this chain.
|
||||||
|
pub fn spending_tx_id(&self, outpoint: &transparent::OutPoint) -> Option<transaction::Hash> {
|
||||||
|
self.spent_utxos.get(outpoint).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Address index queries
|
// Address index queries
|
||||||
|
|
|
@ -31,7 +31,8 @@ pub use address::{
|
||||||
utxo::{address_utxos, AddressUtxos},
|
utxo::{address_utxos, AddressUtxos},
|
||||||
};
|
};
|
||||||
pub use block::{
|
pub use block::{
|
||||||
any_utxo, block, block_header, mined_transaction, transaction_hashes_for_block, unspent_utxo,
|
any_utxo, block, block_header, mined_transaction, spending_transaction_hash,
|
||||||
|
transaction_hashes_for_block, unspent_utxo,
|
||||||
};
|
};
|
||||||
pub use find::{
|
pub use find::{
|
||||||
best_tip, block_locator, depth, finalized_state_contains_block_hash, find_chain_hashes,
|
best_tip, block_locator, depth, finalized_state_contains_block_hash, find_chain_hashes,
|
||||||
|
|
|
@ -181,6 +181,22 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the [`Hash`](transaction::Hash) of the transaction that spent an output at
|
||||||
|
/// the provided [`transparent::OutPoint`], if it exists and is spent in the non-finalized
|
||||||
|
/// `chain` or finalized `db`.
|
||||||
|
pub fn spending_transaction_hash<C>(
|
||||||
|
chain: Option<C>,
|
||||||
|
db: &ZebraDb,
|
||||||
|
outpoint: transparent::OutPoint,
|
||||||
|
) -> Option<transaction::Hash>
|
||||||
|
where
|
||||||
|
C: AsRef<Chain>,
|
||||||
|
{
|
||||||
|
chain
|
||||||
|
.and_then(|chain| chain.as_ref().spending_tx_id(&outpoint))
|
||||||
|
.or_else(|| db.spending_tx_id(&outpoint))
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the [`Utxo`] for [`transparent::OutPoint`], if it exists in any chain
|
/// Returns the [`Utxo`] for [`transparent::OutPoint`], if it exists in any chain
|
||||||
/// in the `non_finalized_state`, or in the finalized `db`.
|
/// in the `non_finalized_state`, or in the finalized `db`.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue