Skip to content

Commit 108edc3

Browse files
committed
Merge #785: Fix wallet export rescan height
e9bbb87 Fix wallet export rescan height (LLFourn) Pull request description: It would return the latest transaction height rather than the earliest as the height to rescan from. Found by @evanlinjin and I while implementing `bdk_core` stuff into bdk's wallet. ### Changelog notice - Fix wallet export transaction height #### All Submissions: * [x] I've signed all my commits * [x] This pull request breaks the existing API * [x] I've added tests to reproduce the issue which are now passing ACKs for top commit: rajarshimaitra: tACK e9bbb87 notmandatory: ACK e9bbb87 Tree-SHA512: 9b29ef0df39d26806f48b38fa5c3643bad32f58b993ffdcfc7811aca64a025bd8f163967321f874aa2ef3d29c3e7bc6e2f44d348306a37111f4def036d4c095e
2 parents 5c42102 + e9bbb87 commit 108edc3

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/wallet/export.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,11 @@ impl FullyNodedExport {
134134
let blockheight = match wallet.database.borrow().iter_txs(false) {
135135
_ if !include_blockheight => 0,
136136
Err(_) => 0,
137-
Ok(txs) => {
138-
let mut heights = txs
139-
.into_iter()
140-
.map(|tx| tx.confirmation_time.map(|c| c.height).unwrap_or(0))
141-
.collect::<Vec<_>>();
142-
heights.sort_unstable();
143-
144-
*heights.last().unwrap_or(&0)
145-
}
137+
Ok(txs) => txs
138+
.into_iter()
139+
.filter_map(|tx| tx.confirmation_time.map(|c| c.height))
140+
.min()
141+
.unwrap_or(0),
146142
};
147143

148144
let export = FullyNodedExport {
@@ -249,6 +245,22 @@ mod test {
249245
fee: Some(500),
250246
confirmation_time: Some(BlockTime {
251247
timestamp: 12345678,
248+
height: 5001,
249+
}),
250+
})
251+
.unwrap();
252+
253+
db.set_tx(&TransactionDetails {
254+
transaction: None,
255+
txid: Txid::from_str(
256+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
257+
)
258+
.unwrap(),
259+
received: 25_000,
260+
sent: 0,
261+
fee: Some(300),
262+
confirmation_time: Some(BlockTime {
263+
timestamp: 12345677,
252264
height: 5000,
253265
}),
254266
})

0 commit comments

Comments
 (0)