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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use bytes::Bytes;
use vapory_types::{H256, U256};
use tetsy_util_mem::MallocSizeOf;
use crate::BlockNumber;
use crate::header::Header;
use tetsy_rlp::{Rlp, RlpStream, Decodable, DecoderError};
use crate::transaction::{UnverifiedTransaction, SignedTransaction};
#[derive(Default, Debug, Clone, PartialEq)]
pub struct Block {
pub header: Header,
pub transactions: Vec<UnverifiedTransaction>,
pub uncles: Vec<Header>,
}
impl Block {
pub fn rlp_bytes(&self) -> Bytes {
let mut block_rlp = RlpStream::new_list(3);
block_rlp.append(&self.header);
block_rlp.append_list(&self.transactions);
block_rlp.append_list(&self.uncles);
block_rlp.out()
}
}
impl Decodable for Block {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
if rlp.as_raw().len() != rlp.payload_info()?.total() {
return Err(DecoderError::RlpIsTooBig);
}
if rlp.item_count()? != 3 {
return Err(DecoderError::RlpIncorrectListLen);
}
Ok(Block {
header: rlp.val_at(0)?,
transactions: rlp.list_at(1)?,
uncles: rlp.list_at(2)?,
})
}
}
#[derive(MallocSizeOf)]
pub struct PreverifiedBlock {
pub header: Header,
pub transactions: Vec<SignedTransaction>,
pub uncles: Vec<Header>,
pub bytes: Bytes,
}
#[derive(Clone)]
pub struct BlockInfo {
pub hash: H256,
pub number: BlockNumber,
pub total_difficulty: U256,
pub location: BlockLocation
}
#[derive(Debug, Clone, PartialEq)]
pub enum BlockLocation {
CanonChain,
Branch,
BranchBecomingCanonChain(BranchBecomingCanonChainData),
}
#[derive(Debug, Clone, PartialEq)]
pub struct BranchBecomingCanonChainData {
pub ancestor: H256,
pub enacted: Vec<H256>,
pub retracted: Vec<H256>,
}