summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-10-23 22:09:26 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-10-23 22:09:26 +0800
commitcadbb7e78aca4378364c8d55503824fb55d30e38 (patch)
tree30a858b9292e5abf8f311f2955a99634de8470cb
parentee8daa37cb327d2f3fb011f54e0c566e0004435d (diff)
feat: bc verify command
API: HashChain::verify now takes Vec instead of &[]
-rw-r--r--src/hash_chain.rs2
-rw-r--r--src/ui.rs20
2 files changed, 16 insertions, 6 deletions
diff --git a/src/hash_chain.rs b/src/hash_chain.rs
index f21b1d2..e0ae1f2 100644
--- a/src/hash_chain.rs
+++ b/src/hash_chain.rs
@@ -53,7 +53,7 @@ impl<T: Encode> HashChain<T> {
self.rehash(&base_hash);
}
- pub fn verify(&self, until_hash: &[u8]) -> bool {
+ pub fn verify(&self, until_hash: Vec<u8>) -> bool {
let pos = self
.data
.iter()
diff --git a/src/ui.rs b/src/ui.rs
index 446fdb6..fe2d186 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -56,11 +56,21 @@ impl Ui {
.get_blockchain()
.clone()
};
- println!(
- "{:#?}",
- bc.lock()
- .await
- );
+ let bc = bc
+ .lock()
+ .await;
+ if let Some(cmd) = cmd.get(1) {
+ if *cmd == "verify" {
+ bc.verify(
+ bc.last()
+ .unwrap()
+ .0
+ .clone(),
+ );
+ }
+ } else {
+ println!("{:#?}", bc);
+ }
}
if cmd[0] == "peer" {