Преглед на файлове

Make sorting Transactions a stable sort (#1147)

If you had 2 Transactions that had the same timestamp the sort could be
unstable and could cause annoying issues. Now it will compare the ids if
they are equal and should always have a stable sorting implementation
now.
benthecarman преди 1 месец
родител
ревизия
6bffd78233
променени са 1 файла, в които са добавени 4 реда и са изтрити 1 реда
  1. 4 1
      crates/cdk-common/src/wallet.rs

+ 4 - 1
crates/cdk-common/src/wallet.rs

@@ -246,7 +246,10 @@ impl PartialOrd for Transaction {
 
 impl Ord for Transaction {
     fn cmp(&self, other: &Self) -> std::cmp::Ordering {
-        self.timestamp.cmp(&other.timestamp).reverse()
+        self.timestamp
+            .cmp(&other.timestamp)
+            .reverse()
+            .then_with(|| self.id().cmp(&other.id()))
     }
 }