/// This handler is called when the Service executor loops receives an API request
This handler is called when the Service executor loops receives an API request
This handler is called when the Service executor loops receives an API request
async fn handle_request(
        &mut self,
        request: OutputManagerRequest,
        utxo_validation_handles: &mut FuturesUnordered<JoinHandle<Result<u64, OutputManagerProtocolError>>>,
    ) -> Result<OutputManagerResponse, OutputManagerError>
    {
        trace!(target: LOG_TARGET, "Handling Service Request: {}", request);
        match request {
            OutputManagerRequest::AddOutput(uo) => {
                self.add_output(uo).await.map(|_| OutputManagerResponse::OutputAdded)
            },
            OutputManagerRequest::GetBalance => self.get_balance(None).await.map(OutputManagerResponse::Balance),
            OutputManagerRequest::GetRecipientKey((tx_id, amount)) => self
                .get_recipient_spending_key(tx_id, amount)
                .await
                .map(OutputManagerResponse::RecipientKeyGenerated),
            OutputManagerRequest::GetCoinbaseKey((tx_id, amount, block_height)) => self
                .get_coinbase_spending_key(tx_id, amount, block_height)
                .await
                .map(OutputManagerResponse::CoinbaseKeyGenerated),
            OutputManagerRequest::PrepareToSendTransaction((amount, fee_per_gram, lock_height, message)) => self
                .prepare_transaction_to_send(amount, fee_per_gram, lock_height, message)
                .await
                .map(OutputManagerResponse::TransactionToSend),
            OutputManagerRequest::ConfirmPendingTransaction(tx_id) => self
                .confirm_encumberance(tx_id)
                .await
                .map(|_| OutputManagerResponse::PendingTransactionConfirmed),
            OutputManagerRequest::ConfirmTransaction((tx_id, spent_outputs, received_outputs)) => self
                .confirm_transaction(tx_id, &spent_outputs, &received_outputs)
                .await
                .map(|_| OutputManagerResponse::TransactionConfirmed),
            OutputManagerRequest::CancelTransaction(tx_id) => self
                .cancel_transaction(tx_id)
                .await
                .map(|_| OutputManagerResponse::TransactionCancelled),
            OutputManagerRequest::TimeoutTransactions(period) => self
                .timeout_pending_transactions(period)
                .await
                .map(|_| OutputManagerResponse::TransactionsTimedOut),
            OutputManagerRequest::GetPendingTransactions => self
                .fetch_pending_transaction_outputs()
                .await
                .map(OutputManagerResponse::PendingTransactions),
            OutputManagerRequest::GetSpentOutputs => {
                let outputs = self
                    .fetch_spent_outputs()
                    .await?
                    .into_iter()
                    .map(|v| v.into())
                    .collect();
                Ok(OutputManagerResponse::SpentOutputs(outputs))
            },
            OutputManagerRequest::GetUnspentOutputs => {
                let outputs = self
                    .fetch_unspent_outputs()
                    .await?
                    .into_iter()
                    .map(|v| v.into())
                    .collect();
                Ok(OutputManagerResponse::UnspentOutputs(outputs))
            },
            OutputManagerRequest::GetSeedWords => self.get_seed_words().await.map(OutputManagerResponse::SeedWords),
            OutputManagerRequest::SetBaseNodePublicKey(pk) => self
                .set_base_node_public_key(pk)
                .await
                .map(|_| OutputManagerResponse::BaseNodePublicKeySet),
            OutputManagerRequest::ValidateUtxos(validation_type, retries) => self
                .validate_outputs(validation_type, retries, utxo_validation_handles)
                .map(OutputManagerResponse::UtxoValidationStarted),
            OutputManagerRequest::GetInvalidOutputs => {
                let outputs = self
                    .fetch_invalid_outputs()
                    .await?
                    .into_iter()
                    .map(|v| v.into())
                    .collect();
                Ok(OutputManagerResponse::InvalidOutputs(outputs))
            },
            OutputManagerRequest::CreateCoinSplit((amount_per_split, split_count, fee_per_gram, lock_height)) => self
                .create_coin_split(amount_per_split, split_count, fee_per_gram, lock_height)
                .await
                .map(OutputManagerResponse::Transaction),
            OutputManagerRequest::ApplyEncryption(cipher) => self
                .resources
                .db
                .apply_encryption(*cipher)
                .await
                .map(|_| OutputManagerResponse::EncryptionApplied)
                .map_err(OutputManagerError::OutputManagerStorageError),
            OutputManagerRequest::RemoveEncryption => self
                .resources
                .db
                .remove_encryption()
                .await
                .map(|_| OutputManagerResponse::EncryptionRemoved)
                .map_err(OutputManagerError::OutputManagerStorageError),
        }
    }
async fn handle_request ( & mut self , request : OutputManagerRequest , utxo_validation_handles : & mut FuturesUnordered < JoinHandle < Result < u64 , OutputManagerProtocolError > > > , ) -> Result < OutputManagerResponse , OutputManagerError > { trace ! ( target LOG_TARGET " " request ) ; match request { OutputManagerRequest :: AddOutput ( uo ) => { self . add_output ( uo ) . await . map ( | _ | OutputManagerResponse :: OutputAdded ) } , OutputManagerRequest :: GetBalance => self . get_balance ( None ) . await . map ( OutputManagerResponse :: Balance ) , OutputManagerRequest :: GetRecipientKey ( ( tx_id , amount ) ) => self . get_recipient_spending_key ( tx_id , amount ) . await . map ( OutputManagerResponse :: RecipientKeyGenerated ) , OutputManagerRequest :: GetCoinbaseKey ( ( tx_id , amount , block_height ) ) => self . get_coinbase_spending_key ( tx_id , amount , block_height ) . await . map ( OutputManagerResponse :: CoinbaseKeyGenerated ) , OutputManagerRequest :: PrepareToSendTransaction ( ( amount , fee_per_gram , lock_height , message ) ) => self . prepare_transaction_to_send ( amount , fee_per_gram , lock_height , message ) . await . map ( OutputManagerResponse :: TransactionToSend ) , OutputManagerRequest :: ConfirmPendingTransaction ( tx_id ) => self . confirm_encumberance ( tx_id ) . await . map ( | _ | OutputManagerResponse :: PendingTransactionConfirmed ) , OutputManagerRequest :: ConfirmTransaction ( ( tx_id , spent_outputs , received_outputs ) ) => self . confirm_transaction ( tx_id , & spent_outputs , & received_outputs ) . await . map ( | _ | OutputManagerResponse :: TransactionConfirmed ) , OutputManagerRequest :: CancelTransaction ( tx_id ) => self . cancel_transaction ( tx_id ) . await . map ( | _ | OutputManagerResponse :: TransactionCancelled ) , OutputManagerRequest :: TimeoutTransactions ( period ) => self . timeout_pending_transactions ( period ) . await . map ( | _ | OutputManagerResponse :: TransactionsTimedOut ) , OutputManagerRequest :: GetPendingTransactions => self . fetch_pending_transaction_outputs ( ) . await . map ( OutputManagerResponse :: PendingTransactions ) , OutputManagerRequest :: GetSpentOutputs => { let outputs = self . fetch_spent_outputs ( ) . await ? . into_iter ( ) . map ( | v | v . into ( ) ) . collect ( ) ; Ok ( OutputManagerResponse :: SpentOutputs ( outputs ) ) } , OutputManagerRequest :: GetUnspentOutputs => { let outputs = self . fetch_unspent_outputs ( ) . await ? . into_iter ( ) . map ( | v | v . into ( ) ) . collect ( ) ; Ok ( OutputManagerResponse :: UnspentOutputs ( outputs ) ) } , OutputManagerRequest :: GetSeedWords => self . get_seed_words ( ) . await . map ( OutputManagerResponse :: SeedWords ) , OutputManagerRequest :: SetBaseNodePublicKey ( pk ) => self . set_base_node_public_key ( pk ) . await . map ( | _ | OutputManagerResponse :: BaseNodePublicKeySet ) , OutputManagerRequest :: ValidateUtxos ( validation_type , retries ) => self . validate_outputs ( validation_type , retries , utxo_validation_handles ) . map ( OutputManagerResponse :: UtxoValidationStarted ) , OutputManagerRequest :: GetInvalidOutputs => { let outputs = self . fetch_invalid_outputs ( ) . await ? . into_iter ( ) . map ( | v | v . into ( ) ) . collect ( ) ; Ok ( OutputManagerResponse :: InvalidOutputs ( outputs ) ) } , OutputManagerRequest :: CreateCoinSplit ( ( amount_per_split , split_count , fee_per_gram , lock_height ) ) => self . create_coin_split ( amount_per_split , split_count , fee_per_gram , lock_height ) . await . map ( OutputManagerResponse :: Transaction ) , OutputManagerRequest :: ApplyEncryption ( cipher ) => self . resources . db . apply_encryption ( * cipher ) . await . map ( | _ | OutputManagerResponse :: EncryptionApplied ) . map_err ( OutputManagerError :: OutputManagerStorageError ) , OutputManagerRequest :: RemoveEncryption => self . resources . db . remove_encryption ( ) . await . map ( | _ | OutputManagerResponse :: EncryptionRemoved ) . map_err ( OutputManagerError :: OutputManagerStorageError ) , } }
This handler is called when the Service executor loops receives an API request
This handler is called when the Service executor loops receives an API request
&mut self
request
OutputManagerRequest
utxo_validation_handles
&mut FuturesUnordered<JoinHandle<Result<u64, OutputManagerProtocolError>>>