summaryrefslogtreecommitdiff
path: root/src/blocks.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-10-21 09:23:53 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-10-21 09:25:48 +0800
commitb71fae628d97ada84c533ce746d4d7980a9f6d73 (patch)
tree89e0a4b083e607a627f5a29a9cffe7d0df188f40 /src/blocks.rs
parent5a96ec7b15a34d6a9b927496cf3e959bd4dd72d5 (diff)
perf(Block::verify_pow): directly use self.hash
chore(Block::Hash)!: panic when trying to hash with no PoW
Diffstat (limited to 'src/blocks.rs')
-rw-r--r--src/blocks.rs16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/blocks.rs b/src/blocks.rs
index 758fe71..288e754 100644
--- a/src/blocks.rs
+++ b/src/blocks.rs
@@ -42,9 +42,9 @@ impl Block {
unreachable!()
}
- pub fn verify_pow(&mut self, pow: u64) -> bool {
+ pub fn verify_pow(&mut self) -> bool {
let mut hasher = DefaultHasher::new();
- (&self.prev_hash, &self.trans, pow).hash(&mut hasher);
+ self.hash(&mut hasher);
hasher
.finish()
.to_string()
@@ -66,15 +66,9 @@ impl Hash for Block {
.hash(state);
self.trans
.hash(state);
- if self
- .pow
- .is_none()
- {
- Self::calc_pow(self).hash(state);
- } else {
- self.pow
- .hash(state);
- }
+ self.pow
+ .expect("Cannot hash whole block with no PoW")
+ .hash(state);
}
}