Split init module into chain and wallet-related parts.
This commit is contained in:
parent
a181203179
commit
22ef05239c
|
@ -84,6 +84,8 @@ use zcash_client_backend::{
|
|||
|
||||
use crate::{error::SqliteClientError, CacheConnection};
|
||||
|
||||
pub mod init;
|
||||
|
||||
struct CompactBlockRow {
|
||||
height: BlockHeight,
|
||||
data: Vec<u8>,
|
||||
|
@ -195,12 +197,16 @@ mod tests {
|
|||
};
|
||||
|
||||
use crate::{
|
||||
init::{init_accounts_table, init_cache_database, init_data_database},
|
||||
chain::init::init_cache_database,
|
||||
tests::{
|
||||
self, fake_compact_block, fake_compact_block_spending, insert_into_cache,
|
||||
sapling_activation_height,
|
||||
},
|
||||
wallet::{get_balance, rewind_to_height},
|
||||
wallet::{
|
||||
get_balance,
|
||||
init::{init_accounts_table, init_data_database},
|
||||
rewind_to_height,
|
||||
},
|
||||
AccountId, CacheConnection, DataConnection, NoteId,
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
//! Functions for initializing the various databases.
|
||||
|
||||
use rusqlite::NO_PARAMS;
|
||||
|
||||
use crate::CacheConnection;
|
||||
|
||||
/// Sets up the internal structure of the cache database.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use tempfile::NamedTempFile;
|
||||
/// use zcash_client_sqlite::{
|
||||
/// CacheConnection,
|
||||
/// init::init_cache_database,
|
||||
/// };
|
||||
///
|
||||
/// let cache_file = NamedTempFile::new().unwrap();
|
||||
/// let db = CacheConnection::for_path(cache_file.path()).unwrap();
|
||||
/// init_cache_database(&db).unwrap();
|
||||
/// ```
|
||||
pub fn init_cache_database(db_cache: &CacheConnection) -> Result<(), rusqlite::Error> {
|
||||
db_cache.0.execute(
|
||||
"CREATE TABLE IF NOT EXISTS compactblocks (
|
||||
height INTEGER PRIMARY KEY,
|
||||
data BLOB NOT NULL
|
||||
)",
|
||||
NO_PARAMS,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
|
@ -53,7 +53,6 @@ use crate::error::SqliteClientError;
|
|||
|
||||
pub mod chain;
|
||||
pub mod error;
|
||||
pub mod init;
|
||||
pub mod transact;
|
||||
pub mod wallet;
|
||||
|
||||
|
@ -80,7 +79,7 @@ impl<'a> DBOps for &'a DataConnection {
|
|||
type UpdateOps = DataConnStmtCache<'a>;
|
||||
|
||||
fn init_db(&self) -> Result<(), Self::Error> {
|
||||
init::init_data_database(self).map_err(SqliteClientError::from)
|
||||
wallet::init::init_data_database(self).map_err(SqliteClientError::from)
|
||||
}
|
||||
|
||||
fn init_account_storage<P: consensus::Parameters>(
|
||||
|
@ -88,7 +87,7 @@ impl<'a> DBOps for &'a DataConnection {
|
|||
params: &P,
|
||||
extfvks: &[ExtendedFullViewingKey],
|
||||
) -> Result<(), Self::Error> {
|
||||
init::init_accounts_table(self, params, extfvks)
|
||||
wallet::init::init_accounts_table(self, params, extfvks)
|
||||
}
|
||||
|
||||
fn init_block_storage(
|
||||
|
@ -98,7 +97,7 @@ impl<'a> DBOps for &'a DataConnection {
|
|||
time: u32,
|
||||
sapling_tree: &[u8],
|
||||
) -> Result<(), Self::Error> {
|
||||
init::init_blocks_table(self, height, hash, time, sapling_tree)
|
||||
wallet::init::init_blocks_table(self, height, hash, time, sapling_tree)
|
||||
}
|
||||
|
||||
fn block_height_extrema(&self) -> Result<Option<(BlockHeight, BlockHeight)>, Self::Error> {
|
||||
|
@ -534,7 +533,7 @@ impl CacheOps for CacheConnection {
|
|||
type Error = SqliteClientError;
|
||||
|
||||
fn init_cache(&self) -> Result<(), Self::Error> {
|
||||
init::init_cache_database(self).map_err(SqliteClientError::from)
|
||||
chain::init::init_cache_database(self).map_err(SqliteClientError::from)
|
||||
}
|
||||
|
||||
fn validate_chain<F>(
|
||||
|
|
|
@ -389,9 +389,12 @@ mod tests {
|
|||
use zcash_client_backend::data_api::chain::scan_cached_blocks;
|
||||
|
||||
use crate::{
|
||||
init::{init_accounts_table, init_blocks_table, init_cache_database, init_data_database},
|
||||
chain::init::init_cache_database,
|
||||
tests::{self, fake_compact_block, insert_into_cache, sapling_activation_height},
|
||||
wallet::{get_balance, get_verified_balance},
|
||||
wallet::{
|
||||
get_balance, get_verified_balance,
|
||||
init::{init_accounts_table, init_blocks_table, init_data_database},
|
||||
},
|
||||
AccountId, CacheConnection, DataConnection,
|
||||
};
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ use zcash_client_backend::{
|
|||
|
||||
use crate::{error::SqliteClientError, AccountId, DataConnection, NoteId};
|
||||
|
||||
pub mod init;
|
||||
|
||||
/// Returns the address for the account.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -424,8 +426,9 @@ mod tests {
|
|||
use zcash_client_backend::data_api::error::Error;
|
||||
|
||||
use crate::{
|
||||
init::{init_accounts_table, init_data_database},
|
||||
tests, AccountId, DataConnection,
|
||||
tests,
|
||||
wallet::init::{init_accounts_table, init_data_database},
|
||||
AccountId, DataConnection,
|
||||
};
|
||||
|
||||
use super::{get_address, get_balance, get_verified_balance};
|
||||
|
|
|
@ -10,33 +10,7 @@ use zcash_primitives::{
|
|||
|
||||
use zcash_client_backend::{data_api::error::Error, encoding::encode_extended_full_viewing_key};
|
||||
|
||||
use crate::{address_from_extfvk, error::SqliteClientError, CacheConnection, DataConnection};
|
||||
|
||||
/// Sets up the internal structure of the cache database.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use tempfile::NamedTempFile;
|
||||
/// use zcash_client_sqlite::{
|
||||
/// CacheConnection,
|
||||
/// init::init_cache_database,
|
||||
/// };
|
||||
///
|
||||
/// let cache_file = NamedTempFile::new().unwrap();
|
||||
/// let db = CacheConnection::for_path(cache_file.path()).unwrap();
|
||||
/// init_cache_database(&db).unwrap();
|
||||
/// ```
|
||||
pub fn init_cache_database(db_cache: &CacheConnection) -> Result<(), rusqlite::Error> {
|
||||
db_cache.0.execute(
|
||||
"CREATE TABLE IF NOT EXISTS compactblocks (
|
||||
height INTEGER PRIMARY KEY,
|
||||
data BLOB NOT NULL
|
||||
)",
|
||||
NO_PARAMS,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
use crate::{address_from_extfvk, error::SqliteClientError, DataConnection};
|
||||
|
||||
/// Sets up the internal structure of the data database.
|
||||
///
|
Loading…
Reference in New Issue