diff --git a/src/database/mod.rs b/src/database/mod.rs index 3940b7eb..3657b7e3 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -81,6 +81,14 @@ pub trait DatabaseConnection { /// Mark the rescan as complete. fn complete_rescan(&mut self); + /// Get the timestamp at which the last poll of the blockchain completed, if any, + /// as the number of seconds since the UNIX epoch. + fn last_poll_timestamp(&mut self) -> Option; + + /// Set the timestamp at which the last poll of the blockchain completed, + /// where `timestamp` should be given as the number of seconds since the UNIX epoch. + fn set_last_poll(&mut self, timestamp: u32); + /// Get the derivation index for this address, as well as whether this address is change. fn derivation_index_by_address( &mut self, @@ -220,6 +228,15 @@ impl DatabaseConnection for SqliteConn { self.complete_wallet_rescan() } + fn last_poll_timestamp(&mut self) -> Option { + self.db_wallet().last_poll_timestamp + } + + fn set_last_poll(&mut self, timestamp: u32) { + self.set_wallet_last_poll_timestamp(timestamp) + .expect("database must be available") + } + fn coins( &mut self, statuses: &[CoinStatus], diff --git a/src/testutils.rs b/src/testutils.rs index a5642b70..44dea5ee 100644 --- a/src/testutils.rs +++ b/src/testutils.rs @@ -149,6 +149,7 @@ struct DummyDbState { txs: HashMap, spend_txs: HashMap)>, timestamp: u32, + last_poll_timestamp: Option, } pub struct DummyDatabase { @@ -181,6 +182,7 @@ impl DummyDatabase { txs: HashMap::new(), spend_txs: HashMap::new(), timestamp: now, + last_poll_timestamp: None, })), } } @@ -411,6 +413,14 @@ impl DatabaseConnection for DummyDatabase { todo!() } + fn last_poll_timestamp(&mut self) -> Option { + self.db.read().unwrap().last_poll_timestamp + } + + fn set_last_poll(&mut self, timestamp: u32) { + self.db.write().unwrap().last_poll_timestamp = Some(timestamp); + } + fn update_labels(&mut self, _items: &HashMap>) { todo!() }