Added a keys check on load. Added a warning on errors.

This commit is contained in:
Revertron
2021-03-23 19:29:51 +01:00
parent 98b00eb8e2
commit 1225bf6fbc
2 changed files with 18 additions and 5 deletions
+14 -2
View File
@@ -64,11 +64,23 @@ impl Keystore {
match fs::read(&path) {
Ok(key) => {
if key.len() == 32 {
return Some(Keystore::from_random_bytes(key.as_slice()));
let mut keystore = Keystore::from_random_bytes(key.as_slice());
keystore.path = path.to_str().unwrap().to_owned();
let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes());
return if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) {
Some(keystore)
} else {
None
};
}
let mut keystore = Self::from_bytes(key.as_slice());
keystore.path = path.to_str().unwrap().to_owned();
Some(keystore)
let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes());
return if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) {
Some(keystore)
} else {
None
};
}
Err(_) => {
None
+4 -3
View File
@@ -148,7 +148,7 @@ fn action_save_key(context: &Arc<Mutex<Context>>) {
}
}
fn action_load_key(context: &Arc<Mutex<Context>>, _web_view: &mut WebView<()>) {
fn action_load_key(context: &Arc<Mutex<Context>>, web_view: &mut WebView<()>) {
let result = tfd::open_file_dialog("Open keys file", "", Some((&["*.key"], "*.key")));
match result {
None => {}
@@ -156,6 +156,7 @@ fn action_load_key(context: &Arc<Mutex<Context>>, _web_view: &mut WebView<()>) {
match Keystore::from_file(&file_name, "") {
None => {
error!("Error loading keystore '{}'!", &file_name);
show_warning(web_view, "Error loading key!<br>Key cannot be loaded or its difficulty is not enough.");
}
Some(keystore) => {
info!("Loaded keystore with key: {:?}", &keystore.get_public());
@@ -246,7 +247,7 @@ fn action_create_domain(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>,
let c = Arc::clone(&context);
let context = context.lock().unwrap();
if context.get_keystore().is_none() {
show_warning(web_view, "You don't have keys loaded!\nLoad or mine the keys and try again.");
show_warning(web_view, "You don't have keys loaded!<br>Load or mine the keys and try again.");
return;
}
let keystore = context.get_keystore().unwrap();
@@ -307,7 +308,7 @@ fn action_create_zone(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>, we
}
} else {
warn!("Can not mine without keys!");
show_warning(web_view, "You don't have keys loaded!\nLoad or mine the keys and try again.");
show_warning(web_view, "You don't have keys loaded!<br>Load or mine the keys and try again.");
}
}