From 2dfd9da52761e738c9d113dee2503bc8a9a82edc Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 21 Oct 2025 20:55:56 +0800 Subject: fix(block): fix verification of PoW --- src/blocks.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/blocks.rs') 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) { -- cgit v1.2.3