mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-07-30 20:01:26 +00:00
Split wallet creation
This commit is contained in:
@@ -87,6 +87,10 @@ impl LightClientConfig {
|
|||||||
wallet_location.into_boxed_path()
|
wallet_location.into_boxed_path()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn wallet_exists(&self) -> bool {
|
||||||
|
return self.get_wallet_path().exists()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_log_path(&self) -> Box<Path> {
|
pub fn get_log_path(&self) -> Box<Path> {
|
||||||
let mut log_path = self.get_zcash_data_path().into_path_buf();
|
let mut log_path = self.get_zcash_data_path().into_path_buf();
|
||||||
log_path.push(LOGFILE_NAME);
|
log_path.push(LOGFILE_NAME);
|
||||||
@@ -201,42 +205,54 @@ impl LightClient {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(seed_phrase: Option<String>, config: &LightClientConfig, latest_block: u64) -> io::Result<Self> {
|
fn read_sapling_params(&mut self) {
|
||||||
let mut lc = if config.get_wallet_path().exists() {
|
// Read Sapling Params
|
||||||
// Make sure that if a wallet exists, there is no seed phrase being attempted
|
self.sapling_output.extend_from_slice(SaplingParams::get("sapling-output.params").unwrap().as_ref());
|
||||||
if !seed_phrase.is_none() {
|
self.sapling_spend.extend_from_slice(SaplingParams::get("sapling-spend.params").unwrap().as_ref());
|
||||||
return Err(Error::new(ErrorKind::AlreadyExists,
|
|
||||||
"Cannot create a new wallet from seed, because a wallet already exists"));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut file_buffer = BufReader::new(File::open(config.get_wallet_path())?);
|
}
|
||||||
|
|
||||||
let wallet = LightWallet::read(&mut file_buffer, config)?;
|
pub fn new_from_phrase(seed_phrase: String, config: &LightClientConfig, latest_block: u64) -> io::Result<Self> {
|
||||||
LightClient {
|
if config.get_wallet_path().exists() {
|
||||||
wallet : Arc::new(RwLock::new(wallet)),
|
return Err(Error::new(ErrorKind::AlreadyExists,
|
||||||
config : config.clone(),
|
"Cannot create a new wallet from seed, because a wallet already exists"));
|
||||||
sapling_output : vec![],
|
}
|
||||||
sapling_spend : vec![]
|
|
||||||
}
|
let mut l = LightClient {
|
||||||
} else {
|
wallet : Arc::new(RwLock::new(LightWallet::new(Some(seed_phrase), config, latest_block)?)),
|
||||||
let l = LightClient {
|
|
||||||
wallet : Arc::new(RwLock::new(LightWallet::new(seed_phrase, config, latest_block)?)),
|
|
||||||
config : config.clone(),
|
config : config.clone(),
|
||||||
sapling_output : vec![],
|
sapling_output : vec![],
|
||||||
sapling_spend : vec![]
|
sapling_spend : vec![]
|
||||||
};
|
};
|
||||||
|
|
||||||
l.set_wallet_initial_state();
|
l.set_wallet_initial_state();
|
||||||
|
l.read_sapling_params();
|
||||||
|
|
||||||
l
|
info!("Created new wallet!");
|
||||||
|
info!("Created LightClient to {}", &config.server);
|
||||||
|
|
||||||
|
Ok(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_from_disk(config: &LightClientConfig) -> io::Result<Self> {
|
||||||
|
if !config.get_wallet_path().exists() {
|
||||||
|
return Err(Error::new(ErrorKind::AlreadyExists,
|
||||||
|
format!("Cannot read wallet. No file at {}", config.get_wallet_path().display())));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut file_buffer = BufReader::new(File::open(config.get_wallet_path())?);
|
||||||
|
|
||||||
|
let wallet = LightWallet::read(&mut file_buffer, config)?;
|
||||||
|
let mut lc = LightClient {
|
||||||
|
wallet : Arc::new(RwLock::new(wallet)),
|
||||||
|
config : config.clone(),
|
||||||
|
sapling_output : vec![],
|
||||||
|
sapling_spend : vec![]
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("Read wallet with birthday {}", lc.wallet.read().unwrap().get_first_tx_block());
|
lc.read_sapling_params();
|
||||||
|
|
||||||
// Read Sapling Params
|
|
||||||
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!("Read wallet with birthday {}", lc.wallet.read().unwrap().get_first_tx_block());
|
||||||
info!("Created LightClient to {}", &config.server);
|
info!("Created LightClient to {}", &config.server);
|
||||||
|
|
||||||
Ok(lc)
|
Ok(lc)
|
||||||
|
@@ -160,7 +160,10 @@ fn startup(server: http::Uri, dangerous: bool, seed: Option<String>, first_sync:
|
|||||||
std::io::Error::new(ErrorKind::Other, e)
|
std::io::Error::new(ErrorKind::Other, e)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let lightclient = Arc::new(LightClient::new(seed, &config, latest_block_height)?);
|
let lightclient = match seed {
|
||||||
|
Some(phrase) => Arc::new(LightClient::new_from_phrase(phrase, &config, latest_block_height)?),
|
||||||
|
None => Arc::new(LightClient::read_from_disk(&config)?)
|
||||||
|
};
|
||||||
|
|
||||||
// Print startup Messages
|
// Print startup Messages
|
||||||
info!(""); // Blank line
|
info!(""); // Blank line
|
||||||
|
Reference in New Issue
Block a user