Skip to content

Commit

Permalink
Update block.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 11, 2024
1 parent c2917c3 commit 006fe61
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions pi-nexus-blockchain/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
// block.rs (updated)
// block.rs (update)

// ...
use crate::transaction::Transaction;

impl BlockHeader {
// ...
pub struct Block {
pub index: u64,
pub previous_hash: String,
pub timestamp: u64,
pub transactions: Vec<Transaction>,
pub hash: String,
}

pub fn mine(&mut self, difficulty_target: u64) {
let mut nonce = 0;
loop {
self.nonce = nonce;
let hash = self.hash();
if hash.starts_with(&format!("{:0>64}", difficulty_target)) {
break;
}
nonce += 1;
impl Block {
pub fn new(index: u64, previous_hash: &str, transactions: Vec<Transaction>) -> Self {
let timestamp = crate::utils::get_current_timestamp();
let hash = crate::utils::calculate_block_hash(index, previous_hash, &transactions, timestamp);
Block {
index,
previous_hash: previous_hash.to_string(),
timestamp,
transactions,
hash,
}
}
}

0 comments on commit 006fe61

Please sign in to comment.