Skip to content

Commit

Permalink
Starting with proof of work
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielgusn committed Apr 24, 2024
1 parent aeacd00 commit 25ebc4f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ pub fn read_tx_from_file(file_path: &str) -> Tx {
return tx_in_json;
}

pub fn sort_txs_by_fee(mut txs: Vec<Tx>){
txs.sort_by_key(|tx| tx.calculate_tx_fee());
}

// TODO: this function is with a problem that all the strings are coming with "\".......\""
// pub fn convert_json_tx_to_struct(tx_json: serde_json::Value) -> Tx {
// let tx_vin = &tx_json["vin"][0];
Expand Down
28 changes: 23 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,32 @@ fn main() {
println!("1st Block Hash: {}", first_block_header.get_block_header_sha256sum());
println!("Size of Block Header: {}", std::mem::size_of::<BlockHeader>());

let data: &str = "texto 1234";
let mut block_vec: Vec<BlockHeader> = vec![];

let mut nonce: u64 = 0_u64;
block_vec.push(first_block_header);

for i in 0..10{
println!("{}", i);
let block_header = BlockHeader::new(block_vec[i].get_block_header_sha256sum(), String::from("00000000000000000000000000000000"), Utc::now(), 0);
block_vec.push(block_header);
}

let teste_string: String = String::from("teste");
for block in &block_vec {
println!("{}", block);
}

println!("{}", teste_string.len());

let mut nonce: u64 = 0_u64;

// for mut block in block_vec{
loop {
if block_vec[0].get_block_header_sha256sum() < block_vec[0].target_hash {
println!("Found the nonce for the target Hash! It is: {} and you can attach this block to the blockchain\n\t Block Hash is: {}", block_vec[0].nonce, block_vec[0].get_block_header_sha256sum());
break
}
println!("Not yet! ({})", block_vec[0].get_block_header_sha256sum());
block_vec[0].nonce += 1;
}
// }

// loop{

Expand Down

0 comments on commit 25ebc4f

Please sign in to comment.