Config update to support new chain.

This commit is contained in:
Revertron
2021-05-05 10:41:32 +02:00
parent fe92983945
commit ec635b19f2
2 changed files with 12 additions and 9 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
# The hash of first block in a chain to know with which nodes to work
origin = "0AE588D62D710422A7972EA1E8A659CC8E93DB59489ACE32C499CD279B000000"
origin = "00002883BB006454F795BE6902770B1A18D897B33A0AB1631F53C37C2F41F800"
# A path to your key file to load automatically
key_file = "default.key"
key_file = "key1.toml"
# How many last blocks to check on start
check_blocks = 8
+10 -7
View File
@@ -34,7 +34,8 @@ pub struct Keystore {
keypair: Keypair,
hash: RefCell<Bytes>,
path: String,
crypto_box: CryptoBox
crypto_box: CryptoBox,
old: bool
}
impl Keystore {
@@ -42,20 +43,20 @@ impl Keystore {
let mut csprng = rand_old::thread_rng();
let keypair = ed25519_dalek::Keypair::generate(&mut csprng);
let crypto_box = CryptoBox::generate(&mut csprng);
Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box }
Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box, old: false }
}
pub fn from_random<R>(csprng: &mut R) -> Self where R: CryptoRng + RngCore {
let keypair = ed25519_dalek::Keypair::generate(csprng);
let crypto_box = CryptoBox::generate(csprng);
Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box }
Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box, old: false }
}
pub fn from_bytes(seed: &[u8]) -> Self {
let keypair = Keypair::from_bytes(seed).expect("Error creating keypair from bytes!");
let mut csprng = rand_old::thread_rng();
let crypto_box = CryptoBox::generate(&mut csprng);
Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box }
Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box, old: false }
}
pub fn from_random_bytes(key: &[u8]) -> Self {
@@ -64,7 +65,7 @@ impl Keystore {
let keypair = Keypair { secret, public };
let mut csprng = rand_old::thread_rng();
let crypto_box = CryptoBox::generate(&mut csprng);
Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box }
Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::new(), crypto_box, old: false }
}
pub fn from_file(filename: &str, _password: &str) -> Option<Self> {
@@ -75,6 +76,7 @@ impl Keystore {
32 => {
let mut keystore = Keystore::from_random_bytes(key.as_slice());
keystore.path = path.to_str().unwrap().to_owned();
keystore.old = true;
let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes());
if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) {
warn!("Loaded key from OLD format! Please, resave it!");
@@ -86,6 +88,7 @@ impl Keystore {
64 => {
let mut keystore = Self::from_bytes(key.as_slice());
keystore.path = path.to_str().unwrap().to_owned();
keystore.old = true;
let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes());
if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) {
warn!("Loaded key from OLD format! Please, resave it!");
@@ -101,7 +104,7 @@ impl Keystore {
let public = PublicKey::from_bytes(&from_hex(&keys.signing.public).unwrap()).unwrap();
let keypair = Keypair { secret, public };
let crypto_box = CryptoBox::from_strings(&keys.encryption.secret, &keys.encryption.public);
let keystore = Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::from(filename), crypto_box };
let keystore = Keystore { keypair, hash: RefCell::new(Bytes::default()), path: String::from(filename), crypto_box, old: false };
let bytes = Bytes::from_bytes(&keystore.keypair.public.to_bytes());
if check_public_key_strength(&bytes, KEYSTORE_DIFFICULTY) {
Some(keystore)
@@ -192,7 +195,7 @@ impl Keystore {
impl Clone for Keystore {
fn clone(&self) -> Self {
let keypair = Keypair::from_bytes(&self.keypair.to_bytes()).unwrap();
Self { keypair, hash: RefCell::new(Bytes::default()), path: self.path.clone(), crypto_box: self.crypto_box.clone() }
Self { keypair, hash: RefCell::new(Bytes::default()), path: self.path.clone(), crypto_box: self.crypto_box.clone(), old: self.old }
}
}