pub async fn send_transaction(
        &mut self,
        dest_pubkey: CommsPublicKey,
        amount: MicroTari,
        fee_per_gram: MicroTari,
        message: String,
        join_handles: &mut FuturesUnordered<JoinHandle<Result<u64, TransactionServiceProtocolError>>>,
        transaction_broadcast_join_handles: &mut FuturesUnordered<
            JoinHandle<Result<u64, TransactionServiceProtocolError>>,
        >,
    ) -> Result<TxId, TransactionServiceError> {
        // If we're paying ourselves, let's complete and submit the transaction immediately
        if self.node_identity.public_key() == &dest_pubkey {
            debug!(
                target: LOG_TARGET,
                "Received transaction with spend-to-self transaction"
            );

            let (tx_id, fee, transaction) = self
                .output_manager_service
                .create_pay_to_self_transaction(amount, fee_per_gram, None, message.clone())
                .await?;

            // Notify that the transaction was successfully resolved.
            let _ = self
                .event_publisher
                .send(Arc::new(TransactionEvent::TransactionCompletedImmediately(tx_id)));

            self.submit_transaction(
                transaction_broadcast_join_handles,
                CompletedTransaction::new(
                    tx_id,
                    self.node_identity.public_key().clone(),
                    self.node_identity.public_key().clone(),
                    amount,
                    fee,
                    transaction,
                    TransactionStatus::Completed,
                    message,
                    Utc::now().naive_utc(),
                    TransactionDirection::Inbound,
                    None,
                ),
            )
            .await?;

            return Ok(tx_id);
        }

        let sender_protocol = self
            .output_manager_service
            .prepare_transaction_to_send(amount, fee_per_gram, None, message.clone(), script!(Nop))
            .await?;

        let tx_id = sender_protocol.get_tx_id()?;

        let (tx_reply_sender, tx_reply_receiver) = mpsc::channel(100);
        let (cancellation_sender, cancellation_receiver) = oneshot::channel();
        self.pending_transaction_reply_senders.insert(tx_id, tx_reply_sender);

        self.send_transaction_cancellation_senders
            .insert(tx_id, cancellation_sender);
        let protocol = TransactionSendProtocol::new(
            tx_id,
            self.resources.clone(),
            tx_reply_receiver,
            cancellation_receiver,
            dest_pubkey,
            amount,
            message,
            sender_protocol,
            TransactionSendProtocolStage::Initial,
        );

        let join_handle = tokio::spawn(protocol.execute());
        join_handles.push(join_handle);

        Ok(tx_id)
    }
/// Sends a new transaction to a recipient
/// # Arguments
/// 'dest_pubkey': The Comms pubkey of the recipient node
/// 'amount': The amount of Tari to send to the recipient
/// 'fee_per_gram': The amount of fee per transaction gram to be included in transaction
Sends a new transaction to a recipient
Sends a new transaction to a recipient
pub async fn send_transaction(
        &mut self,
        dest_pubkey: CommsPublicKey,
        amount: MicroTari,
        fee_per_gram: MicroTari,
        message: String,
        join_handles: &mut FuturesUnordered<JoinHandle<Result<u64, TransactionServiceProtocolError>>>,
        transaction_broadcast_join_handles: &mut FuturesUnordered<
            JoinHandle<Result<u64, TransactionServiceProtocolError>>,
        >,
    ) -> Result<TxId, TransactionServiceError> {
        // If we're paying ourselves, let's complete and submit the transaction immediately
        if self.node_identity.public_key() == &dest_pubkey {
            debug!(
                target: LOG_TARGET,
                "Received transaction with spend-to-self transaction"
            );
            let (tx_id, fee, transaction) = self
                .output_manager_service
                .create_pay_to_self_transaction(amount, fee_per_gram, None, message.clone())
                .await?;
            // Notify that the transaction was successfully resolved.
            let _ = self
                .event_publisher
                .send(Arc::new(TransactionEvent::TransactionCompletedImmediately(tx_id)));
            self.submit_transaction(
                transaction_broadcast_join_handles,
                CompletedTransaction::new(
                    tx_id,
                    self.node_identity.public_key().clone(),
                    self.node_identity.public_key().clone(),
                    amount,
                    fee,
                    transaction,
                    TransactionStatus::Completed,
                    message,
                    Utc::now().naive_utc(),
                    TransactionDirection::Inbound,
                    None,
                ),
            )
            .await?;
            return Ok(tx_id);
        }
        let sender_protocol = self
            .output_manager_service
            .prepare_transaction_to_send(amount, fee_per_gram, None, message.clone(), script!(Nop))
            .await?;
        let tx_id = sender_protocol.get_tx_id()?;
        let (tx_reply_sender, tx_reply_receiver) = mpsc::channel(100);
        let (cancellation_sender, cancellation_receiver) = oneshot::channel();
        self.pending_transaction_reply_senders.insert(tx_id, tx_reply_sender);
        self.send_transaction_cancellation_senders
            .insert(tx_id, cancellation_sender);
        let protocol = TransactionSendProtocol::new(
            tx_id,
            self.resources.clone(),
            tx_reply_receiver,
            cancellation_receiver,
            dest_pubkey,
            amount,
            message,
            sender_protocol,
            TransactionSendProtocolStage::Initial,
        );
        let join_handle = tokio::spawn(protocol.execute());
        join_handles.push(join_handle);
        Ok(tx_id)
    }
pub async fn send_transaction ( & mut self , dest_pubkey : CommsPublicKey , amount : MicroTari , fee_per_gram : MicroTari , message : String , join_handles : & mut FuturesUnordered < JoinHandle < Result < u64 , TransactionServiceProtocolError > > > , transaction_broadcast_join_handles : & mut FuturesUnordered < JoinHandle < Result < u64 , TransactionServiceProtocolError > > , > , ) -> Result < TxId , TransactionServiceError > { // If we're paying ourselves, let's complete and submit the transaction immediately if self . node_identity . public_key ( ) == & dest_pubkey { debug ! ( target LOG_TARGET " " ) ; let ( tx_id , fee , transaction ) = self . output_manager_service . create_pay_to_self_transaction ( amount , fee_per_gram , None , message . clone ( ) ) . await ? ; // Notify that the transaction was successfully resolved. let _ = self . event_publisher . send ( Arc :: new ( TransactionEvent :: TransactionCompletedImmediately ( tx_id ) ) ) ; self . submit_transaction ( transaction_broadcast_join_handles , CompletedTransaction :: new ( tx_id , self . node_identity . public_key ( ) . clone ( ) , self . node_identity . public_key ( ) . clone ( ) , amount , fee , transaction , TransactionStatus :: Completed , message , Utc :: now ( ) . naive_utc ( ) , TransactionDirection :: Inbound , None , ) , ) . await ? ; return Ok ( tx_id ) ; } let sender_protocol = self . output_manager_service . prepare_transaction_to_send ( amount , fee_per_gram , None , message . clone ( ) , script ! ( Nop ) ) . await ? ; let tx_id = sender_protocol . get_tx_id ( ) ? ; let ( tx_reply_sender , tx_reply_receiver ) = mpsc :: channel ( 100 ) ; let ( cancellation_sender , cancellation_receiver ) = oneshot :: channel ( ) ; self . pending_transaction_reply_senders . insert ( tx_id , tx_reply_sender ) ; self . send_transaction_cancellation_senders . insert ( tx_id , cancellation_sender ) ; let protocol = TransactionSendProtocol :: new ( tx_id , self . resources . clone ( ) , tx_reply_receiver , cancellation_receiver , dest_pubkey , amount , message , sender_protocol , TransactionSendProtocolStage :: Initial , ) ; let join_handle = tokio :: spawn ( protocol . execute ( ) ) ; join_handles . push ( join_handle ) ; Ok ( tx_id ) }
Sends a new transaction to a recipient
Sends a new transaction to a recipient
&mut self
dest_pubkey
CommsPublicKey
amount
MicroTari
fee_per_gram
MicroTari
message
String
join_handles
&mut FuturesUnordered<JoinHandle<Result<u64, TransactionServiceProtocolError>>>
transaction_broadcast_join_handles
&mut FuturesUnordered<
            JoinHandle<Result<u64, TransactionServiceProtocolError>>,
        >
&mut self
dest_pubkey
CommsPublicKey
amount
MicroTari
fee_per_gram
MicroTari
message
String
join_handles
&mut FuturesUnordered<JoinHandle<Result<u64, TransactionServiceProtocolError>>>
transaction_broadcast_join_handles
&mut FuturesUnordered<
            JoinHandle<Result<u64, TransactionServiceProtocolError>>,
        >