1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
    Appellation: attr <blocks>
    Creator: FL03 <jo3mccain@icloud.com>
    Description: attributes for blocks in the Disarray mainnet
*/

pub use self::{
    classification::*, content::*, difficulty::*, header::*, interface::*, justification::*,
    utils::*,
};

pub(crate) mod classification;
pub(crate) mod content;
pub(crate) mod difficulty;
pub(crate) mod header;
pub(crate) mod interface;
pub(crate) mod justification;

pub(crate) mod utils {
    use crate::{
        blocks::{BlockContent, BlockDifficulty, BlockHeader, BlockJustification},
        transactions::{generate_random_signed_transaction, SignedTransaction},
    };
    use algae::merkle::{MerkleTree, MerkleTreeWrapper};
    use scsys::{
        core::Timestamp,
        prelude::{
            generate_random_hash,
            rand::{self, Rng},
        },
    };

    pub fn generate_random_block_content() -> BlockContent {
        BlockContent::new(
            vec![generate_random_signed_transaction()],
            vec![generate_random_hash()],
        )
    }

    pub fn generate_random_block_header(transactions: Vec<SignedTransaction>) -> BlockHeader {
        let mut rng = rand::thread_rng();
        let difficulty = BlockDifficulty::new(generate_random_hash(), generate_random_hash());
        let justification = BlockJustification::default();
        let root = MerkleTree::create(&transactions).root();
        BlockHeader::new(
            difficulty,
            justification,
            rng.gen(),
            generate_random_hash(),
            rng.gen(),
            root,
            Timestamp::timestamp(),
        )
    }
}