async fn query_coinbase_transaction(
        &mut self,
        signature: Signature,
        completed_tx: CompletedTransaction,
        client: &mut BaseNodeWalletRpcClient,
    ) -> Result<(bool, Option<u64>), TransactionServiceProtocolError> {
        trace!(
            target: LOG_TARGET,
            "Querying status for coinbase transaction (TxId: {})",
            self.tx_id,
        );
        let response = match client.transaction_query(signature.into()).await {
            Ok(r) => match TxQueryResponse::try_from(r) {
                Ok(r) => r,
                Err(_) => {
                    trace!(
                        target: LOG_TARGET,
                        "Could not convert proto TxQueryResponse for coinbase transaction (TxId: {})",
                        self.tx_id,
                    );
                    return Ok((false, None));
                },
            },
            Err(e) => {
                error!(
                    target: LOG_TARGET,
                    "Coinbase transaction Query RPC Call to Base Node failed for coinbase transaction (TxId: {}): {}",
                    self.tx_id,
                    e
                );
                return Ok((false, None));
            },
        };

        if !(response.is_synced ||
            response.location == TxLocation::Mined &&
                response.confirmations >= self.resources.config.num_confirmations_required)
        {
            info!(
                target: LOG_TARGET,
                "Base Node reports not being synced, coinbase monitoring will be retried."
            );
            return Ok((false, Some(response.height_of_longest_chain)));
        }

        // Mined?
        if response.location == TxLocation::Mined {
            if response.confirmations >= self.resources.config.num_confirmations_required {
                info!(
                    target: LOG_TARGET,
                    "Coinbase transaction (TxId: {}) detected as mined and CONFIRMED with {} confirmations",
                    self.tx_id,
                    response.confirmations
                );
                self.resources
                    .output_manager_service
                    .confirm_transaction(
                        self.tx_id,
                        completed_tx.transaction.body.inputs().clone(),
                        completed_tx.transaction.body.outputs().clone(),
                    )
                    .await
                    .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;

                self.resources
                    .db
                    .confirm_broadcast_or_coinbase_transaction(self.tx_id)
                    .await
                    .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;

                let _ = self
                    .resources
                    .event_publisher
                    .send(Arc::new(TransactionEvent::TransactionMined(self.tx_id)))
                    .map_err(|e| {
                        trace!(
                            target: LOG_TARGET,
                            "Error sending event because there are no subscribers: {:?}",
                            e
                        );
                        e
                    });
                return Ok((true, Some(response.height_of_longest_chain)));
            }
            info!(
                target: LOG_TARGET,
                "Coinbase transaction (TxId: {}) detected as mined but UNCONFIRMED with {} confirmations",
                self.tx_id,
                response.confirmations
            );

            self.resources
                .db
                .set_transaction_mined_height(self.tx_id, self.block_height)
                .await
                .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;
            self.resources
                .db
                .mine_completed_transaction(self.tx_id)
                .await
                .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;

            let _ = self
                .resources
                .event_publisher
                .send(Arc::new(TransactionEvent::TransactionMinedUnconfirmed(
                    self.tx_id,
                    response.confirmations,
                )))
                .map_err(|e| {
                    trace!(
                        target: LOG_TARGET,
                        "Error sending event because there are no subscribers: {:?}",
                        e
                    );
                    e
                });
        } else if response.location == TxLocation::InMempool {
            debug!(
                target: LOG_TARGET,
                "Coinbase transaction (TxId: {}) found in mempool, still waiting.", self.tx_id
            );
        } else {
            debug!(
                target: LOG_TARGET,
                "Coinbase transaction (TxId: {}) not found in mempool, still waiting.", self.tx_id
            );
        }

        Ok((false, Some(response.height_of_longest_chain)))
    }
/// Attempt to query the location of the transaction from the base node via RPC.
/// # Returns:
/// `Ok((true, Some(u64)))`  => Transaction was successfully mined and confirmed.
/// `Ok((false, Some(u64)))` => Either the transaction is mined but does not have the required number of
///                             confirmations yet, or it is not mined and still in the mempool, or it is not mined
///                             and not found in the mempool.
/// `Ok((false, None))`      => There was a problem with the RPC call.
Attempt to query the location of the transaction from the base node via RPC.
Attempt to query the location of the transaction from the base node via RPC .
async fn query_coinbase_transaction(
        &mut self,
        signature: Signature,
        completed_tx: CompletedTransaction,
        client: &mut BaseNodeWalletRpcClient,
    ) -> Result<(bool, Option<u64>), TransactionServiceProtocolError> {
        trace!(
            target: LOG_TARGET,
            "Querying status for coinbase transaction (TxId: {})",
            self.tx_id,
        );
        let response = match client.transaction_query(signature.into()).await {
            Ok(r) => match TxQueryResponse::try_from(r) {
                Ok(r) => r,
                Err(_) => {
                    trace!(
                        target: LOG_TARGET,
                        "Could not convert proto TxQueryResponse for coinbase transaction (TxId: {})",
                        self.tx_id,
                    );
                    return Ok((false, None));
                },
            },
            Err(e) => {
                error!(
                    target: LOG_TARGET,
                    "Coinbase transaction Query RPC Call to Base Node failed for coinbase transaction (TxId: {}): {}",
                    self.tx_id,
                    e
                );
                return Ok((false, None));
            },
        };
        if !(response.is_synced ||
            response.location == TxLocation::Mined &&
                response.confirmations >= self.resources.config.num_confirmations_required)
        {
            info!(
                target: LOG_TARGET,
                "Base Node reports not being synced, coinbase monitoring will be retried."
            );
            return Ok((false, Some(response.height_of_longest_chain)));
        }
        // Mined?
        if response.location == TxLocation::Mined {
            if response.confirmations >= self.resources.config.num_confirmations_required {
                info!(
                    target: LOG_TARGET,
                    "Coinbase transaction (TxId: {}) detected as mined and CONFIRMED with {} confirmations",
                    self.tx_id,
                    response.confirmations
                );
                self.resources
                    .output_manager_service
                    .confirm_transaction(
                        self.tx_id,
                        completed_tx.transaction.body.inputs().clone(),
                        completed_tx.transaction.body.outputs().clone(),
                    )
                    .await
                    .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;
                self.resources
                    .db
                    .confirm_broadcast_or_coinbase_transaction(self.tx_id)
                    .await
                    .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;
                let _ = self
                    .resources
                    .event_publisher
                    .send(Arc::new(TransactionEvent::TransactionMined(self.tx_id)))
                    .map_err(|e| {
                        trace!(
                            target: LOG_TARGET,
                            "Error sending event because there are no subscribers: {:?}",
                            e
                        );
                        e
                    });
                return Ok((true, Some(response.height_of_longest_chain)));
            }
            info!(
                target: LOG_TARGET,
                "Coinbase transaction (TxId: {}) detected as mined but UNCONFIRMED with {} confirmations",
                self.tx_id,
                response.confirmations
            );
            self.resources
                .db
                .set_transaction_mined_height(self.tx_id, self.block_height)
                .await
                .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;
            self.resources
                .db
                .mine_completed_transaction(self.tx_id)
                .await
                .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;
            let _ = self
                .resources
                .event_publisher
                .send(Arc::new(TransactionEvent::TransactionMinedUnconfirmed(
                    self.tx_id,
                    response.confirmations,
                )))
                .map_err(|e| {
                    trace!(
                        target: LOG_TARGET,
                        "Error sending event because there are no subscribers: {:?}",
                        e
                    );
                    e
                });
        } else if response.location == TxLocation::InMempool {
            debug!(
                target: LOG_TARGET,
                "Coinbase transaction (TxId: {}) found in mempool, still waiting.", self.tx_id
            );
        } else {
            debug!(
                target: LOG_TARGET,
                "Coinbase transaction (TxId: {}) not found in mempool, still waiting.", self.tx_id
            );
        }
        Ok((false, Some(response.height_of_longest_chain)))
    }
async fn query_coinbase_transaction ( & mut self , signature : Signature , completed_tx : CompletedTransaction , client : & mut BaseNodeWalletRpcClient , ) -> Result < ( bool , Option < u64 > ) , TransactionServiceProtocolError > { trace ! ( target LOG_TARGET " " self tx_id ) ; let response = match client . transaction_query ( signature . into ( ) ) . await { Ok ( r ) => match TxQueryResponse :: try_from ( r ) { Ok ( r ) => r , Err ( _ ) => { trace ! ( target LOG_TARGET " " self tx_id ) ; return Ok ( ( false , None ) ) ; } , } , Err ( e ) => { error ! ( target LOG_TARGET " " self tx_id e ) ; return Ok ( ( false , None ) ) ; } , } ; if ! ( response . is_synced || response . location == TxLocation :: Mined && response . confirmations >= self . resources . config . num_confirmations_required ) { info ! ( target LOG_TARGET " " ) ; return Ok ( ( false , Some ( response . height_of_longest_chain ) ) ) ; } // Mined? if response . location == TxLocation :: Mined { if response . confirmations >= self . resources . config . num_confirmations_required { info ! ( target LOG_TARGET " " self tx_id response confirmations ) ; self . resources . output_manager_service . confirm_transaction ( self . tx_id , completed_tx . transaction . body . inputs ( ) . clone ( ) , completed_tx . transaction . body . outputs ( ) . clone ( ) , ) . await . map_err ( | e | TransactionServiceProtocolError :: new ( self . tx_id , TransactionServiceError :: from ( e ) ) ) ? ; self . resources . db . confirm_broadcast_or_coinbase_transaction ( self . tx_id ) . await . map_err ( | e | TransactionServiceProtocolError :: new ( self . tx_id , TransactionServiceError :: from ( e ) ) ) ? ; let _ = self . resources . event_publisher . send ( Arc :: new ( TransactionEvent :: TransactionMined ( self . tx_id ) ) ) . map_err ( | e | { trace ! ( target LOG_TARGET " " e ) ; e } ) ; return Ok ( ( true , Some ( response . height_of_longest_chain ) ) ) ; } info ! ( target LOG_TARGET " " self tx_id response confirmations ) ; self . resources . db . set_transaction_mined_height ( self . tx_id , self . block_height ) . await . map_err ( | e | TransactionServiceProtocolError :: new ( self . tx_id , TransactionServiceError :: from ( e ) ) ) ? ; self . resources . db . mine_completed_transaction ( self . tx_id ) . await . map_err ( | e | TransactionServiceProtocolError :: new ( self . tx_id , TransactionServiceError :: from ( e ) ) ) ? ; let _ = self . resources . event_publisher . send ( Arc :: new ( TransactionEvent :: TransactionMinedUnconfirmed ( self . tx_id , response . confirmations , ) ) ) . map_err ( | e | { trace ! ( target LOG_TARGET " " e ) ; e } ) ; } else if response . location == TxLocation :: InMempool { debug ! ( target LOG_TARGET " " self tx_id ) ; } else { debug ! ( target LOG_TARGET " " self tx_id ) ; } Ok ( ( false , Some ( response . height_of_longest_chain ) ) ) }
Attempt to query the location of the transaction from the base node via RPC.
Attempt to query the location of the transaction from the base node via RPC .
&mut self
signature
Signature
completed_tx
CompletedTransaction
client
&mut BaseNodeWalletRpcClient
&mut self
signature
Signature
completed_tx
CompletedTransaction
client
&mut BaseNodeWalletRpcClient
returns:
`Ok((true, Some(u64)))`  => Transaction was successfully mined and confirmed.
`Ok((false, Some(u64)))` => Either the transaction is mined but does not have the required number of
confirmations yet, or it is not mined and still in the mempool, or it is not mined
and not found in the mempool.
`Ok((false, None))`      => There was a problem with the RPC call.
` Ok (( true Some ( u64 ))) ` = > Transaction was successfully mined and confirmed . ` Ok (( false Some ( u64 ))) ` = > Either the transaction is mined but does not have the required number of confirmations yet or it is not mined and still in the mempool or it is not mined and not found in the mempool . ` Ok (( false None )) ` = > There was a problem with the RPC call .