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:
+10
-1
@@ -1,5 +1,7 @@
|
||||
use std::num;
|
||||
use rand::Rng;
|
||||
use num_bigint::BigUint;
|
||||
use num_traits::One;
|
||||
|
||||
/// Convert bytes array to HEX format
|
||||
pub fn to_hex(buf: &[u8]) -> String {
|
||||
@@ -33,12 +35,19 @@ pub fn same_hash(left: &[u8], right: &[u8]) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn hash_is_good(hash: &[u8], difficulty: usize) -> bool {
|
||||
let target = BigUint::one() << ((hash.len() << 3) - difficulty);
|
||||
let hash_int = BigUint::from_bytes_be(&hash);
|
||||
|
||||
return hash_int < target;
|
||||
}
|
||||
|
||||
/// Generates random string of given length
|
||||
pub fn random_string(length: usize) -> String {
|
||||
let chars: Vec<char> = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?".chars().collect();
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut result = String::with_capacity(length);
|
||||
for x in 0..length {
|
||||
for _ in 0..length {
|
||||
let position: usize = rng.gen::<usize>() % chars.len();
|
||||
let c: char = *chars.get(position).unwrap();
|
||||
result.push(c);
|
||||
|
||||
Reference in New Issue
Block a user