pub struct Block {
pub transactions: Vec<Transaction>,
pub timestamp: u64,
pub nonce: u64,
pub meta: BlockMetadata,
}Expand description
Stores transaction, difficulties, its hash, and its nonce The hash can be often used for indexing, however can only be trusted if this node checked this block already
Fields§
§transactions: Vec<Transaction>§timestamp: u64§nonce: u64§meta: BlockMetadataImplementations§
Source§impl Block
impl Block
Sourcepub fn new_block_now(
transactions: Vec<Transaction>,
block_pow_difficulty: &[u8; 32],
tx_pow_difficulty: &[u8; 32],
previous_block: Hash,
merkle_tree_root: &[u8; 32],
address_inclusion_filter: AddressInclusionFilter,
) -> Self
pub fn new_block_now( transactions: Vec<Transaction>, block_pow_difficulty: &[u8; 32], tx_pow_difficulty: &[u8; 32], previous_block: Hash, merkle_tree_root: &[u8; 32], address_inclusion_filter: AddressInclusionFilter, ) -> Self
Create a new block timestamped now, with a set of transactions, specifying transaction difficulty and block difficulty
Sourcepub fn get_hashing_buf(&self) -> Result<Vec<u8>, EncodeError>
pub fn get_hashing_buf(&self) -> Result<Vec<u8>, EncodeError>
Get this blocks hashing buffer required to mine this transaction. Essentially makes sure that any hash attached to this block is not included in the block hashing buffer WARNING: Slow
Sourcepub fn compute_pow(&mut self) -> Result<(), EncodeError>
👎Deprecated
pub fn compute_pow(&mut self) -> Result<(), EncodeError>
Mine this block and attach its hash. DEPRECATED: This is single threaded and cannot be used for actual mining as proper, multi-threaded mining machines outperform this by absolute miles
Sourcepub fn check_meta(&self) -> Result<(), BlockError>
pub fn check_meta(&self) -> Result<(), BlockError>
Checks if block meta is valid
Sourcepub fn check_completeness(&self) -> Result<(), BlockError>
pub fn check_completeness(&self) -> Result<(), BlockError>
Checks if this block is complete, and has all required fields to be valid on a blockchain
Sourcepub fn validate_block_hash(&self) -> Result<(), BlockError>
pub fn validate_block_hash(&self) -> Result<(), BlockError>
Checks if the attached block hash is valid
Sourcepub fn validate_difficulties(
&self,
real_block_pow_difficulty: &[u8; 32],
real_tx_pow_difficulty: &[u8; 32],
) -> Result<(), BlockError>
pub fn validate_difficulties( &self, real_block_pow_difficulty: &[u8; 32], real_tx_pow_difficulty: &[u8; 32], ) -> Result<(), BlockError>
Checks if the passed difficulties match the blocks difficulties (true = valid, false = invalid)
Sourcepub fn validate_merkle_tree(&self) -> Result<(), BlockError>
pub fn validate_merkle_tree(&self) -> Result<(), BlockError>
Check if merkle tree root is correctly calculated
Sourcepub fn validate_address_inclusion_filter(&self) -> Result<(), BlockError>
pub fn validate_address_inclusion_filter(&self) -> Result<(), BlockError>
Check if inclusion filter is correctly calculated