Implemented loading Settings from file. Implemented mining of Keystore (key pair). Changed Transaction structure a lot. Added an icon to windows build. Changed some HTML.
This commit is contained in:
+24
-8
@@ -1,5 +1,9 @@
|
||||
use crate::{Keystore, Blockchain};
|
||||
use std::collections::HashMap;
|
||||
use serde::{Serialize, Deserialize, Serializer, Deserializer};
|
||||
use serde::de::Error;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
pub struct Context {
|
||||
pub(crate) settings: Settings,
|
||||
@@ -38,21 +42,33 @@ impl Context {
|
||||
pub fn get_blockchain(&self) -> &Blockchain {
|
||||
&self.blockchain
|
||||
}
|
||||
|
||||
pub fn add_salt(&mut self, name: String, salt: String) {
|
||||
&self.settings.salts.insert(name, salt);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Settings {
|
||||
pub chain_id: u32,
|
||||
pub version: u32,
|
||||
salts: HashMap<String, String>
|
||||
pub key_file: String
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
/// TODO parse settings
|
||||
pub fn new<S: Into<String>>(settings: S) -> Settings {
|
||||
Settings { chain_id: 42, version: 0, salts: HashMap::new() }
|
||||
pub fn new<S: Into<String>>(settings: S) -> serde_json::Result<Settings> {
|
||||
serde_json::from_str(&settings.into())
|
||||
}
|
||||
|
||||
pub fn load(file_name: &str) -> Option<Settings> {
|
||||
match File::open(file_name) {
|
||||
Ok(mut file) => {
|
||||
let mut text = String::new();
|
||||
file.read_to_string(&mut text);
|
||||
let loaded = serde_json::from_str(&text);
|
||||
return if loaded.is_ok() {
|
||||
Some(loaded.unwrap())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
Err(..) => None
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user