Rename ConfirmationTime to BlockTime
This commit is contained in:
@@ -144,7 +144,7 @@ impl BatchOperations for AnyDatabase {
|
||||
fn set_last_index(&mut self, keychain: KeychainKind, value: u32) -> Result<(), Error> {
|
||||
impl_inner_method!(AnyDatabase, self, set_last_index, keychain, value)
|
||||
}
|
||||
fn set_last_sync_time(&mut self, last_sync_time: ConfirmationTime) -> Result<(), Error> {
|
||||
fn set_last_sync_time(&mut self, last_sync_time: BlockTime) -> Result<(), Error> {
|
||||
impl_inner_method!(AnyDatabase, self, set_last_sync_time, last_sync_time)
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ impl BatchOperations for AnyDatabase {
|
||||
fn del_last_index(&mut self, keychain: KeychainKind) -> Result<Option<u32>, Error> {
|
||||
impl_inner_method!(AnyDatabase, self, del_last_index, keychain)
|
||||
}
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
|
||||
impl_inner_method!(AnyDatabase, self, del_last_sync_time)
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ impl Database for AnyDatabase {
|
||||
fn get_last_index(&self, keychain: KeychainKind) -> Result<Option<u32>, Error> {
|
||||
impl_inner_method!(AnyDatabase, self, get_last_index, keychain)
|
||||
}
|
||||
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
|
||||
impl_inner_method!(AnyDatabase, self, get_last_sync_time)
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ impl BatchOperations for AnyBatch {
|
||||
fn set_last_index(&mut self, keychain: KeychainKind, value: u32) -> Result<(), Error> {
|
||||
impl_inner_method!(AnyBatch, self, set_last_index, keychain, value)
|
||||
}
|
||||
fn set_last_sync_time(&mut self, last_sync_time: ConfirmationTime) -> Result<(), Error> {
|
||||
fn set_last_sync_time(&mut self, last_sync_time: BlockTime) -> Result<(), Error> {
|
||||
impl_inner_method!(AnyBatch, self, set_last_sync_time, last_sync_time)
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ impl BatchOperations for AnyBatch {
|
||||
fn del_last_index(&mut self, keychain: KeychainKind) -> Result<Option<u32>, Error> {
|
||||
impl_inner_method!(AnyBatch, self, del_last_index, keychain)
|
||||
}
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
|
||||
impl_inner_method!(AnyBatch, self, del_last_sync_time)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ macro_rules! impl_batch_operations {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_last_sync_time(&mut self, ct: ConfirmationTime) -> Result<(), Error> {
|
||||
fn set_last_sync_time(&mut self, ct: BlockTime) -> Result<(), Error> {
|
||||
let key = MapKey::LastSyncTime.as_map_key();
|
||||
self.insert(key, serde_json::to_vec(&ct)?)$($after_insert)*;
|
||||
|
||||
@@ -176,7 +176,7 @@ macro_rules! impl_batch_operations {
|
||||
}
|
||||
}
|
||||
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
|
||||
let key = MapKey::LastSyncTime.as_map_key();
|
||||
let res = self.remove(key);
|
||||
let res = $process_delete!(res);
|
||||
@@ -357,7 +357,7 @@ impl Database for Tree {
|
||||
.transpose()
|
||||
}
|
||||
|
||||
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
|
||||
let key = MapKey::LastSyncTime.as_map_key();
|
||||
Ok(self
|
||||
.get(key)?
|
||||
|
||||
@@ -183,7 +183,7 @@ impl BatchOperations for MemoryDatabase {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
fn set_last_sync_time(&mut self, ct: ConfirmationTime) -> Result<(), Error> {
|
||||
fn set_last_sync_time(&mut self, ct: BlockTime) -> Result<(), Error> {
|
||||
let key = MapKey::LastSyncTime.as_map_key();
|
||||
self.map.insert(key, Box::new(ct));
|
||||
|
||||
@@ -279,7 +279,7 @@ impl BatchOperations for MemoryDatabase {
|
||||
Some(b) => Ok(Some(*b.downcast_ref().unwrap())),
|
||||
}
|
||||
}
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
|
||||
let key = MapKey::LastSyncTime.as_map_key();
|
||||
let res = self.map.remove(&key);
|
||||
self.deleted_keys.push(key);
|
||||
@@ -423,7 +423,7 @@ impl Database for MemoryDatabase {
|
||||
Ok(self.map.get(&key).map(|b| *b.downcast_ref().unwrap()))
|
||||
}
|
||||
|
||||
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
|
||||
let key = MapKey::LastSyncTime.as_map_key();
|
||||
Ok(self
|
||||
.map
|
||||
@@ -505,7 +505,7 @@ macro_rules! populate_test_db {
|
||||
let txid = tx.txid();
|
||||
let confirmation_time = tx_meta
|
||||
.min_confirmations
|
||||
.map(|conf| $crate::ConfirmationTime {
|
||||
.map(|conf| $crate::BlockTime {
|
||||
height: current_height.unwrap().checked_sub(conf as u32).unwrap(),
|
||||
timestamp: 0,
|
||||
});
|
||||
|
||||
@@ -65,7 +65,7 @@ pub trait BatchOperations {
|
||||
/// Store the last derivation index for a given keychain.
|
||||
fn set_last_index(&mut self, keychain: KeychainKind, value: u32) -> Result<(), Error>;
|
||||
/// Store the sync time in terms of block height and timestamp
|
||||
fn set_last_sync_time(&mut self, last_sync_time: ConfirmationTime) -> Result<(), Error>;
|
||||
fn set_last_sync_time(&mut self, last_sync_time: BlockTime) -> Result<(), Error>;
|
||||
|
||||
/// Delete a script_pubkey given the keychain and its child number.
|
||||
fn del_script_pubkey_from_path(
|
||||
@@ -94,7 +94,7 @@ pub trait BatchOperations {
|
||||
/// Reset the last sync time to `None`
|
||||
///
|
||||
/// Returns the removed value
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error>;
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error>;
|
||||
}
|
||||
|
||||
/// Trait for reading data from a database
|
||||
@@ -141,7 +141,7 @@ pub trait Database: BatchOperations {
|
||||
/// Return the last defivation index for a keychain.
|
||||
fn get_last_index(&self, keychain: KeychainKind) -> Result<Option<u32>, Error>;
|
||||
/// Return the last sync time, if present
|
||||
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error>;
|
||||
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error>;
|
||||
|
||||
/// Increment the last derivation index for a keychain and return it
|
||||
///
|
||||
@@ -333,7 +333,7 @@ pub mod test {
|
||||
received: 1337,
|
||||
sent: 420420,
|
||||
fee: Some(140),
|
||||
confirmation_time: Some(ConfirmationTime {
|
||||
confirmation_time: Some(BlockTime {
|
||||
timestamp: 123456,
|
||||
height: 1000,
|
||||
}),
|
||||
@@ -388,7 +388,7 @@ pub mod test {
|
||||
pub fn test_last_sync_time<D: Database>(mut tree: D) {
|
||||
assert!(tree.get_last_sync_time().unwrap().is_none());
|
||||
|
||||
tree.set_last_sync_time(ConfirmationTime {
|
||||
tree.set_last_sync_time(BlockTime {
|
||||
height: 100,
|
||||
timestamp: 1000,
|
||||
})
|
||||
|
||||
@@ -206,7 +206,7 @@ impl SqliteDatabase {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_last_sync_time(&self, ct: ConfirmationTime) -> Result<i64, Error> {
|
||||
fn update_last_sync_time(&self, ct: BlockTime) -> Result<i64, Error> {
|
||||
let mut statement = self.connection.prepare_cached(
|
||||
"INSERT INTO last_sync_time (id, height, timestamp) VALUES (0, :height, :timestamp) ON CONFLICT(id) DO UPDATE SET height=:height, timestamp=:timestamp WHERE id = 0",
|
||||
)?;
|
||||
@@ -389,7 +389,7 @@ impl SqliteDatabase {
|
||||
};
|
||||
|
||||
let confirmation_time = match (height, timestamp) {
|
||||
(Some(height), Some(timestamp)) => Some(ConfirmationTime { height, timestamp }),
|
||||
(Some(height), Some(timestamp)) => Some(BlockTime { height, timestamp }),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@@ -423,7 +423,7 @@ impl SqliteDatabase {
|
||||
let verified: bool = row.get(6)?;
|
||||
|
||||
let confirmation_time = match (height, timestamp) {
|
||||
(Some(height), Some(timestamp)) => Some(ConfirmationTime { height, timestamp }),
|
||||
(Some(height), Some(timestamp)) => Some(BlockTime { height, timestamp }),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@@ -466,7 +466,7 @@ impl SqliteDatabase {
|
||||
};
|
||||
|
||||
let confirmation_time = match (height, timestamp) {
|
||||
(Some(height), Some(timestamp)) => Some(ConfirmationTime { height, timestamp }),
|
||||
(Some(height), Some(timestamp)) => Some(BlockTime { height, timestamp }),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@@ -501,12 +501,12 @@ impl SqliteDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
fn select_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn select_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
|
||||
let mut statement = self
|
||||
.connection
|
||||
.prepare_cached("SELECT height, timestamp FROM last_sync_time WHERE id = 0")?;
|
||||
let mut rows = statement.query_map([], |row| {
|
||||
Ok(ConfirmationTime {
|
||||
Ok(BlockTime {
|
||||
height: row.get(0)?,
|
||||
timestamp: row.get(1)?,
|
||||
})
|
||||
@@ -658,7 +658,7 @@ impl BatchOperations for SqliteDatabase {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_last_sync_time(&mut self, ct: ConfirmationTime) -> Result<(), Error> {
|
||||
fn set_last_sync_time(&mut self, ct: BlockTime) -> Result<(), Error> {
|
||||
self.update_last_sync_time(ct)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -749,7 +749,7 @@ impl BatchOperations for SqliteDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
|
||||
match self.select_last_sync_time()? {
|
||||
Some(value) => {
|
||||
self.delete_last_sync_time()?;
|
||||
@@ -870,7 +870,7 @@ impl Database for SqliteDatabase {
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn get_last_sync_time(&self) -> Result<Option<ConfirmationTime>, Error> {
|
||||
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
|
||||
self.select_last_sync_time()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user