Skip to content

Commit

Permalink
restore note prioritization logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed May 7, 2024
1 parent 695cf94 commit 3294222
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions crates/view/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,18 +471,26 @@ 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.
fn prioritize_and_filter_spendable_notes(
pub fn prioritize_and_filter_spendable_notes(
&mut self,
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| b.note.amount().cmp(&a.note.amount()));

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
}

Expand Down

0 comments on commit 3294222

Please sign in to comment.