diff --git a/Cargo.toml b/Cargo.toml index 4e76748..d799476 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ webpki-roots = "0.16.0" tower-h2 = { git = "https://github.com/tower-rs/tower-h2" } openssl = "*" openssl-probe = "*" - +rust-embed = "5.1.0" [dependencies.bellman] git = "https://github.com/adityapk00/librustzcash.git" @@ -72,4 +72,4 @@ tower-grpc-build = { git = "https://github.com/tower-rs/tower-grpc", features = rand_core = "0.5.1" [profile.release] -debug = true \ No newline at end of file +debug = false \ No newline at end of file diff --git a/src/lightclient.rs b/src/lightclient.rs index f21d142..2a75efb 100644 --- a/src/lightclient.rs +++ b/src/lightclient.rs @@ -37,6 +37,7 @@ use zcash_client_backend::{ use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction, TransparentAddressBlockFilter, TxFilter, Empty, LightdInfo}; use crate::grpc_client::client::CompactTxStreamer; +use crate::SaplingParams; // Used below to return the grpc "Client" type to calling methods @@ -142,8 +143,6 @@ macro_rules! make_grpc_client { }}; } - - #[derive(Clone, Debug)] pub struct LightClientConfig { pub server : http::Uri, @@ -153,22 +152,6 @@ pub struct LightClientConfig { } impl LightClientConfig { - pub fn get_params_path(&self, name: &str) -> Box { - let mut params_location; - - if cfg!(target_os="macos") || cfg!(target_os="windows") { - params_location = dirs::data_dir() - .expect("Couldn't determine app data directory!"); - params_location.push("ZcashParams"); - } else { - params_location = dirs::home_dir() - .expect("Couldn't determine home directory!"); - params_location.push(".zcash-params"); - }; - - params_location.push(name); - params_location.into_boxed_path() - } pub fn get_zcash_data_path(&self) -> Box { let mut zcash_data_location; @@ -335,19 +318,8 @@ impl LightClient { info!("Read wallet with birthday {}", lc.wallet.get_first_tx_block()); // Read Sapling Params - let mut f = match File::open(config.get_params_path("sapling-output.params")) { - Ok(file) => file, - Err(_) => return Err(Error::new(ErrorKind::NotFound, - format!("Couldn't read {}", config.get_params_path("sapling-output.params").display()))) - }; - f.read_to_end(&mut lc.sapling_output)?; - - let mut f = match File::open(config.get_params_path("sapling-spend.params")) { - Ok(file) => file, - Err(_) => return Err(Error::new(ErrorKind::NotFound, - format!("Couldn't read {}", config.get_params_path("sapling-spend.params").display()))) - }; - f.read_to_end(&mut lc.sapling_spend)?; + lc.sapling_output.extend_from_slice(SaplingParams::get("sapling-output.params").unwrap().as_ref()); + lc.sapling_spend.extend_from_slice(SaplingParams::get("sapling-spend.params").unwrap().as_ref()); info!("Created LightClient to {}", &config.server); println!("Lightclient connecting to {}", config.server); diff --git a/src/lightwallet/mod.rs b/src/lightwallet/mod.rs index d257fd8..cfc6729 100644 --- a/src/lightwallet/mod.rs +++ b/src/lightwallet/mod.rs @@ -1228,24 +1228,17 @@ pub mod tests { use super::LightWallet; use crate::LightClientConfig; use secp256k1::{Secp256k1, key::PublicKey, key::SecretKey}; + use crate::SaplingParams; fn get_sapling_params(config: &LightClientConfig) -> Result<(Vec, Vec), Error> { // Read Sapling Params let mut sapling_output = vec![]; - let mut f = match File::open(config.get_params_path("sapling-output.params")) { - Ok(file) => file, - Err(_) => return Err(Error::new(ErrorKind::NotFound, - format!("Couldn't read {}", config.get_params_path("sapling-output.params").display()))) - }; - f.read_to_end(&mut sapling_output)?; + sapling_output.extend_from_slice(SaplingParams::get("sapling-output.params").unwrap().as_ref()); + println!("Read output {}", sapling_output.len()); let mut sapling_spend = vec![]; - let mut f = match File::open(config.get_params_path("sapling-spend.params")) { - Ok(file) => file, - Err(_) => return Err(Error::new(ErrorKind::NotFound, - format!("Couldn't read {}", config.get_params_path("sapling-spend.params").display()))) - }; - f.read_to_end(&mut sapling_spend)?; + sapling_spend.extend_from_slice(SaplingParams::get("sapling-spend.params").unwrap().as_ref()); + println!("Read output {}", sapling_spend.len()); Ok((sapling_spend, sapling_output)) } diff --git a/src/main.rs b/src/main.rs index a540f1e..65badad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate rust_embed; + mod lightclient; mod lightwallet; mod address; @@ -24,6 +27,10 @@ pub mod grpc_client { include!(concat!(env!("OUT_DIR"), "/cash.z.wallet.sdk.rpc.rs")); } +#[derive(RustEmbed)] +#[folder = "zcash-params/"] +pub struct SaplingParams; + pub fn main() { // Get command line arguments let matches = App::new("ZecLite CLI") diff --git a/zcash-params/sapling-output.params b/zcash-params/sapling-output.params new file mode 100644 index 0000000..01760fa Binary files /dev/null and b/zcash-params/sapling-output.params differ diff --git a/zcash-params/sapling-spend.params b/zcash-params/sapling-spend.params new file mode 100644 index 0000000..b91cd77 Binary files /dev/null and b/zcash-params/sapling-spend.params differ