block.rs
block.rs
-----------------------------------------------------------------------------------
---------------
// Getting started with building the Blockchain ( block.rs / proof of work.rs)
//
-----------------------------------------------------------------------------------
---------------
// Block.rs file
use crate::{ProofOfWork, Transaction};
use serde::{Deserialize, Serialize};
use sled::IVec;
impl Block {
// Proof of work.rs
use crate::Block;
use data_encoding::HEXLOWER;
use num_bigint::{BigInt, Sign};
use std::borrow::Borrow;
use std::ops::ShlAssign;
target.shl_assign(256 - TARGET_BITS);
ProofOfWork { block, target }
}
if hash_int.lt(self.target.borrow()) {
println!("{}", HEXLOWER.encode(hash.as_slice()));
break;
} else {
nonce += 1;
}
}
println!();
return (nonce, HEXLOWER.encode(hash.as_slice()));
}
}