spark_rust/wallet/internal_handlers/implementations/
mempool.rs

1use crate::{
2    error::SparkSdkError,
3    signer::traits::SparkSigner,
4    wallet::{
5        internal_handlers::traits::mempool::MempoolInternalHandlers, mempool::MempoolClient,
6        utils::bitcoin::bitcoin_tx_from_hex,
7    },
8    SparkSdk,
9};
10use tonic::async_trait;
11
12#[async_trait]
13impl<S: SparkSigner + Send + Sync> MempoolInternalHandlers for SparkSdk<S> {
14    #[cfg_attr(feature = "telemetry", tracing::instrument(skip_all))]
15    async fn query_mempool_transaction_by_txid(
16        &self,
17        txid: String,
18    ) -> Result<bitcoin::Transaction, SparkSdkError> {
19        let network = self.config.spark_config.network;
20
21        let client = MempoolClient::new()?;
22        let tx_hex = client
23            .request_text(network, &format!("tx/{}/hex", txid))
24            .await?;
25
26        // Verify tx_hex is a valid hex string
27        let tx = bitcoin_tx_from_hex(&tx_hex)?;
28
29        Ok(tx)
30    }
31}