Remove cyclic dev dependency between zcash_client_backend and zcash_client_sqlite.

This commit is contained in:
Kris Nuttycombe 2022-01-20 20:55:34 -07:00
parent f75ffb0eaf
commit 8f408354b9
5 changed files with 32 additions and 82 deletions

View File

@ -43,7 +43,6 @@ protobuf-codegen-pure = "2.20"
gumdrop = "0.8"
rand_xorshift = "0.3"
tempfile = "3.1.0"
zcash_client_sqlite = { version = "0.3", path = "../zcash_client_sqlite", features = ["transparent-inputs"] }
zcash_proofs = { version = "0.5", path = "../zcash_proofs" }
[features]

View File

@ -4,7 +4,8 @@
//! # Examples
//!
//! ```
//! use tempfile::NamedTempFile;
//! # #[cfg(feature = "test-dependencies")]
//! # {
//! use zcash_primitives::{
//! consensus::{BlockHeight, Network, Parameters}
//! };
@ -17,32 +18,18 @@
//! scan_cached_blocks,
//! },
//! error::Error,
//! testing,
//! },
//! };
//!
//! use zcash_client_sqlite::{
//! BlockDb,
//! WalletDb,
//! error::SqliteClientError,
//! wallet::{rewind_to_height},
//! wallet::init::{init_wallet_db},
//! };
//!
//! # // doctests have a problem with sqlite IO, so we ignore errors
//! # // generated in this example code as it's not really testing anything
//! # fn main() {
//! # test();
//! # }
//! #
//! # fn test() -> Result<(), SqliteClientError> {
//! # fn test() -> Result<(), Error<u32>> {
//! let network = Network::TestNetwork;
//! let cache_file = NamedTempFile::new()?;
//! let db_cache = BlockDb::for_path(cache_file)?;
//! let db_file = NamedTempFile::new()?;
//! let db_read = WalletDb::for_path(db_file, network)?;
//! init_wallet_db(&db_read)?;
//!
//! let mut db_data = db_read.get_update_ops()?;
//! let db_cache = testing::MockBlockSource {};
//! let mut db_data = testing::MockWalletDb {};
//!
//! // 1) Download new CompactBlocks into db_cache.
//!
@ -52,7 +39,7 @@
//! // errors are in the blocks we have previously cached or scanned.
//! if let Err(e) = validate_chain(&network, &db_cache, db_data.get_max_height_hash()?) {
//! match e {
//! SqliteClientError::BackendError(Error::InvalidChain(lower_bound, _)) => {
//! Error::InvalidChain(lower_bound, _) => {
//! // a) Pick a height to rewind to.
//! //
//! // This might be informed by some external chain reorg information, or
@ -72,10 +59,10 @@
//! // d) If there is some separate thread or service downloading
//! // CompactBlocks, tell it to go back and download from rewind_height
//! // onwards.
//! }
//! },
//! e => {
//! // Handle or return other errors.
//! return Err(e);
//! // handle or return other errors
//!
//! }
//! }
//! }
@ -87,6 +74,7 @@
//! // next time this codepath is executed after new blocks are received).
//! scan_cached_blocks(&network, &db_cache, &mut db_data, None)
//! # }
//! # }
//! ```
use std::fmt::Debug;
@ -198,44 +186,6 @@ where
///
/// Scanned blocks are required to be height-sequential. If a block is missing from the
/// cache, an error will be returned with kind [`ChainInvalid::BlockHeightDiscontinuity`].
///
/// # Examples
///
/// ```
/// use tempfile::NamedTempFile;
/// use zcash_primitives::consensus::{
/// Network,
/// Parameters,
/// };
/// use zcash_client_backend::{
/// data_api::chain::scan_cached_blocks,
/// };
/// use zcash_client_sqlite::{
/// BlockDb,
/// WalletDb,
/// error::SqliteClientError,
/// wallet::init::init_wallet_db,
/// };
///
/// # // doctests have a problem with sqlite IO, so we ignore errors
/// # // generated in this example code as it's not really testing anything
/// # fn main() {
/// # test();
/// # }
/// #
/// # fn test() -> Result<(), SqliteClientError> {
/// let cache_file = NamedTempFile::new().unwrap();
/// let cache = BlockDb::for_path(cache_file).unwrap();
///
/// let data_file = NamedTempFile::new().unwrap();
/// let db_read = WalletDb::for_path(data_file, Network::TestNetwork)?;
/// init_wallet_db(&db_read)?;
///
/// let mut data = db_read.get_update_ops()?;
/// scan_cached_blocks(&Network::TestNetwork, &cache, &mut data, None)?;
/// # Ok(())
/// # }
/// ```
pub fn scan_cached_blocks<E, N, P, C, D>(
params: &P,
cache: &C,

View File

@ -95,31 +95,27 @@ where
/// # Examples
///
/// ```
/// # #[cfg(feature = "test-dependencies")]
/// # {
/// use tempfile::NamedTempFile;
/// use zcash_primitives::{
/// consensus::{self, Network},
/// constants::testnet::COIN_TYPE,
/// transaction::components::Amount
/// transaction::{TxId, components::Amount},
/// };
/// use zcash_proofs::prover::LocalTxProver;
/// use zcash_client_backend::{
/// keys::sapling,
/// data_api::wallet::create_spend_to_address,
/// data_api::{wallet::create_spend_to_address, error::Error, testing},
/// wallet::{AccountId, OvkPolicy},
/// };
/// use zcash_client_sqlite::{
/// WalletDb,
/// error::SqliteClientError,
/// wallet::init::init_wallet_db,
/// };
///
/// # // doctests have a problem with sqlite IO, so we ignore errors
/// # // generated in this example code as it's not really testing anything
/// # fn main() {
/// # test();
/// # }
/// #
/// # fn test() -> Result<(), SqliteClientError> {
/// # fn test() -> Result<TxId, Error<u32>> {
///
/// let tx_prover = match LocalTxProver::with_default_location() {
/// Some(tx_prover) => tx_prover,
/// None => {
@ -131,13 +127,10 @@ where
/// let extsk = sapling::spending_key(&[0; 32][..], COIN_TYPE, account);
/// let to = extsk.default_address().1.into();
///
/// let data_file = NamedTempFile::new().unwrap();
/// let db_read = WalletDb::for_path(data_file, Network::TestNetwork).unwrap();
/// init_wallet_db(&db_read)?;
/// let mut db = db_read.get_update_ops()?;
/// let mut db_read = testing::MockWalletDb {};
///
/// create_spend_to_address(
/// &mut db,
/// &mut db_read,
/// &Network::TestNetwork,
/// tx_prover,
/// account,
@ -147,9 +140,9 @@ where
/// None,
/// OvkPolicy::Sender,
/// 10
/// )?;
/// )
///
/// # Ok(())
/// # }
/// # }
/// ```
#[allow(clippy::too_many_arguments)]

View File

@ -212,6 +212,7 @@ pub mod transparent {
#[derive(Clone, Debug)]
pub struct UnifiedFullViewingKey {
account: AccountId,
#[cfg(feature = "transparent-inputs")]
transparent: Option<transparent::AccountPubKey>,
sapling: Option<sapling::ExtendedFullViewingKey>,
}
@ -220,7 +221,7 @@ impl UnifiedFullViewingKey {
/// Construct a new unified full viewing key, if the required components are present.
pub fn new(
account: AccountId,
transparent: Option<transparent::AccountPubKey>,
#[cfg(feature = "transparent-inputs")] transparent: Option<transparent::AccountPubKey>,
sapling: Option<sapling::ExtendedFullViewingKey>,
) -> Option<UnifiedFullViewingKey> {
if sapling.is_none() {
@ -228,6 +229,7 @@ impl UnifiedFullViewingKey {
} else {
Some(UnifiedFullViewingKey {
account,
#[cfg(feature = "transparent-inputs")]
transparent,
sapling,
})
@ -240,6 +242,7 @@ impl UnifiedFullViewingKey {
self.account
}
#[cfg(feature = "transparent-inputs")]
/// Returns the transparent component of the unified key at the
/// BIP44 path `m/44'/<coin_type>'/<account>'`.
pub fn transparent(&self) -> Option<&transparent::AccountPubKey> {

View File

@ -8,12 +8,14 @@ use zcash_primitives::{
};
use zcash_client_backend::{
encoding::{encode_extended_full_viewing_key, AddressCodec},
keys::UnifiedFullViewingKey,
encoding::encode_extended_full_viewing_key, keys::UnifiedFullViewingKey,
};
use crate::{address_from_extfvk, error::SqliteClientError, WalletDb};
#[cfg(feature = "transparent-inputs")]
use zcash_client_backend::encoding::AddressCodec;
/// Sets up the internal structure of the data database.
///
/// The database structure is the same irrespective of whether or
@ -201,11 +203,14 @@ pub fn init_accounts_table<P: consensus::Parameters>(
let address_str: Option<String> = key
.sapling()
.map(|extfvk| address_from_extfvk(&wdb.params, extfvk));
#[cfg(feature = "transparent-inputs")]
let taddress_str: Option<String> = key.transparent().and_then(|k| {
k.to_external_pubkey(0)
.ok()
.map(|k| k.to_address().encode(&wdb.params))
});
#[cfg(not(feature = "transparent-inputs"))]
let taddress_str: Option<String> = None;
wdb.conn.execute(
"INSERT INTO accounts (account, extfvk, address, transparent_address)