Add mainnet support to zcash_client_sqlite via a feature flag

This commit is contained in:
Jack Grigg 2019-04-08 12:24:49 +01:00
parent a2de5d7028
commit f0ce0c5530
6 changed files with 33 additions and 20 deletions

View File

@ -26,3 +26,6 @@ rand_core = "0.5.1"
remove_dir_all = "=0.5.2" # tempfile dependency; 0.5.3 bumped the MSRV
tempfile = "3"
zcash_proofs = { version = "0.2", path = "../zcash_proofs" }
[features]
mainnet = []

View File

@ -16,8 +16,7 @@ of the following:
* ❌ The code **has not been subjected to thorough review** by engineers at the Electric Coin Company.
* :warning: This library **is** compatible with the latest version of zcashd, but there **is no** automated testing of this.
* :heavy_check_mark: The library **is not** majorly broken in some way.
* ❌ The library **only runs** on testnet.
* ❌ The library **does not run** on mainnet or regtest.
* :heavy_check_mark: The library **does run** on mainnet and testnet.
* ❌ We **are actively rebasing** this branch and adding features where/when needed.
* ❌ We **do not** undertake appropriate security coverage (threat models, review, response, etc.).
* :heavy_check_mark: There is a product manager for this library.

View File

@ -2,15 +2,13 @@
use rusqlite::{types::ToSql, Connection, NO_PARAMS};
use std::path::Path;
use zcash_client_backend::{
constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
encoding::encode_extended_full_viewing_key,
};
use zcash_client_backend::encoding::encode_extended_full_viewing_key;
use zcash_primitives::{block::BlockHash, zip32::ExtendedFullViewingKey};
use crate::{
address_from_extfvk,
error::{Error, ErrorKind},
HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
};
/// Sets up the internal structure of the cache database.
@ -243,16 +241,14 @@ pub fn init_blocks_table<P: AsRef<Path>>(
#[cfg(test)]
mod tests {
use tempfile::NamedTempFile;
use zcash_client_backend::{
constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS, encoding::decode_payment_address,
};
use zcash_client_backend::encoding::decode_payment_address;
use zcash_primitives::{
block::BlockHash,
zip32::{ExtendedFullViewingKey, ExtendedSpendingKey},
};
use super::{init_accounts_table, init_blocks_table, init_data_database};
use crate::query::get_address;
use crate::{query::get_address, HRP_SAPLING_PAYMENT_ADDRESS};
#[test]
fn init_accounts_table_only_works_once() {

View File

@ -16,16 +16,29 @@
//! **MUST NOT** write to the database without using these APIs. Callers **MAY** read
//! the database directly in order to extract information for display to users.
//!
//! # Features
//!
//! The `mainnet` feature configures the light client for use with the Zcash mainnet. By
//! default, the light client is configured for use with the Zcash testnet.
//!
//! [`CompactBlock`]: zcash_client_backend::proto::compact_formats::CompactBlock
//! [`init_cache_database`]: crate::init::init_cache_database
use rusqlite::{Connection, NO_PARAMS};
use std::cmp;
use zcash_client_backend::{
constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS, encoding::encode_payment_address,
};
use zcash_client_backend::encoding::encode_payment_address;
use zcash_primitives::zip32::ExtendedFullViewingKey;
#[cfg(feature = "mainnet")]
use zcash_client_backend::constants::mainnet::{
HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY, HRP_SAPLING_PAYMENT_ADDRESS,
};
#[cfg(not(feature = "mainnet"))]
use zcash_client_backend::constants::testnet::{
HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY, HRP_SAPLING_PAYMENT_ADDRESS,
};
pub mod error;
pub mod init;
pub mod query;
@ -33,6 +46,11 @@ pub mod scan;
pub mod transact;
const ANCHOR_OFFSET: u32 = 10;
#[cfg(feature = "mainnet")]
const SAPLING_ACTIVATION_HEIGHT: i32 = 419_200;
#[cfg(not(feature = "mainnet"))]
const SAPLING_ACTIVATION_HEIGHT: i32 = 280_000;
fn address_from_extfvk(extfvk: &ExtendedFullViewingKey) -> String {

View File

@ -5,7 +5,6 @@ use protobuf::parse_from_bytes;
use rusqlite::{types::ToSql, Connection, NO_PARAMS};
use std::path::Path;
use zcash_client_backend::{
constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
encoding::decode_extended_full_viewing_key, proto::compact_formats::CompactBlock,
welding_rig::scan_block,
};
@ -17,7 +16,7 @@ use zcash_primitives::{
use crate::{
error::{Error, ErrorKind},
SAPLING_ACTIVATION_HEIGHT,
HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY, SAPLING_ACTIVATION_HEIGHT,
};
struct CompactBlockRow {

View File

@ -5,10 +5,7 @@ use pairing::bls12_381::Bls12;
use rusqlite::{types::ToSql, Connection, NO_PARAMS};
use std::convert::TryInto;
use std::path::Path;
use zcash_client_backend::{
constants::testnet::{HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY, HRP_SAPLING_PAYMENT_ADDRESS},
encoding::{encode_extended_full_viewing_key, encode_payment_address},
};
use zcash_client_backend::encoding::{encode_extended_full_viewing_key, encode_payment_address};
use zcash_primitives::{
consensus,
jubjub::fs::{Fs, FsRepr},
@ -27,7 +24,8 @@ use zcash_primitives::{
use crate::{
error::{Error, ErrorKind},
get_target_and_anchor_heights,
get_target_and_anchor_heights, HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
HRP_SAPLING_PAYMENT_ADDRESS,
};
struct SelectedNoteRow {