pub fn select(
		&self,
		root_key_id: keychain::Identifier,
		amount: u64,
		current_height: u64,
		minimum_confirmations: u64,
		max_outputs: usize,
		default_strategy: bool,
	) -> Vec<OutputData> {
		// first find all eligible outputs based on number of confirmations
		let mut eligible = self.outputs
			.values()
			.filter(|out| {
				out.root_key_id == root_key_id
					&& out.eligible_to_spend(current_height, minimum_confirmations)
			})
			.cloned()
			.collect::<Vec<OutputData>>();

		// sort eligible outputs by increasing value
		eligible.sort_by_key(|out| out.value);

		// use a sliding window to identify potential sets of possible outputs to spend
		if eligible.len() > max_outputs {
			for window in eligible.windows(max_outputs) {
				let eligible = window.iter().cloned().collect::<Vec<_>>();
				if let Some(outputs) = self.select_from(amount, default_strategy, eligible) {
					return outputs;
				}
			}
		} else {
			if let Some(outputs) = self.select_from(amount, default_strategy, eligible.clone()) {
				return outputs;
			}
		}

		// we failed to find a suitable set of outputs to spend,
		// so return the largest amount we can so we can provide guidance on what is possible
		eligible.reverse();
		eligible.iter().take(max_outputs).cloned().collect()
	}
/// Select spendable coins from the wallet.
/// Default strategy is to spend the maximum number of outputs (up to max_outputs).
/// Alternative strategy is to spend smallest outputs first but only as many as necessary.
/// When we introduce additional strategies we should pass something other than a bool in.
Select spendable coins from the wallet.
Default strategy is to spend the maximum number of outputs (up to max_outputs).
Alternative strategy is to spend smallest outputs first but only as many as necessary.
When we introduce additional strategies we should pass something other than a bool in.
Select spendable coins from the wallet . Default strategy is to spend the maximum number of outputs ( up to max_outputs ) . Alternative strategy is to spend smallest outputs first but only as many as necessary . When we introduce additional strategies we should pass something other than a bool in .
pub fn select(
		&self,
		root_key_id: keychain::Identifier,
		amount: u64,
		current_height: u64,
		minimum_confirmations: u64,
		max_outputs: usize,
		default_strategy: bool,
	) -> Vec<OutputData> {
		// first find all eligible outputs based on number of confirmations
		let mut eligible = self.outputs
			.values()
			.filter(|out| {
				out.root_key_id == root_key_id
					&& out.eligible_to_spend(current_height, minimum_confirmations)
			})
			.cloned()
			.collect::<Vec<OutputData>>();
		// sort eligible outputs by increasing value
		eligible.sort_by_key(|out| out.value);
		// use a sliding window to identify potential sets of possible outputs to spend
		if eligible.len() > max_outputs {
			for window in eligible.windows(max_outputs) {
				let eligible = window.iter().cloned().collect::<Vec<_>>();
				if let Some(outputs) = self.select_from(amount, default_strategy, eligible) {
					return outputs;
				}
			}
		} else {
			if let Some(outputs) = self.select_from(amount, default_strategy, eligible.clone()) {
				return outputs;
			}
		}
		// we failed to find a suitable set of outputs to spend,
		// so return the largest amount we can so we can provide guidance on what is possible
		eligible.reverse();
		eligible.iter().take(max_outputs).cloned().collect()
	}
pub fn select ( & self , root_key_id : keychain :: Identifier , amount : u64 , current_height : u64 , minimum_confirmations : u64 , max_outputs : usize , default_strategy : bool , ) -> Vec < OutputData > { // first find all eligible outputs based on number of confirmations let mut eligible = self . outputs . values ( ) . filter ( | out | { out . root_key_id == root_key_id && out . eligible_to_spend ( current_height , minimum_confirmations ) } ) . cloned ( ) . collect :: < Vec < OutputData > > ( ) ; // sort eligible outputs by increasing value eligible . sort_by_key ( | out | out . value ) ; // use a sliding window to identify potential sets of possible outputs to spend if eligible . len ( ) > max_outputs { for window in eligible . windows ( max_outputs ) { let eligible = window . iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ; if let Some ( outputs ) = self . select_from ( amount , default_strategy , eligible ) { return outputs ; } } } else { if let Some ( outputs ) = self . select_from ( amount , default_strategy , eligible . clone ( ) ) { return outputs ; } } // we failed to find a suitable set of outputs to spend, // so return the largest amount we can so we can provide guidance on what is possible eligible . reverse ( ) ; eligible . iter ( ) . take ( max_outputs ) . cloned ( ) . collect ( ) }
Select spendable coins from the wallet.
Select spendable coins from the wallet .
&self
root_key_id
keychain::Identifier
amount
u64
current_height
u64
minimum_confirmations
u64
max_outputs
usize
default_strategy
bool