Added a keys check on load. Added a warning on errors.
This commit is contained in:
+14
-2
@@ -64,11 +64,23 @@ impl Keystore {
|
|||||||
match fs::read(&path) {
|
match fs::read(&path) {
|
||||||
Ok(key) => {
|
Ok(key) => {
|
||||||
if key.len() == 32 {
|
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());
|
let mut keystore = Self::from_bytes(key.as_slice());
|
||||||
keystore.path = path.to_str().unwrap().to_owned();
|
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(_) => {
|
Err(_) => {
|
||||||
None
|
None
|
||||||
|
|||||||
+4
-3
@@ -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")));
|
let result = tfd::open_file_dialog("Open keys file", "", Some((&["*.key"], "*.key")));
|
||||||
match result {
|
match result {
|
||||||
None => {}
|
None => {}
|
||||||
@@ -156,6 +156,7 @@ fn action_load_key(context: &Arc<Mutex<Context>>, _web_view: &mut WebView<()>) {
|
|||||||
match Keystore::from_file(&file_name, "") {
|
match Keystore::from_file(&file_name, "") {
|
||||||
None => {
|
None => {
|
||||||
error!("Error loading keystore '{}'!", &file_name);
|
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) => {
|
Some(keystore) => {
|
||||||
info!("Loaded keystore with key: {:?}", &keystore.get_public());
|
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 c = Arc::clone(&context);
|
||||||
let context = context.lock().unwrap();
|
let context = context.lock().unwrap();
|
||||||
if context.get_keystore().is_none() {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
let keystore = context.get_keystore().unwrap();
|
let keystore = context.get_keystore().unwrap();
|
||||||
@@ -307,7 +308,7 @@ fn action_create_zone(context: Arc<Mutex<Context>>, miner: Arc<Mutex<Miner>>, we
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!("Can not mine without keys!");
|
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user