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
use near_primitives::views::{BlockHeaderView, BlockView};
use crate::{BlockHeight, CryptoHash};
#[derive(Debug, PartialEq)]
pub struct Block {
header: BlockHeader,
}
impl Block {
pub fn timestamp(&self) -> u64 {
self.header.timestamp_nanosec
}
pub fn height(&self) -> BlockHeight {
self.header.height
}
pub fn hash(&self) -> &CryptoHash {
&self.header.hash
}
pub fn epoch_id(&self) -> &CryptoHash {
&self.header.epoch_id
}
}
#[derive(Debug, PartialEq)]
struct BlockHeader {
height: BlockHeight,
epoch_id: CryptoHash,
hash: CryptoHash,
timestamp_nanosec: u64,
}
impl From<BlockView> for Block {
fn from(block_view: BlockView) -> Self {
Self {
header: block_view.header.into(),
}
}
}
impl From<BlockHeaderView> for BlockHeader {
fn from(header_view: BlockHeaderView) -> Self {
Self {
height: header_view.height,
epoch_id: CryptoHash(header_view.epoch_id.0),
hash: CryptoHash(header_view.hash.0),
timestamp_nanosec: header_view.timestamp_nanosec,
}
}
}