disarray-ledger 0.1.20

This crate services our hybrid multi-chain directly implementing several critical structures from blocks to chains and transactions
Documentation
/*
   Appellation: mine <module>
   Creator: FL03 <jo3mccain@icloud.com>
   Description:
       ... Summary ...
*/
use crate::{
    blocks::calculate_block_hash, transactions::SignedTransaction, BlockHs, BlockId, BlockNc,
    BlockTs, DIFFICULTY_PREFIX,
};

/// Mines a new block<Dt> where Dt represents transaction data
pub fn create_block_by_mining(
    id: BlockId,
    previous: BlockHs,
    timestamp: BlockTs,
    transactions: Vec<SignedTransaction>,
) -> (BlockNc, BlockHs) {
    log::info!("Mining a new block...");
    let mut nonce = 0;
    loop {
        if nonce % 100000 == 0 {
            log::info!("nonce: {}", nonce);
        }
        let hash = calculate_block_hash(id, nonce, previous, timestamp, transactions.clone());
        let binary_hash = &hash.0;
        if binary_hash.starts_with(DIFFICULTY_PREFIX.as_ref()) {
            log::info!(
                "mined! nonce: {}, hash: {}, binary hash: {:#?}",
                nonce,
                hex::encode(hash),
                binary_hash
            );
            return (nonce, hash);
        }
        nonce += 1;
    }
}