async fn transaction_query(
        &mut self,
        signature: Signature,
        client: &mut BaseNodeWalletRpcClient,
    ) -> Result<bool, TransactionServiceProtocolError> {
        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");
                    return Ok(false);
                },
            },
            Err(e) => {
                info!(
                    target: LOG_TARGET,
                    "Transaction Query RPC Call to Base Node failed: {}", e
                );
                return Ok(false);
            },
        };

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

        // Mined?
        if response.location == TxLocation::Mined {
            self.resources
                .db
                .set_transaction_confirmations(self.tx_id, response.confirmations)
                .await
                .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;

            self.resources
                .db
                .set_transaction_mined_height(
                    self.tx_id,
                    response.height_of_longest_chain.saturating_sub(response.confirmations),
                )
                .await
                .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;

            if response.confirmations >= self.resources.config.num_confirmations_required as u64 {
                info!(
                    target: LOG_TARGET,
                    "Transaction (TxId: {}) detected as mined and CONFIRMED with {} confirmations",
                    self.tx_id,
                    response.confirmations
                );
                return Ok(true);
            }
            info!(
                target: LOG_TARGET,
                "Transaction (TxId: {}) detected as mined but UNCONFIRMED with {} confirmations",
                self.tx_id,
                response.confirmations
            );
            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 {
            if !self.first_rejection {
                info!(
                    target: LOG_TARGET,
                    "Transaction (TxId: {}) not found in mempool, attempting to resubmit transaction", self.tx_id
                );
                self.mode = TxBroadcastMode::TransactionSubmission;
                self.first_rejection = true;
            } else {
                error!(
                    target: LOG_TARGET,
                    "Transaction (TxId: {}) has been rejected by the mempool after second submission attempt, \
                     cancelling transaction",
                    self.tx_id
                );
                self.cancel_transaction().await;

                let _ = self
                    .resources
                    .event_publisher
                    .send(Arc::new(TransactionEvent::TransactionCancelled(self.tx_id)))
                    .map_err(|e| {
                        trace!(
                            target: LOG_TARGET,
                            "Error sending event because there are no subscribers: {:?}",
                            e
                        );
                        e
                    });
                return Err(TransactionServiceProtocolError::new(
                    self.tx_id,
                    TransactionServiceError::MempoolRejection,
                ));
            }
        } else {
            info!(
                target: LOG_TARGET,
                "Transaction (TxId: {}) found in mempool.", self.tx_id
            );
        }

        Ok(false)
    }
/// Attempt to query the location of the transaction from the base node via RPC.
/// # Returns:
/// `Ok(true)` => Transaction was successfully mined and confirmed
/// `Ok(false)` => There was a problem with the RPC call or the transaction is not mined but still in the mempool
/// and this should be retried `Err(_)` => The transaction was rejected by the base node and the protocol should
/// end.
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 transaction_query(
        &mut self,
        signature: Signature,
        client: &mut BaseNodeWalletRpcClient,
    ) -> Result<bool, TransactionServiceProtocolError> {
        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");
                    return Ok(false);
                },
            },
            Err(e) => {
                info!(
                    target: LOG_TARGET,
                    "Transaction Query RPC Call to Base Node failed: {}", e
                );
                return Ok(false);
            },
        };
        if !(response.is_synced ||
            (response.location == TxLocation::Mined &&
                response.confirmations >= self.resources.config.num_confirmations_required as u64))
        {
            info!(
                target: LOG_TARGET,
                "Base Node reports not being synced, submission will be retried."
            );
            return Ok(false);
        }
        // Mined?
        if response.location == TxLocation::Mined {
            self.resources
                .db
                .set_transaction_confirmations(self.tx_id, response.confirmations)
                .await
                .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;
            self.resources
                .db
                .set_transaction_mined_height(
                    self.tx_id,
                    response.height_of_longest_chain.saturating_sub(response.confirmations),
                )
                .await
                .map_err(|e| TransactionServiceProtocolError::new(self.tx_id, TransactionServiceError::from(e)))?;
            if response.confirmations >= self.resources.config.num_confirmations_required as u64 {
                info!(
                    target: LOG_TARGET,
                    "Transaction (TxId: {}) detected as mined and CONFIRMED with {} confirmations",
                    self.tx_id,
                    response.confirmations
                );
                return Ok(true);
            }
            info!(
                target: LOG_TARGET,
                "Transaction (TxId: {}) detected as mined but UNCONFIRMED with {} confirmations",
                self.tx_id,
                response.confirmations
            );
            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 {
            if !self.first_rejection {
                info!(
                    target: LOG_TARGET,
                    "Transaction (TxId: {}) not found in mempool, attempting to resubmit transaction", self.tx_id
                );
                self.mode = TxBroadcastMode::TransactionSubmission;
                self.first_rejection = true;
            } else {
                error!(
                    target: LOG_TARGET,
                    "Transaction (TxId: {}) has been rejected by the mempool after second submission attempt, \
                     cancelling transaction",
                    self.tx_id
                );
                self.cancel_transaction().await;
                let _ = self
                    .resources
                    .event_publisher
                    .send(Arc::new(TransactionEvent::TransactionCancelled(self.tx_id)))
                    .map_err(|e| {
                        trace!(
                            target: LOG_TARGET,
                            "Error sending event because there are no subscribers: {:?}",
                            e
                        );
                        e
                    });
                return Err(TransactionServiceProtocolError::new(
                    self.tx_id,
                    TransactionServiceError::MempoolRejection,
                ));
            }
        } else {
            info!(
                target: LOG_TARGET,
                "Transaction (TxId: {}) found in mempool.", self.tx_id
            );
        }
        Ok(false)
    }
async fn transaction_query ( & mut self , signature : Signature , client : & mut BaseNodeWalletRpcClient , ) -> Result < bool , TransactionServiceProtocolError > { let response = match client . transaction_query ( signature . into ( ) ) . await { Ok ( r ) => match TxQueryResponse :: try_from ( r ) { Ok ( r ) => r , Err ( _ ) => { trace ! ( target LOG_TARGET " " ) ; return Ok ( false ) ; } , } , Err ( e ) => { info ! ( target LOG_TARGET " " e ) ; return Ok ( false ) ; } , } ; if ! ( response . is_synced || ( response . location == TxLocation :: Mined && response . confirmations >= self . resources . config . num_confirmations_required as u64 ) ) { info ! ( target LOG_TARGET " " ) ; return Ok ( false ) ; } // Mined? if response . location == TxLocation :: Mined { self . resources . db . set_transaction_confirmations ( self . tx_id , response . confirmations ) . await . map_err ( | e | TransactionServiceProtocolError :: new ( self . tx_id , TransactionServiceError :: from ( e ) ) ) ? ; self . resources . db . set_transaction_mined_height ( self . tx_id , response . height_of_longest_chain . saturating_sub ( response . confirmations ) , ) . await . map_err ( | e | TransactionServiceProtocolError :: new ( self . tx_id , TransactionServiceError :: from ( e ) ) ) ? ; if response . confirmations >= self . resources . config . num_confirmations_required as u64 { info ! ( target LOG_TARGET " " self tx_id response confirmations ) ; return Ok ( true ) ; } info ! ( target LOG_TARGET " " self tx_id response confirmations ) ; 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 { if ! self . first_rejection { info ! ( target LOG_TARGET " " self tx_id ) ; self . mode = TxBroadcastMode :: TransactionSubmission ; self . first_rejection = true ; } else { error ! ( target LOG_TARGET " \
 " self tx_id ) ; self . cancel_transaction ( ) . await ; let _ = self . resources . event_publisher . send ( Arc :: new ( TransactionEvent :: TransactionCancelled ( self . tx_id ) ) ) . map_err ( | e | { trace ! ( target LOG_TARGET " " e ) ; e } ) ; return Err ( TransactionServiceProtocolError :: new ( self . tx_id , TransactionServiceError :: MempoolRejection , ) ) ; } } else { info ! ( target LOG_TARGET " " self tx_id ) ; } Ok ( false ) }
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
client
&mut BaseNodeWalletRpcClient
&mut self
signature
Signature
client
&mut BaseNodeWalletRpcClient
returns:
`Ok(true)` => Transaction was successfully mined and confirmed
`Ok(false)` => There was a problem with the RPC call or the transaction is not mined but still in the mempool
and this should be retried `Err(_)` => The transaction was rejected by the base node and the protocol should
end.
` Ok ( true ) ` = > Transaction was successfully mined and confirmed ` Ok ( false ) ` = > There was a problem with the RPC call or the transaction is not mined but still in the mempool and this should be retried ` Err ( _ ) ` = > The transaction was rejected by the base node and the protocol should end .