bitcoin: make tip_time return an Option

In preparation of making get_block_stats() fallible.
This commit is contained in:
Antoine Poinsot 2023-10-27 18:36:21 +02:00
parent d967dc1476
commit 869779dd94
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
3 changed files with 11 additions and 6 deletions

View File

@ -51,7 +51,7 @@ pub trait BitcoinInterface: Send {
fn chain_tip(&self) -> BlockChainTip;
/// Get the timestamp set in the best block's header.
fn tip_time(&self) -> u32;
fn tip_time(&self) -> Option<u32>;
/// Check whether this former tip is part of the current best chain.
fn is_in_chain(&self, tip: &BlockChainTip) -> bool;
@ -316,9 +316,9 @@ impl BitcoinInterface for d::BitcoinD {
self.tip_before_timestamp(timestamp)
}
fn tip_time(&self) -> u32 {
fn tip_time(&self) -> Option<u32> {
let tip = self.chain_tip();
self.get_block_stats(tip.hash).time
Some(self.get_block_stats(tip.hash).time)
}
fn wallet_transaction(
@ -400,7 +400,7 @@ impl BitcoinInterface for sync::Arc<sync::Mutex<dyn BitcoinInterface + 'static>>
self.lock().unwrap().block_before_date(timestamp)
}
fn tip_time(&self) -> u32 {
fn tip_time(&self) -> Option<u32> {
self.lock().unwrap().tip_time()
}

View File

@ -694,7 +694,12 @@ impl DaemonControl {
pub fn start_rescan(&self, timestamp: u32) -> Result<(), CommandError> {
let mut db_conn = self.db.connection();
if timestamp < MAINNET_GENESIS_TIME || timestamp >= self.bitcoin.tip_time() {
let future_timestamp = self
.bitcoin
.tip_time()
.map(|t| timestamp >= t)
.unwrap_or(false);
if timestamp < MAINNET_GENESIS_TIME || future_timestamp {
return Err(CommandError::InsaneRescanTimestamp(timestamp));
}
if db_conn.rescan_timestamp().is_some() || self.bitcoin.rescan_progress().is_some() {

View File

@ -106,7 +106,7 @@ impl BitcoinInterface for DummyBitcoind {
todo!()
}
fn tip_time(&self) -> u32 {
fn tip_time(&self) -> Option<u32> {
todo!()
}