Remove cyclic dev dependency between zcash_client_backend and zcash_client_sqlite.
This commit is contained in:
parent
f75ffb0eaf
commit
8f408354b9
|
@ -43,7 +43,6 @@ protobuf-codegen-pure = "2.20"
|
||||||
gumdrop = "0.8"
|
gumdrop = "0.8"
|
||||||
rand_xorshift = "0.3"
|
rand_xorshift = "0.3"
|
||||||
tempfile = "3.1.0"
|
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" }
|
zcash_proofs = { version = "0.5", path = "../zcash_proofs" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
//! # Examples
|
//! # Examples
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! use tempfile::NamedTempFile;
|
//! # #[cfg(feature = "test-dependencies")]
|
||||||
|
//! # {
|
||||||
//! use zcash_primitives::{
|
//! use zcash_primitives::{
|
||||||
//! consensus::{BlockHeight, Network, Parameters}
|
//! consensus::{BlockHeight, Network, Parameters}
|
||||||
//! };
|
//! };
|
||||||
|
@ -17,32 +18,18 @@
|
||||||
//! scan_cached_blocks,
|
//! scan_cached_blocks,
|
||||||
//! },
|
//! },
|
||||||
//! error::Error,
|
//! 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() {
|
//! # fn main() {
|
||||||
//! # test();
|
//! # test();
|
||||||
//! # }
|
//! # }
|
||||||
//! #
|
//! #
|
||||||
//! # fn test() -> Result<(), SqliteClientError> {
|
//! # fn test() -> Result<(), Error<u32>> {
|
||||||
//! let network = Network::TestNetwork;
|
//! let network = Network::TestNetwork;
|
||||||
//! let cache_file = NamedTempFile::new()?;
|
//! let db_cache = testing::MockBlockSource {};
|
||||||
//! let db_cache = BlockDb::for_path(cache_file)?;
|
//! let mut db_data = testing::MockWalletDb {};
|
||||||
//! 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()?;
|
|
||||||
//!
|
//!
|
||||||
//! // 1) Download new CompactBlocks into db_cache.
|
//! // 1) Download new CompactBlocks into db_cache.
|
||||||
//!
|
//!
|
||||||
|
@ -52,7 +39,7 @@
|
||||||
//! // errors are in the blocks we have previously cached or scanned.
|
//! // 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()?) {
|
//! if let Err(e) = validate_chain(&network, &db_cache, db_data.get_max_height_hash()?) {
|
||||||
//! match e {
|
//! match e {
|
||||||
//! SqliteClientError::BackendError(Error::InvalidChain(lower_bound, _)) => {
|
//! Error::InvalidChain(lower_bound, _) => {
|
||||||
//! // a) Pick a height to rewind to.
|
//! // a) Pick a height to rewind to.
|
||||||
//! //
|
//! //
|
||||||
//! // This might be informed by some external chain reorg information, or
|
//! // 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
|
//! // d) If there is some separate thread or service downloading
|
||||||
//! // CompactBlocks, tell it to go back and download from rewind_height
|
//! // CompactBlocks, tell it to go back and download from rewind_height
|
||||||
//! // onwards.
|
//! // onwards.
|
||||||
//! }
|
//! },
|
||||||
//! e => {
|
//! e => {
|
||||||
//! // Handle or return other errors.
|
//! // handle or return other errors
|
||||||
//! return Err(e);
|
//!
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
|
@ -87,6 +74,7 @@
|
||||||
//! // next time this codepath is executed after new blocks are received).
|
//! // next time this codepath is executed after new blocks are received).
|
||||||
//! scan_cached_blocks(&network, &db_cache, &mut db_data, None)
|
//! scan_cached_blocks(&network, &db_cache, &mut db_data, None)
|
||||||
//! # }
|
//! # }
|
||||||
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
@ -198,44 +186,6 @@ where
|
||||||
///
|
///
|
||||||
/// Scanned blocks are required to be height-sequential. If a block is missing from the
|
/// 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`].
|
/// 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>(
|
pub fn scan_cached_blocks<E, N, P, C, D>(
|
||||||
params: &P,
|
params: &P,
|
||||||
cache: &C,
|
cache: &C,
|
||||||
|
|
|
@ -95,31 +95,27 @@ where
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
/// # #[cfg(feature = "test-dependencies")]
|
||||||
|
/// # {
|
||||||
/// use tempfile::NamedTempFile;
|
/// use tempfile::NamedTempFile;
|
||||||
/// use zcash_primitives::{
|
/// use zcash_primitives::{
|
||||||
/// consensus::{self, Network},
|
/// consensus::{self, Network},
|
||||||
/// constants::testnet::COIN_TYPE,
|
/// constants::testnet::COIN_TYPE,
|
||||||
/// transaction::components::Amount
|
/// transaction::{TxId, components::Amount},
|
||||||
/// };
|
/// };
|
||||||
/// use zcash_proofs::prover::LocalTxProver;
|
/// use zcash_proofs::prover::LocalTxProver;
|
||||||
/// use zcash_client_backend::{
|
/// use zcash_client_backend::{
|
||||||
/// keys::sapling,
|
/// keys::sapling,
|
||||||
/// data_api::wallet::create_spend_to_address,
|
/// data_api::{wallet::create_spend_to_address, error::Error, testing},
|
||||||
/// wallet::{AccountId, OvkPolicy},
|
/// 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() {
|
/// # fn main() {
|
||||||
/// # test();
|
/// # test();
|
||||||
/// # }
|
/// # }
|
||||||
/// #
|
/// #
|
||||||
/// # fn test() -> Result<(), SqliteClientError> {
|
/// # fn test() -> Result<TxId, Error<u32>> {
|
||||||
|
///
|
||||||
/// let tx_prover = match LocalTxProver::with_default_location() {
|
/// let tx_prover = match LocalTxProver::with_default_location() {
|
||||||
/// Some(tx_prover) => tx_prover,
|
/// Some(tx_prover) => tx_prover,
|
||||||
/// None => {
|
/// None => {
|
||||||
|
@ -131,13 +127,10 @@ where
|
||||||
/// let extsk = sapling::spending_key(&[0; 32][..], COIN_TYPE, account);
|
/// let extsk = sapling::spending_key(&[0; 32][..], COIN_TYPE, account);
|
||||||
/// let to = extsk.default_address().1.into();
|
/// let to = extsk.default_address().1.into();
|
||||||
///
|
///
|
||||||
/// let data_file = NamedTempFile::new().unwrap();
|
/// let mut db_read = testing::MockWalletDb {};
|
||||||
/// let db_read = WalletDb::for_path(data_file, Network::TestNetwork).unwrap();
|
|
||||||
/// init_wallet_db(&db_read)?;
|
|
||||||
/// let mut db = db_read.get_update_ops()?;
|
|
||||||
///
|
///
|
||||||
/// create_spend_to_address(
|
/// create_spend_to_address(
|
||||||
/// &mut db,
|
/// &mut db_read,
|
||||||
/// &Network::TestNetwork,
|
/// &Network::TestNetwork,
|
||||||
/// tx_prover,
|
/// tx_prover,
|
||||||
/// account,
|
/// account,
|
||||||
|
@ -147,9 +140,9 @@ where
|
||||||
/// None,
|
/// None,
|
||||||
/// OvkPolicy::Sender,
|
/// OvkPolicy::Sender,
|
||||||
/// 10
|
/// 10
|
||||||
/// )?;
|
/// )
|
||||||
///
|
///
|
||||||
/// # Ok(())
|
/// # }
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
|
|
@ -212,6 +212,7 @@ pub mod transparent {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct UnifiedFullViewingKey {
|
pub struct UnifiedFullViewingKey {
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
|
#[cfg(feature = "transparent-inputs")]
|
||||||
transparent: Option<transparent::AccountPubKey>,
|
transparent: Option<transparent::AccountPubKey>,
|
||||||
sapling: Option<sapling::ExtendedFullViewingKey>,
|
sapling: Option<sapling::ExtendedFullViewingKey>,
|
||||||
}
|
}
|
||||||
|
@ -220,7 +221,7 @@ impl UnifiedFullViewingKey {
|
||||||
/// Construct a new unified full viewing key, if the required components are present.
|
/// Construct a new unified full viewing key, if the required components are present.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
account: AccountId,
|
account: AccountId,
|
||||||
transparent: Option<transparent::AccountPubKey>,
|
#[cfg(feature = "transparent-inputs")] transparent: Option<transparent::AccountPubKey>,
|
||||||
sapling: Option<sapling::ExtendedFullViewingKey>,
|
sapling: Option<sapling::ExtendedFullViewingKey>,
|
||||||
) -> Option<UnifiedFullViewingKey> {
|
) -> Option<UnifiedFullViewingKey> {
|
||||||
if sapling.is_none() {
|
if sapling.is_none() {
|
||||||
|
@ -228,6 +229,7 @@ impl UnifiedFullViewingKey {
|
||||||
} else {
|
} else {
|
||||||
Some(UnifiedFullViewingKey {
|
Some(UnifiedFullViewingKey {
|
||||||
account,
|
account,
|
||||||
|
#[cfg(feature = "transparent-inputs")]
|
||||||
transparent,
|
transparent,
|
||||||
sapling,
|
sapling,
|
||||||
})
|
})
|
||||||
|
@ -240,6 +242,7 @@ impl UnifiedFullViewingKey {
|
||||||
self.account
|
self.account
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "transparent-inputs")]
|
||||||
/// Returns the transparent component of the unified key at the
|
/// Returns the transparent component of the unified key at the
|
||||||
/// BIP44 path `m/44'/<coin_type>'/<account>'`.
|
/// BIP44 path `m/44'/<coin_type>'/<account>'`.
|
||||||
pub fn transparent(&self) -> Option<&transparent::AccountPubKey> {
|
pub fn transparent(&self) -> Option<&transparent::AccountPubKey> {
|
||||||
|
|
|
@ -8,12 +8,14 @@ use zcash_primitives::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use zcash_client_backend::{
|
use zcash_client_backend::{
|
||||||
encoding::{encode_extended_full_viewing_key, AddressCodec},
|
encoding::encode_extended_full_viewing_key, keys::UnifiedFullViewingKey,
|
||||||
keys::UnifiedFullViewingKey,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{address_from_extfvk, error::SqliteClientError, WalletDb};
|
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.
|
/// Sets up the internal structure of the data database.
|
||||||
///
|
///
|
||||||
/// The database structure is the same irrespective of whether or
|
/// 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
|
let address_str: Option<String> = key
|
||||||
.sapling()
|
.sapling()
|
||||||
.map(|extfvk| address_from_extfvk(&wdb.params, extfvk));
|
.map(|extfvk| address_from_extfvk(&wdb.params, extfvk));
|
||||||
|
#[cfg(feature = "transparent-inputs")]
|
||||||
let taddress_str: Option<String> = key.transparent().and_then(|k| {
|
let taddress_str: Option<String> = key.transparent().and_then(|k| {
|
||||||
k.to_external_pubkey(0)
|
k.to_external_pubkey(0)
|
||||||
.ok()
|
.ok()
|
||||||
.map(|k| k.to_address().encode(&wdb.params))
|
.map(|k| k.to_address().encode(&wdb.params))
|
||||||
});
|
});
|
||||||
|
#[cfg(not(feature = "transparent-inputs"))]
|
||||||
|
let taddress_str: Option<String> = None;
|
||||||
|
|
||||||
wdb.conn.execute(
|
wdb.conn.execute(
|
||||||
"INSERT INTO accounts (account, extfvk, address, transparent_address)
|
"INSERT INTO accounts (account, extfvk, address, transparent_address)
|
||||||
|
|
Loading…
Reference in New Issue