kaspa_database/
registry.rs1use enum_primitive_derive::Primitive;
2
3pub const SEPARATOR: u8 = u8::MAX;
6
7#[derive(Primitive, Debug, Clone, Copy)]
8#[repr(u8)]
9pub enum DatabaseStorePrefixes {
10 AcceptanceData = 1,
12 BlockTransactions = 2,
13 NonDaaMergeset = 3,
14 BlockDepth = 4,
15 Ghostdag = 5,
16 GhostdagCompact = 6,
17 HeadersSelectedTip = 7,
18 Headers = 8,
19 HeadersCompact = 9,
20 PastPruningPoints = 10,
21 PruningUtxoset = 11,
22 PruningUtxosetPosition = 12,
23 PruningPoint = 13,
24 HistoryRoot = 14,
25 Reachability = 15,
26 ReachabilityReindexRoot = 16,
27 ReachabilityRelations = 17,
28 RelationsParents = 18,
29 RelationsChildren = 19,
30 ChainHashByIndex = 20,
31 ChainIndexByHash = 21,
32 ChainHighestIndex = 22,
33 Statuses = 23,
34 Tips = 24,
35 UtxoDiffs = 25,
36 UtxoMultisets = 26,
37 VirtualUtxoset = 27,
38 VirtualState = 28,
39
40 ReachabilityTreeChildren = 30,
42 ReachabilityFutureCoveringSet = 31,
43
44 MultiConsensusMetadata = 124,
46 ConsensusEntries = 125,
47
48 Addresses = 128,
50 BannedAddresses = 129,
51
52 UtxoIndex = 192,
54 UtxoIndexTips = 193,
55 CirculatingSupply = 194,
56
57 Separator = SEPARATOR,
60}
61
62impl From<DatabaseStorePrefixes> for Vec<u8> {
63 fn from(value: DatabaseStorePrefixes) -> Self {
64 [value as u8].to_vec()
65 }
66}
67
68impl From<DatabaseStorePrefixes> for u8 {
69 fn from(value: DatabaseStorePrefixes) -> Self {
70 value as u8
71 }
72}
73
74impl AsRef<[u8]> for DatabaseStorePrefixes {
75 fn as_ref(&self) -> &[u8] {
76 std::slice::from_ref(unsafe { &*(self as *const Self as *const u8) })
78 }
79}
80
81impl IntoIterator for DatabaseStorePrefixes {
82 type Item = u8;
83 type IntoIter = <[u8; 1] as IntoIterator>::IntoIter;
84 fn into_iter(self) -> Self::IntoIter {
85 [self as u8].into_iter()
86 }
87}
88
89#[cfg(test)]
90mod tests {
91 use super::*;
92
93 #[test]
94 fn test_as_ref() {
95 let prefix = DatabaseStorePrefixes::AcceptanceData;
96 assert_eq!(&[prefix as u8], prefix.as_ref());
97 assert_eq!(
98 size_of::<u8>(),
99 size_of::<DatabaseStorePrefixes>(),
100 "DatabaseStorePrefixes is expected to have the same memory layout of u8"
101 );
102 }
103}