summaryrefslogtreecommitdiff
path: root/src
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
parent71d5eadbc5ebe366da3af11dd8a010f55a83fd05 (diff)
fix: usage of hash_chain
fix: visibility of hash_chain funcs
Diffstat (limited to 'src')
-rw-r--r--src/blocks.rs14
-rw-r--r--src/hash_chain.rs8
-rw-r--r--src/network.rs2
3 files changed, 9 insertions, 15 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
diff --git a/src/hash_chain.rs b/src/hash_chain.rs
index 0fe2c1d..f21b1d2 100644
--- a/src/hash_chain.rs
+++ b/src/hash_chain.rs
@@ -26,7 +26,7 @@ impl<T: Encode> HashChain<T> {
this
}
- fn push(&mut self, data: T) {
+ pub fn push(&mut self, data: T) {
let prev_hash = self
.data
.last()
@@ -40,7 +40,7 @@ impl<T: Encode> HashChain<T> {
// TODO: make try_last that does same as this but returns Err() if it's not the
// last one and/or refuse to insert
- fn insert(&mut self, data: T, base_hash: &Vec<u8>) {
+ pub fn insert(&mut self, data: T, base_hash: &Vec<u8>) {
let pos = self
.data
.iter()
@@ -53,7 +53,7 @@ impl<T: Encode> HashChain<T> {
self.rehash(&base_hash);
}
- fn verify(&self, until_hash: &[u8]) -> bool {
+ pub fn verify(&self, until_hash: &[u8]) -> bool {
let pos = self
.data
.iter()
@@ -68,7 +68,7 @@ impl<T: Encode> HashChain<T> {
})
}
- fn rehash(&mut self, from_hash: &[u8]) {
+ pub fn rehash(&mut self, from_hash: &[u8]) {
let pos = self
.data
.iter()
diff --git a/src/network.rs b/src/network.rs
index 4c3d2f6..08693c5 100644
--- a/src/network.rs
+++ b/src/network.rs
@@ -286,7 +286,7 @@ impl Peer {
// TODO: Optimize via try_fold
.fold(true, |i, b| {
if i {
- b.pow
+ b.1.pow
.is_none()
} else {
false