diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-10-21 20:55:56 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-10-21 21:14:13 +0800 |
| commit | 2dfd9da52761e738c9d113dee2503bc8a9a82edc (patch) | |
| tree | da3d6cf1af44fba8f720f03e39b3d64f54d34984 | |
| parent | 84b41b9a6619094383dbacfbdaa8c0f3e2819113 (diff) | |
fix(block): fix verification of PoW
| -rw-r--r-- | src/blocks.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/blocks.rs b/src/blocks.rs index 67af3f1..1097626 100644 --- a/src/blocks.rs +++ b/src/blocks.rs @@ -58,10 +58,14 @@ impl Block { unreachable!() } - pub fn verify_pow(&mut self) -> bool { - let mut hasher = Sha256::new(); - Digest::update(&mut hasher, bincode::encode_to_vec(&*self, bincode::config::standard()).unwrap()); - Self::pref_zeros(&hasher.finalize()).is_ok() + pub fn verify_pow(&self) -> bool { + if let Some(nonce) = self.pow { + let mut hasher = Sha256::new(); + Digest::update(&mut hasher, bincode::encode_to_vec((&self.prev_hash, &self.trans, nonce), bincode::config::standard()).unwrap()); + Self::pref_zeros(&hasher.finalize()).is_ok() + } else { + false + } } pub fn calc_set_pow(&mut self) { |
