Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn proof_of_work(data: String, difficulty: i16) {
- let mut nonce: i64 = 0;
- let mut proof: bool = false;
- let mut hash: String = String::from("");
- let mut difficulty_str: String = String::from("");
- for _ in 0..difficulty {
- difficulty_str = String::from(difficulty_str + "0");
- }
- while proof == false {
- hash = hash_block(&data, nonce);
- nonce = nonce + 1;
- if hash.find(&difficulty_str) != None {
- proof = true;
- } else {
- println!("Nonce increased to {}", nonce);
- }
- }
- println!("found proof of work at nonce {} with hash {}", nonce, hash);
- }
Add Comment
Please, Sign In to add comment