|
|
@ -1,6 +1,5 @@ |
|
|
|
use crate::lightwallet::LightWallet; |
|
|
|
|
|
|
|
use log::{info, warn, error}; |
|
|
|
use rand::{rngs::OsRng, seq::SliceRandom}; |
|
|
|
|
|
|
|
use std::sync::{Arc, RwLock, Mutex}; |
|
|
@ -20,6 +19,17 @@ use zcash_client_backend::{ |
|
|
|
constants::testnet, constants::mainnet, constants::regtest, encoding::encode_payment_address, |
|
|
|
}; |
|
|
|
|
|
|
|
use log::{info, warn, error, LevelFilter}; |
|
|
|
use log4rs::append::rolling_file::RollingFileAppender; |
|
|
|
use log4rs::encode::pattern::PatternEncoder; |
|
|
|
use log4rs::config::{Appender, Config, Root}; |
|
|
|
use log4rs::filter::threshold::ThresholdFilter; |
|
|
|
use log4rs::append::rolling_file::policy::compound::{ |
|
|
|
CompoundPolicy, |
|
|
|
trigger::size::SizeTrigger, |
|
|
|
roll::fixed_window::FixedWindowRoller, |
|
|
|
}; |
|
|
|
|
|
|
|
use crate::grpc_client::{BlockId}; |
|
|
|
use crate::grpcconnector::{self, *}; |
|
|
|
use crate::SaplingParams; |
|
|
@ -100,6 +110,37 @@ impl LightClientConfig { |
|
|
|
Ok((config, info.block_height)) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Build the Logging config
|
|
|
|
pub fn get_log_config(&self) -> io::Result<Config> { |
|
|
|
let window_size = 3; // log0, log1, log2
|
|
|
|
let fixed_window_roller = |
|
|
|
FixedWindowRoller::builder().build("zecwallet-light-wallet-log{}",window_size).unwrap(); |
|
|
|
let size_limit = 5 * 1024 * 1024; // 5MB as max log file size to roll
|
|
|
|
let size_trigger = SizeTrigger::new(size_limit); |
|
|
|
let compound_policy = CompoundPolicy::new(Box::new(size_trigger),Box::new(fixed_window_roller)); |
|
|
|
|
|
|
|
Config::builder() |
|
|
|
.appender( |
|
|
|
Appender::builder() |
|
|
|
.filter(Box::new(ThresholdFilter::new(LevelFilter::Info))) |
|
|
|
.build( |
|
|
|
"logfile", |
|
|
|
Box::new( |
|
|
|
RollingFileAppender::builder() |
|
|
|
.encoder(Box::new(PatternEncoder::new("{d} {l}::{m}{n}"))) |
|
|
|
.build(self.get_log_path(), Box::new(compound_policy))?, |
|
|
|
), |
|
|
|
), |
|
|
|
) |
|
|
|
.build( |
|
|
|
Root::builder() |
|
|
|
.appender("logfile") |
|
|
|
.build(LevelFilter::Debug), |
|
|
|
) |
|
|
|
.map_err(|e|Error::new(ErrorKind::Other, format!("{}", e))) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn get_zcash_data_path(&self) -> Box<Path> { |
|
|
|
let mut zcash_data_location;
|
|
|
|
if self.data_dir.is_some() { |
|
|
@ -361,6 +402,16 @@ impl LightClient { |
|
|
|
Ok(lc) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn init_logging(&self) -> io::Result<()> { |
|
|
|
// Configure logging first.
|
|
|
|
let log_config = self.config.get_log_config()?; |
|
|
|
log4rs::init_config(log_config).map_err(|e| { |
|
|
|
std::io::Error::new(ErrorKind::Other, e) |
|
|
|
})?; |
|
|
|
|
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
|
|
|
|
pub fn attempt_recover_seed(config: &LightClientConfig) -> Result<String, String> { |
|
|
|
use std::io::prelude::*; |
|
|
|
use byteorder::{LittleEndian, ReadBytesExt,}; |
|
|
|