Adds a `TransactionIdForSpentOutPoint` ReadRequest and a `TransactionId` ReadResponse
This commit is contained in:
parent
445a929efb
commit
00b2eef74d
|
@ -1020,6 +1020,12 @@ pub enum ReadRequest {
|
|||
height_range: RangeInclusive<block::Height>,
|
||||
},
|
||||
|
||||
/// Looks up a spending transaction id by its spent transparent input.
|
||||
///
|
||||
/// Returns [`ReadResponse::TransactionId`] with the hash of the transaction
|
||||
/// that spent the output at the provided [`transparent::OutPoint`].
|
||||
TransactionIdForSpentOutPoint(transparent::OutPoint),
|
||||
|
||||
/// Looks up utxos for the provided addresses.
|
||||
///
|
||||
/// Returns a type with found utxos and transaction information.
|
||||
|
@ -1100,6 +1106,7 @@ impl ReadRequest {
|
|||
ReadRequest::OrchardSubtrees { .. } => "orchard_subtrees",
|
||||
ReadRequest::AddressBalance { .. } => "address_balance",
|
||||
ReadRequest::TransactionIdsByAddresses { .. } => "transaction_ids_by_addesses",
|
||||
ReadRequest::TransactionIdForSpentOutPoint { .. } => "transaction_id_by_spent_outpoint",
|
||||
ReadRequest::UtxosByAddresses(_) => "utxos_by_addesses",
|
||||
ReadRequest::CheckBestChainTipNullifiersAndAnchors(_) => {
|
||||
"best_chain_tip_nullifiers_anchors"
|
||||
|
|
|
@ -175,6 +175,11 @@ pub enum ReadResponse {
|
|||
/// or `None` if the block was not found.
|
||||
TransactionIdsForBlock(Option<Arc<[transaction::Hash]>>),
|
||||
|
||||
/// Response to [`ReadRequest::TransactionIdForSpentOutPoint`],
|
||||
/// with an list of transaction hashes in block order,
|
||||
/// or `None` if the block was not found.
|
||||
TransactionId(Option<transaction::Hash>),
|
||||
|
||||
/// Response to [`ReadRequest::BlockLocator`] with a block locator object.
|
||||
BlockLocator(Vec<block::Hash>),
|
||||
|
||||
|
@ -339,6 +344,7 @@ impl TryFrom<ReadResponse> for Response {
|
|||
| ReadResponse::OrchardSubtrees(_)
|
||||
| ReadResponse::AddressBalance(_)
|
||||
| ReadResponse::AddressesTransactionIds(_)
|
||||
| ReadResponse::TransactionId(_)
|
||||
| ReadResponse::AddressUtxos(_) => {
|
||||
Err("there is no corresponding Response for this ReadResponse")
|
||||
}
|
||||
|
|
|
@ -1383,6 +1383,34 @@ impl Service<ReadRequest> for ReadStateService {
|
|||
.wait_for_panics()
|
||||
}
|
||||
|
||||
ReadRequest::TransactionIdForSpentOutPoint(outpoint) => {
|
||||
let state = self.clone();
|
||||
|
||||
tokio::task::spawn_blocking(move || {
|
||||
span.in_scope(move || {
|
||||
let spending_transaction_id = state
|
||||
.non_finalized_state_receiver
|
||||
.with_watch_data(|non_finalized_state| {
|
||||
read::spending_transaction_hash(
|
||||
non_finalized_state.best_chain(),
|
||||
&state.db,
|
||||
outpoint,
|
||||
)
|
||||
});
|
||||
|
||||
// The work is done in the future.
|
||||
timer.finish(
|
||||
module_path!(),
|
||||
line!(),
|
||||
"ReadRequest::TransactionIdForSpentOutPoint",
|
||||
);
|
||||
|
||||
Ok(ReadResponse::TransactionId(spending_transaction_id))
|
||||
})
|
||||
})
|
||||
.wait_for_panics()
|
||||
}
|
||||
|
||||
ReadRequest::UnspentBestChainUtxo(outpoint) => {
|
||||
let state = self.clone();
|
||||
|
||||
|
|
Loading…
Reference in New Issue