pub fn validate_block(block: &Block, previous_block: &Block) -> bool {
        if block.previous_hash != previous_block.hash {
            println!("block with id: {} has wrong previous hash", block.id);
            return false;
        } else if !&block.hash.starts_with(DIFFICULTY_PREFIX) {
            println!("block with id: {} has invalid difficulty", block.id);
            return false;
        } else if block.id != previous_block.id + 1 {
            println!(
                "block with id: {} is not the next block after the latest: {}",
                block.id, previous_block.id
            );
            return false;
        } else if hash_to_binary(&calculate_hash(
            &block.data,
            block.id,
            &block.next_miner,
            &block.next_validators,
            block.nonce,
            &block.previous_hash,
            block.timestamp,
        )) != block.hash
        {
            println!("block with id: {} has invalid hash", block.id);
            return false;
        }
        true
    }
/// Validates if two adjacent blocks have been correctly mined
Validates if two adjacent blocks have been correctly mined
Validates if two adjacent blocks have been correctly mined
pub fn validate_block(block: &Block, previous_block: &Block) -> bool {
        if block.previous_hash != previous_block.hash {
            println!("block with id: {} has wrong previous hash", block.id);
            return false;
        } else if !&block.hash.starts_with(DIFFICULTY_PREFIX) {
            println!("block with id: {} has invalid difficulty", block.id);
            return false;
        } else if block.id != previous_block.id + 1 {
            println!(
                "block with id: {} is not the next block after the latest: {}",
                block.id, previous_block.id
            );
            return false;
        } else if hash_to_binary(&calculate_hash(
            &block.data,
            block.id,
            &block.next_miner,
            &block.next_validators,
            block.nonce,
            &block.previous_hash,
            block.timestamp,
        )) != block.hash
        {
            println!("block with id: {} has invalid hash", block.id);
            return false;
        }
        true
    }
pub fn validate_block ( block : & Block , previous_block : & Block ) -> bool { if block . previous_hash != previous_block . hash { println ! ( " " block id ) ; return false ; } else if ! & block . hash . starts_with ( DIFFICULTY_PREFIX ) { println ! ( " " block id ) ; return false ; } else if block . id != previous_block . id + 1 { println ! ( " " block id previous_block id ) ; return false ; } else if hash_to_binary ( & calculate_hash ( & block . data , block . id , & block . next_miner , & block . next_validators , block . nonce , & block . previous_hash , block . timestamp , ) ) != block . hash { println ! ( " " block id ) ; return false ; } true }
Validates if two adjacent blocks have been correctly mined
Validates if two adjacent blocks have been correctly mined
block
&Block
previous_block
&Block