Browse Source

Move config creation to lib

checkpoints
Aditya Kulkarni 5 years ago
parent
commit
425ae21a6c
  1. 22
      lib/src/lightclient.rs
  2. 30
      src/main.rs

22
lib/src/lightclient.rs

@ -18,9 +18,9 @@ use zcash_client_backend::{
};
use crate::grpc_client::{BlockId};
use crate::grpcconnector::*;
use crate::grpcconnector::{self, *};
use crate::SaplingParams;
use crate::ANCHOR_OFFSET;
pub const DEFAULT_SERVER: &str = "https://lightd-main.zecwallet.co:443";
pub const WALLET_NAME: &str = "zecwallet-light-wallet.dat";
@ -39,6 +39,24 @@ pub struct LightClientConfig {
impl LightClientConfig {
pub fn create(server: http::Uri, dangerous: bool) -> io::Result<(LightClientConfig, u64)> {
// Do a getinfo first, before opening the wallet
let info = grpcconnector::get_info(server.clone(), dangerous)
.map_err(|e| std::io::Error::new(ErrorKind::ConnectionRefused, e))?;
// Create a Light Client Config
let config = LightClientConfig {
server,
chain_name : info.chain_name,
sapling_activation_height : info.sapling_activation_height,
consensus_branch_id : info.consensus_branch_id,
anchor_offset : ANCHOR_OFFSET,
no_cert_verification : dangerous,
};
Ok((config, info.block_height))
}
pub fn get_zcash_data_path(&self) -> Box<Path> {
let mut zcash_data_location;
if cfg!(target_os="macos") || cfg!(target_os="windows") {

30
src/main.rs

@ -3,9 +3,8 @@ use std::sync::{Arc};
use std::sync::mpsc::{channel, Sender, Receiver};
use std::time::Duration;
use zecwalletlitelib::{grpcconnector, commands,
use zecwalletlitelib::{commands,
lightclient::{self, LightClient, LightClientConfig},
ANCHOR_OFFSET,
};
use log::{info, error, LevelFilter};
@ -148,7 +147,7 @@ pub fn main() {
fn startup(server: http::Uri, dangerous: bool, seed: Option<String>, first_sync: bool, print_updates: bool)
-> Result<(Sender<(String, Vec<String>)>, Receiver<String>)> {
// Try to get the configuration
let (config, latest_block_height) = create_lightclient_config(server.clone(), dangerous)?;
let (config, latest_block_height) = LightClientConfig::create(server.clone(), dangerous)?;
// Configure logging first.
let log_config = get_log_config(&config)?;
@ -156,7 +155,7 @@ fn startup(server: http::Uri, dangerous: bool, seed: Option<String>, first_sync:
std::io::Error::new(ErrorKind::Other, e)
})?;
let lightclient = Arc::new(create_lightclient(seed, latest_block_height, &config)?);
let lightclient = Arc::new(LightClient::new(seed, &config, latest_block_height)?);
// Print startup Messages
info!(""); // Blank line
@ -181,29 +180,6 @@ fn startup(server: http::Uri, dangerous: bool, seed: Option<String>, first_sync:
Ok((command_tx, resp_rx))
}
fn create_lightclient_config(server: http::Uri, dangerous: bool) -> Result<(LightClientConfig, u64)> {
// Do a getinfo first, before opening the wallet
let info = grpcconnector::get_info(server.clone(), dangerous)
.map_err(|e| std::io::Error::new(ErrorKind::ConnectionRefused, e))?;
// Create a Light Client Config
let config = lightclient::LightClientConfig {
server,
chain_name : info.chain_name,
sapling_activation_height : info.sapling_activation_height,
consensus_branch_id : info.consensus_branch_id,
anchor_offset : ANCHOR_OFFSET,
no_cert_verification : dangerous,
};
Ok((config, info.block_height))
}
fn create_lightclient(seed: Option<String>, latest_block: u64, config: &LightClientConfig) -> Result<(LightClient)> {
let lightclient = LightClient::new(seed, config, latest_block)?;
Ok(lightclient)
}
fn start_interactive(command_tx: Sender<(String, Vec<String>)>, resp_rx: Receiver<String>) {
// `()` can be used when no completer is required

Loading…
Cancel
Save