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
use std::{
fmt::{Debug, Display},
hash::Hash,
};
use derive_more::Display;
use serde::{de::DeserializeOwned, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use casper_execution_engine::storage::trie::Trie;
use casper_hashing::Digest;
use casper_types::{bytesrepr::ToBytes, Key, StoredValue};
use crate::types::{BlockHash, BlockHeader, BlockHeaderWithMetadata};
#[derive(
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize_repr,
Deserialize_repr,
Debug,
Display,
)]
#[repr(u8)]
pub enum Tag {
Deploy,
Block,
GossipedAddress,
BlockByHeight,
BlockHeaderByHash,
BlockHeaderAndFinalitySignaturesByHeight,
}
pub trait Item: Clone + Serialize + DeserializeOwned + Send + Sync + Debug + Display {
type Id: Copy + Eq + Hash + Serialize + DeserializeOwned + Send + Sync + Debug + Display;
const TAG: Tag;
const ID_IS_COMPLETE_ITEM: bool;
fn id(&self) -> Self::Id;
}
impl Item for Trie<Key, StoredValue> {
type Id = Digest;
const TAG: Tag = Tag::Deploy;
const ID_IS_COMPLETE_ITEM: bool = false;
fn id(&self) -> Self::Id {
let node_bytes = self.to_bytes().expect("Could not serialize trie to bytes");
Digest::hash(&node_bytes)
}
}
impl Item for BlockHeader {
type Id = BlockHash;
const TAG: Tag = Tag::BlockHeaderByHash;
const ID_IS_COMPLETE_ITEM: bool = false;
fn id(&self) -> Self::Id {
self.hash()
}
}
impl Item for BlockHeaderWithMetadata {
type Id = u64;
const TAG: Tag = Tag::BlockHeaderAndFinalitySignaturesByHeight;
const ID_IS_COMPLETE_ITEM: bool = false;
fn id(&self) -> Self::Id {
self.block_header.height()
}
}