bitcoin: make tip_time return an Option
In preparation of making get_block_stats() fallible.
This commit is contained in:
parent
d967dc1476
commit
869779dd94
@ -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()
|
||||
}
|
||||
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -106,7 +106,7 @@ impl BitcoinInterface for DummyBitcoind {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn tip_time(&self) -> u32 {
|
||||
fn tip_time(&self) -> Option<u32> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user