]> Untitled Git - bdk/commitdiff
Fix wallet export rescan height
authorLLFourn <lloyd.fourn@gmail.com>
Wed, 26 Oct 2022 04:35:21 +0000 (12:35 +0800)
committerLLFourn <lloyd.fourn@gmail.com>
Wed, 26 Oct 2022 04:35:21 +0000 (12:35 +0800)
It would return the latest transaction height rather than the earliest :S

src/wallet/export.rs

index 9c7532119bae63b1069f4b141f321af9eb7a5227..d7c68f7ed7872d6dedcd8ea01b23772ff793ea41 100644 (file)
@@ -134,15 +134,11 @@ impl FullyNodedExport {
         let blockheight = match wallet.database.borrow().iter_txs(false) {
             _ if !include_blockheight => 0,
             Err(_) => 0,
-            Ok(txs) => {
-                let mut heights = txs
-                    .into_iter()
-                    .map(|tx| tx.confirmation_time.map(|c| c.height).unwrap_or(0))
-                    .collect::<Vec<_>>();
-                heights.sort_unstable();
-
-                *heights.last().unwrap_or(&0)
-            }
+            Ok(txs) => txs
+                .into_iter()
+                .filter_map(|tx| tx.confirmation_time.map(|c| c.height))
+                .min()
+                .unwrap_or(0),
         };
 
         let export = FullyNodedExport {
@@ -249,6 +245,22 @@ mod test {
             fee: Some(500),
             confirmation_time: Some(BlockTime {
                 timestamp: 12345678,
+                height: 5001,
+            }),
+        })
+        .unwrap();
+
+        db.set_tx(&TransactionDetails {
+            transaction: None,
+            txid: Txid::from_str(
+                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+            )
+            .unwrap(),
+            received: 25_000,
+            sent: 0,
+            fee: Some(300),
+            confirmation_time: Some(BlockTime {
+                timestamp: 12345677,
                 height: 5000,
             }),
         })