acme_chains/actors/chains/
chain.rs

1/*
2   Appellation: chains
3   Context:
4   Creator: FL03 <jo3mccain@icloud.com>
5   Description:
6       ... Summary ...
7*/
8use crate::Block;
9use serde::{Deserialize, Serialize};
10
11type Blockchain = Vec<Block>;
12
13pub enum ChainStates {}
14
15#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
16pub struct Chain {
17    pub blockchain: Blockchain,
18}
19
20impl Chain {
21    pub fn new() -> Self {
22        Self {
23            blockchain: Vec::new(),
24        }
25    }
26
27    pub fn constructor(&mut self) -> Blockchain {
28        let id = 0;
29        let data = "".to_string();
30        let previous = "genesis".to_string();
31        let genesis_block = Block::new(id, data.clone(), previous.clone());
32        self.blockchain.push(genesis_block);
33        self.blockchain.clone()
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_chain_genesis() {
43        let mut chain = Chain::new();
44        let blockchain = Chain::constructor(&mut chain);
45        println!("{:#?}", &chain);
46        assert_eq!(&blockchain, &blockchain)
47    }
48}