Skip to content

Commit

Permalink
filter for largest notes
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed May 7, 2024
1 parent 74ddead commit b482d64
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions crates/view/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,27 +472,16 @@ impl<R: RngCore + CryptoRng> Planner<R> {
/// instance, a user might prefer a note prioritization strategy that harvested
/// capital losses when possible, using cost basis information retained by the
/// view server.
pub fn prioritize_and_filter_spendable_notes(
&mut self,
fn prioritize_and_filter_spendable_notes(
records: Vec<SpendableNoteRecord>,
) -> Vec<SpendableNoteRecord> {
// Filter out zero valued notes.
let mut filtered = records
.into_iter()
.filter(|record| record.note.amount() > Amount::zero())
.collect::<Vec<_>>();

filtered.sort_by(|a, b| {
// Sort by whether the note was sent to an ephemeral address...
match (
a.address_index.is_ephemeral(),
b.address_index.is_ephemeral(),
) {
(true, false) => std::cmp::Ordering::Less,
(false, true) => std::cmp::Ordering::Greater,
// ... then by largest amount.
_ => b.note.amount().cmp(&a.note.amount()),
}
});
filtered.sort_by(|a, b| b.note.amount().cmp(&a.note.amount()));

filtered
}
Expand Down

0 comments on commit b482d64

Please sign in to comment.