(&self)
| 135 | |
| 136 | |
| 137 | pub fn run(&self) -> (i64, String) { |
| 138 | let mut nonce = 0; |
| 139 | let mut hash = Vec::new(); |
| 140 | println!("Mining the block"); |
| 141 | while nonce < MAX_NONCE { |
| 142 | let data = self.prepare_data(nonce); |
| 143 | hash = crate::sha256_digest(data.as_slice()); |
| 144 | let hash_int = BigInt::from_bytes_be(Sign::Plus, hash.as_slice()); |
| 145 | |
| 146 | |
| 147 | if hash_int.lt(self.target.borrow()) { |
| 148 | println!("{}", HEXLOWER.encode(hash.as_slice())); |
| 149 | break; |
| 150 | } else { |
| 151 | nonce += 1; |
| 152 | } |
| 153 | } |
| 154 | println!(); |
| 155 | return (nonce, HEXLOWER.encode(hash.as_slice())); |
| 156 | } |
| 157 | } |
no test coverage detected