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 2419c6648c
commit 98db781931
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
6 changed files with 33 additions and 20 deletions

View File

@ -21,3 +21,6 @@ rand_core = "0.5"
rand_os = "0.2" rand_os = "0.2"
tempfile = "3" tempfile = "3"
zcash_proofs = { path = "../zcash_proofs" } zcash_proofs = { 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. * ❌ 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. * :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. * :heavy_check_mark: The library **is not** majorly broken in some way.
* ❌ The library **only runs** on testnet. * :heavy_check_mark: The library **does run** on mainnet and testnet.
* ❌ The library **does not run** on mainnet or regtest.
* ❌ We **are actively rebasing** this branch and adding features where/when needed. * ❌ We **are actively rebasing** this branch and adding features where/when needed.
* ❌ We **do not** undertake appropriate security coverage (threat models, review, response, etc.). * ❌ We **do not** undertake appropriate security coverage (threat models, review, response, etc.).
* :heavy_check_mark: There is a product manager for this library. * :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 rusqlite::{types::ToSql, Connection, NO_PARAMS};
use std::path::Path; use std::path::Path;
use zcash_client_backend::{ use zcash_client_backend::encoding::encode_extended_full_viewing_key;
constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
encoding::encode_extended_full_viewing_key,
};
use zcash_primitives::{block::BlockHash, zip32::ExtendedFullViewingKey}; use zcash_primitives::{block::BlockHash, zip32::ExtendedFullViewingKey};
use crate::{ use crate::{
address_from_extfvk, address_from_extfvk,
error::{Error, ErrorKind}, error::{Error, ErrorKind},
HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
}; };
/// Sets up the internal structure of the cache database. /// Sets up the internal structure of the cache database.
@ -243,16 +241,14 @@ pub fn init_blocks_table<P: AsRef<Path>>(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use zcash_client_backend::{ use zcash_client_backend::encoding::decode_payment_address;
constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS, encoding::decode_payment_address,
};
use zcash_primitives::{ use zcash_primitives::{
block::BlockHash, block::BlockHash,
zip32::{ExtendedFullViewingKey, ExtendedSpendingKey}, zip32::{ExtendedFullViewingKey, ExtendedSpendingKey},
}; };
use super::{init_accounts_table, init_blocks_table, init_data_database}; 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] #[test]
fn init_accounts_table_only_works_once() { 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 //! **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. //! 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 //! [`CompactBlock`]: zcash_client_backend::proto::compact_formats::CompactBlock
//! [`init_cache_database`]: crate::init::init_cache_database //! [`init_cache_database`]: crate::init::init_cache_database
use rusqlite::{Connection, NO_PARAMS}; use rusqlite::{Connection, NO_PARAMS};
use std::cmp; use std::cmp;
use zcash_client_backend::{ use zcash_client_backend::encoding::encode_payment_address;
constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS, encoding::encode_payment_address,
};
use zcash_primitives::zip32::ExtendedFullViewingKey; 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 error;
pub mod init; pub mod init;
pub mod query; pub mod query;
@ -33,6 +46,11 @@ pub mod scan;
pub mod transact; pub mod transact;
const ANCHOR_OFFSET: u32 = 10; 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; const SAPLING_ACTIVATION_HEIGHT: i32 = 280_000;
fn address_from_extfvk(extfvk: &ExtendedFullViewingKey) -> String { 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 rusqlite::{types::ToSql, Connection, NO_PARAMS};
use std::path::Path; use std::path::Path;
use zcash_client_backend::{ use zcash_client_backend::{
constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
encoding::decode_extended_full_viewing_key, proto::compact_formats::CompactBlock, encoding::decode_extended_full_viewing_key, proto::compact_formats::CompactBlock,
welding_rig::scan_block, welding_rig::scan_block,
}; };
@ -17,7 +16,7 @@ use zcash_primitives::{
use crate::{ use crate::{
error::{Error, ErrorKind}, error::{Error, ErrorKind},
SAPLING_ACTIVATION_HEIGHT, HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY, SAPLING_ACTIVATION_HEIGHT,
}; };
struct CompactBlockRow { struct CompactBlockRow {

View File

@ -4,10 +4,7 @@ use ff::{PrimeField, PrimeFieldRepr};
use pairing::bls12_381::Bls12; use pairing::bls12_381::Bls12;
use rusqlite::{types::ToSql, Connection, NO_PARAMS}; use rusqlite::{types::ToSql, Connection, NO_PARAMS};
use std::path::Path; use std::path::Path;
use zcash_client_backend::{ use zcash_client_backend::encoding::{encode_extended_full_viewing_key, encode_payment_address};
constants::testnet::{HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY, HRP_SAPLING_PAYMENT_ADDRESS},
encoding::{encode_extended_full_viewing_key, encode_payment_address},
};
use zcash_primitives::{ use zcash_primitives::{
jubjub::fs::{Fs, FsRepr}, jubjub::fs::{Fs, FsRepr},
merkle_tree::IncrementalWitness, merkle_tree::IncrementalWitness,
@ -25,7 +22,8 @@ use zcash_primitives::{
use crate::{ use crate::{
error::{Error, ErrorKind}, 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 { struct SelectedNoteRow {