Guest User

Untitled

a guest
Oct 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. fn proof_of_work(data: String, difficulty: i16) {
  2. let mut nonce: i64 = 0;
  3. let mut proof: bool = false;
  4. let mut hash: String = String::from("");
  5. let mut difficulty_str: String = String::from("");
  6.  
  7. for _ in 0..difficulty {
  8. difficulty_str = String::from(difficulty_str + "0");
  9. }
  10.  
  11. while proof == false {
  12. hash = hash_block(&data, nonce);
  13. nonce = nonce + 1;
  14. if hash.find(&difficulty_str) != None {
  15. proof = true;
  16. } else {
  17. println!("Nonce increased to {}", nonce);
  18. }
  19. }
  20.  
  21. println!("found proof of work at nonce {} with hash {}", nonce, hash);
  22. }
Add Comment
Please, Sign In to add comment