Skip to content

Commit 7c06f52

Browse files
committed
[wallet] Store the block height and timestamp after syncing
Closes #455
1 parent 12e51b3 commit 7c06f52

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/testutils/blockchain_tests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ macro_rules! bdk_blockchain_tests {
394394

395395
#[test]
396396
fn test_sync_simple() {
397+
use std::ops::Deref;
398+
use crate::database::Database;
399+
397400
let (wallet, descriptors, mut test_client) = init_single_sig();
398401

399402
let tx = testutils! {
@@ -402,7 +405,13 @@ macro_rules! bdk_blockchain_tests {
402405
println!("{:?}", tx);
403406
let txid = test_client.receive(tx);
404407

408+
// the RPC blockchain needs to call `sync()` during initialization to import the
409+
// addresses (see `init_single_sig()`), so we skip this assertion
410+
#[cfg(not(feature = "test-rpc"))]
411+
assert!(wallet.database().deref().get_sync_time().unwrap().is_none(), "initial sync_time not none");
412+
405413
wallet.sync(noop_progress(), None).unwrap();
414+
assert!(wallet.database().deref().get_sync_time().unwrap().is_some(), "sync_time hasn't been updated");
406415

407416
assert_eq!(wallet.get_balance().unwrap(), 50_000, "incorrect balance");
408417
assert_eq!(wallet.list_unspent().unwrap()[0].keychain, KeychainKind::External, "incorrect keychain kind");

src/wallet/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,15 @@ where
15541554
}
15551555
}
15561556

1557+
let last_sync_time = ConfirmationTime {
1558+
height: maybe_await!(self.client.get_height())?,
1559+
timestamp: time::get_timestamp(),
1560+
};
1561+
debug!("Saving `last_sync_time` = {:?}", last_sync_time);
1562+
self.database
1563+
.borrow_mut()
1564+
.set_last_sync_time(last_sync_time)?;
1565+
15571566
Ok(())
15581567
}
15591568

0 commit comments

Comments
 (0)