Skip to content

Commit

Permalink
Remove Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Jan 26, 2023
1 parent e60c1f9 commit ce627d8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use crate::single_random_draw::select_coins_srd;

/// Trait that a UTXO struct must implement to be used as part of the coin selection
/// algorithm.
pub trait Utxo: Clone {
pub trait Utxo {
/// Return the value of the UTXO.
fn get_value(&self) -> u64;

Expand All @@ -48,7 +48,7 @@ pub fn select_coins<T: Utxo>(
cost_of_change: u64,
fee_rate: u64,
utxo_pool: &mut [T],
) -> Option<Vec<T>> {
) -> Option<Vec<&T>> {
let spend = Spend::new(fee_rate);

match select_coins_bnb(target, cost_of_change, utxo_pool) {
Expand Down
5 changes: 2 additions & 3 deletions src/single_random_draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rand::{seq::SliceRandom, thread_rng};
/// Requires compilation with the "rand" feature.
#[cfg(any(test, feature = "rand"))]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn select_coins_srd<T: Utxo>(target: u64, utxo_pool: &mut [T], spend: Spend) -> Option<Vec<T>> {
pub fn select_coins_srd<T: Utxo>(target: u64, utxo_pool: &mut [T], spend: Spend) -> Option<Vec<&T>> {
utxo_pool.shuffle(&mut thread_rng());

let mut sum = 0;
Expand All @@ -30,8 +30,7 @@ pub fn select_coins_srd<T: Utxo>(target: u64, utxo_pool: &mut [T], spend: Spend)
sum += spend.get_effective_value(*x);
true
})
.cloned()
.collect::<Vec<T>>();
.collect::<Vec<&T>>();

if sum >= target {
return Some(res);
Expand Down

0 comments on commit ce627d8

Please sign in to comment.