pub async fn find_inputs(&self, addresses: Vec<String>, amount: u64) -> Result<Vec<UtxoInput>> {
        // Get outputs from node and select inputs
        let mut available_outputs = Vec::new();
        for address in addresses {
            available_outputs.extend_from_slice(&self.get_address().outputs(&address, Default::default()).await?);
        }

        let mut signature_locked_outputs = Vec::new();
        let mut dust_allowance_outputs = Vec::new();

        for output in available_outputs.into_iter() {
            let output_data = self.get_output(&output).await?;
            let (amount, _, signature_locked) =
                ClientMessageBuilder::get_output_amount_and_address(&output_data.output)?;
            if signature_locked {
                signature_locked_outputs.push((output, amount));
            } else {
                dust_allowance_outputs.push((output, amount));
            }
        }
        signature_locked_outputs.sort_by(|l, r| r.1.cmp(&l.1));
        dust_allowance_outputs.sort_by(|l, r| r.1.cmp(&l.1));

        let mut total_already_spent = 0;
        let mut selected_inputs = Vec::new();
        for (_offset, output_wrapper) in signature_locked_outputs
            .into_iter()
            .chain(dust_allowance_outputs.into_iter())
            // Max inputs is 127
            .take(INPUT_OUTPUT_COUNT_MAX)
            .enumerate()
        {
            // Break if we have enough funds and don't create dust for the remainder
            if total_already_spent == amount || total_already_spent >= amount + DUST_THRESHOLD {
                break;
            }
            selected_inputs.push(output_wrapper.0.clone());
            total_already_spent += output_wrapper.1;
        }

        if total_already_spent < amount
            || (total_already_spent != amount && total_already_spent < amount + DUST_THRESHOLD)
        {
            return Err(crate::Error::NotEnoughBalance(total_already_spent, amount));
        }

        Ok(selected_inputs)
    }
/// Function to find inputs from addresses for a provided amount (useful for offline signing)
Function to find inputs from addresses for a provided amount (useful for offline signing)
Function to find inputs from addresses for a provided amount ( useful for offline signing )
pub async fn find_inputs(&self, addresses: Vec<String>, amount: u64) -> Result<Vec<UtxoInput>> {
        // Get outputs from node and select inputs
        let mut available_outputs = Vec::new();
        for address in addresses {
            available_outputs.extend_from_slice(&self.get_address().outputs(&address, Default::default()).await?);
        }
        let mut signature_locked_outputs = Vec::new();
        let mut dust_allowance_outputs = Vec::new();
        for output in available_outputs.into_iter() {
            let output_data = self.get_output(&output).await?;
            let (amount, _, signature_locked) =
                ClientMessageBuilder::get_output_amount_and_address(&output_data.output)?;
            if signature_locked {
                signature_locked_outputs.push((output, amount));
            } else {
                dust_allowance_outputs.push((output, amount));
            }
        }
        signature_locked_outputs.sort_by(|l, r| r.1.cmp(&l.1));
        dust_allowance_outputs.sort_by(|l, r| r.1.cmp(&l.1));
        let mut total_already_spent = 0;
        let mut selected_inputs = Vec::new();
        for (_offset, output_wrapper) in signature_locked_outputs
            .into_iter()
            .chain(dust_allowance_outputs.into_iter())
            // Max inputs is 127
            .take(INPUT_OUTPUT_COUNT_MAX)
            .enumerate()
        {
            // Break if we have enough funds and don't create dust for the remainder
            if total_already_spent == amount || total_already_spent >= amount + DUST_THRESHOLD {
                break;
            }
            selected_inputs.push(output_wrapper.0.clone());
            total_already_spent += output_wrapper.1;
        }
        if total_already_spent < amount
            || (total_already_spent != amount && total_already_spent < amount + DUST_THRESHOLD)
        {
            return Err(crate::Error::NotEnoughBalance(total_already_spent, amount));
        }
        Ok(selected_inputs)
    }
pub async fn find_inputs ( & self , addresses : Vec < String > , amount : u64 ) -> Result < Vec < UtxoInput > > { // Get outputs from node and select inputs let mut available_outputs = Vec :: new ( ) ; for address in addresses { available_outputs . extend_from_slice ( & self . get_address ( ) . outputs ( & address , Default :: default ( ) ) . await ? ) ; } let mut signature_locked_outputs = Vec :: new ( ) ; let mut dust_allowance_outputs = Vec :: new ( ) ; for output in available_outputs . into_iter ( ) { let output_data = self . get_output ( & output ) . await ? ; let ( amount , _ , signature_locked ) = ClientMessageBuilder :: get_output_amount_and_address ( & output_data . output ) ? ; if signature_locked { signature_locked_outputs . push ( ( output , amount ) ) ; } else { dust_allowance_outputs . push ( ( output , amount ) ) ; } } signature_locked_outputs . sort_by ( | l , r | r . 1 . cmp ( & l . 1 ) ) ; dust_allowance_outputs . sort_by ( | l , r | r . 1 . cmp ( & l . 1 ) ) ; let mut total_already_spent = 0 ; let mut selected_inputs = Vec :: new ( ) ; for ( _offset , output_wrapper ) in signature_locked_outputs . into_iter ( ) . chain ( dust_allowance_outputs . into_iter ( ) ) // Max inputs is 127 . take ( INPUT_OUTPUT_COUNT_MAX ) . enumerate ( ) { // Break if we have enough funds and don't create dust for the remainder if total_already_spent == amount || total_already_spent >= amount + DUST_THRESHOLD { break ; } selected_inputs . push ( output_wrapper . 0 . clone ( ) ) ; total_already_spent += output_wrapper . 1 ; } if total_already_spent < amount || ( total_already_spent != amount && total_already_spent < amount + DUST_THRESHOLD ) { return Err ( crate :: Error :: NotEnoughBalance ( total_already_spent , amount ) ) ; } Ok ( selected_inputs ) }
Function to find inputs from addresses for a provided amount (useful for offline signing)
Function to find inputs from addresses for a provided amount ( useful for offline signing )
&self
addresses
Vec<String>
amount
u64
&self
addresses
Vec<String>
amount
u64