[database] Wrap BlockTime in another struct to allow adding more

fields in the future
This commit is contained in:
Alekos Filini
2021-11-04 15:38:38 +00:00
parent 2c77329333
commit 5830226216
6 changed files with 103 additions and 88 deletions

View File

@@ -18,7 +18,7 @@ use bitcoin::hash_types::Txid;
use bitcoin::{OutPoint, Script, Transaction};
use crate::database::memory::MapKey;
use crate::database::{BatchDatabase, BatchOperations, Database};
use crate::database::{BatchDatabase, BatchOperations, Database, SyncTime};
use crate::error::Error;
use crate::types::*;
@@ -82,9 +82,9 @@ macro_rules! impl_batch_operations {
Ok(())
}
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)*;
fn set_sync_time(&mut self, data: SyncTime) -> Result<(), Error> {
let key = MapKey::SyncTime.as_map_key();
self.insert(key, serde_json::to_vec(&data)?)$($after_insert)*;
Ok(())
}
@@ -176,8 +176,8 @@ macro_rules! impl_batch_operations {
}
}
fn del_last_sync_time(&mut self) -> Result<Option<BlockTime>, Error> {
let key = MapKey::LastSyncTime.as_map_key();
fn del_sync_time(&mut self) -> Result<Option<SyncTime>, Error> {
let key = MapKey::SyncTime.as_map_key();
let res = self.remove(key);
let res = $process_delete!(res);
@@ -357,8 +357,8 @@ impl Database for Tree {
.transpose()
}
fn get_last_sync_time(&self) -> Result<Option<BlockTime>, Error> {
let key = MapKey::LastSyncTime.as_map_key();
fn get_sync_time(&self) -> Result<Option<SyncTime>, Error> {
let key = MapKey::SyncTime.as_map_key();
Ok(self
.get(key)?
.map(|b| serde_json::from_slice(&b))
@@ -495,7 +495,7 @@ mod test {
}
#[test]
fn test_last_sync_time() {
crate::database::test::test_last_sync_time(get_tree());
fn test_sync_time() {
crate::database::test::test_sync_time(get_tree());
}
}