summaryrefslogtreecommitdiff
path: root/src/blocks.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-10-22 19:05:02 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-10-23 22:00:57 +0800
commitee8daa37cb327d2f3fb011f54e0c566e0004435d (patch)
tree6d3c631c12a7d6e2cd976ce197d5a6b2aede2b40 /src/blocks.rs
parent71d5eadbc5ebe366da3af11dd8a010f55a83fd05 (diff)
fix: usage of hash_chain
fix: visibility of hash_chain funcs
Diffstat (limited to 'src/blocks.rs')
-rw-r--r--src/blocks.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/blocks.rs b/src/blocks.rs
index 53f9326..d1f287a 100644
--- a/src/blocks.rs
+++ b/src/blocks.rs
@@ -4,11 +4,7 @@ use std::ops::Deref;
use serde::{Deserialize, Serialize};
-use crate::{
- ZERO_PREFIX_AMOUNT,
- hash_chain::{self, HashChain},
- transaction::Transaction,
-};
+use crate::{ZERO_PREFIX_AMOUNT, hash_chain::HashChain, transaction::Transaction};
use std::sync::{
Arc,
@@ -134,17 +130,15 @@ impl BlockChain {
}
pub fn new_block(&self, trans: Transaction) -> Block {
- let mut hasher = Sha256::new();
let prev = self
.blocks
.last();
let prev_hash = if let Some(b) = prev {
- b.digest(&mut hasher);
- Some(&*hasher.finalize())
+ Some(HashChain::hash_o_item(b))
} else {
None
};
- Block::new(prev_hash, trans)
+ Block::new(prev_hash.as_deref(), trans)
}
pub fn store(&mut self, block: Block) {
@@ -159,7 +153,7 @@ impl BlockChain {
}
impl Deref for BlockChain {
- type Target = Vec<Block>;
+ type Target = HashChain<Block>;
fn deref(&self) -> &Self::Target {
&self.blocks