Add database initialization implementation.

This commit is contained in:
Kris Nuttycombe 2020-08-04 16:34:09 -06:00
parent f3f3512068
commit 724fbac33a
2 changed files with 11 additions and 3 deletions

View File

@ -21,7 +21,7 @@ pub trait DBOps {
// type TxRef; // Backend-specific transaction handle // type TxRef; // Backend-specific transaction handle
// type NoteRef; // Backend-specific note identifier` // type NoteRef; // Backend-specific note identifier`
// fn init_db() -> Result<(), Self::Error>; fn init_db(&self) -> Result<(), Self::Error>;
// //
// fn init_accounts(extfvks: &[ExtendedFullViewingKey]) -> Result<(), Self::Error>; // fn init_accounts(extfvks: &[ExtendedFullViewingKey]) -> Result<(), Self::Error>;
// //
@ -42,8 +42,6 @@ pub trait DBOps {
block_height: BlockHeight, block_height: BlockHeight,
) -> Result<(), Self::Error>; ) -> Result<(), Self::Error>;
// //
// // fn get_target_and_anchor_heights() -> Result<(u32, u32), Self::Error>;
//
// fn get_address(account: Account) -> Result<String, Self::Error>; // fn get_address(account: Account) -> Result<String, Self::Error>;
// //
// fn get_balance(account: Account) -> Result<Amount, Self::Error>; // fn get_balance(account: Account) -> Result<Amount, Self::Error>;
@ -84,6 +82,8 @@ pub trait DBOps {
pub trait CacheOps { pub trait CacheOps {
type Error; type Error;
fn init_cache(&self) -> Result<(), Self::Error>;
// Validate the cached chain by applying a function that checks pairwise constraints // Validate the cached chain by applying a function that checks pairwise constraints
// (top_block :: &CompactBlock, next_block :: &CompactBlock) -> Result<(), Self::Error) // (top_block :: &CompactBlock, next_block :: &CompactBlock) -> Result<(), Self::Error)
// beginning with the current maximum height walking backward through the chain, terminating // beginning with the current maximum height walking backward through the chain, terminating

View File

@ -59,6 +59,10 @@ impl DataConnection {
impl DBOps for DataConnection { impl DBOps for DataConnection {
type Error = Error<rusqlite::Error>; type Error = Error<rusqlite::Error>;
fn init_db(&self) -> Result<(), Self::Error> {
init::init_data_database(self).map_err(Error::Database)
}
fn block_height_extrema(&self) -> Result<Option<(BlockHeight, BlockHeight)>, Self::Error> { fn block_height_extrema(&self) -> Result<Option<(BlockHeight, BlockHeight)>, Self::Error> {
chain::block_height_extrema(self).map_err(Error::Database) chain::block_height_extrema(self).map_err(Error::Database)
} }
@ -87,6 +91,10 @@ impl CacheConnection {
impl CacheOps for CacheConnection { impl CacheOps for CacheConnection {
type Error = Error<rusqlite::Error>; type Error = Error<rusqlite::Error>;
fn init_cache(&self) -> Result<(), Self::Error> {
init::init_cache_database(self).map_err(Error::Database)
}
fn validate_chain<F>( fn validate_chain<F>(
&self, &self,
from_height: BlockHeight, from_height: BlockHeight,