penumbra_sdk_tct/internal/complete/
top.rs

1use crate::prelude::*;
2
3use complete::Nested;
4
5/// A complete top-level tier of the tiered commitment tree, being an 8-deep sparse quad-tree.
6#[derive(Clone, Debug, Serialize, Deserialize)]
7pub struct Top<Item: GetHash + Height + Clone> {
8    pub(in super::super) inner: Nested<Item>,
9}
10
11impl<Item: GetHash + Height + Clone> Height for Top<Item> {
12    type Height = <Nested<Item> as Height>::Height;
13}
14
15impl<Item: GetHash + Height + Clone> GetHash for Top<Item> {
16    #[inline]
17    fn hash(&self) -> Hash {
18        self.inner.hash()
19    }
20
21    #[inline]
22    fn cached_hash(&self) -> Option<Hash> {
23        self.inner.cached_hash()
24    }
25}
26
27impl<Item: GetHash + Height + Clone> From<complete::Tier<Item>> for Top<Item> {
28    fn from(tier: complete::Tier<Item>) -> Self {
29        Top { inner: tier.inner }
30    }
31}
32
33impl<Item: Height + GetHash + Clone> GetPosition for Top<Item> {
34    fn position(&self) -> Option<u64> {
35        None
36    }
37}
38
39impl<'tree, Item: Height + structure::Any<'tree> + Clone> structure::Any<'tree> for Top<Item> {
40    fn kind(&self) -> Kind {
41        self.inner.kind()
42    }
43
44    fn forgotten(&self) -> Forgotten {
45        (&self.inner as &dyn structure::Any).forgotten()
46    }
47
48    fn children(&'tree self) -> Vec<HashOrNode<'tree>> {
49        (&self.inner as &dyn structure::Any).children()
50    }
51}
52
53impl<Item: GetHash + Height + OutOfOrderOwned + Clone> OutOfOrderOwned for Top<Item> {
54    fn uninitialized_out_of_order_insert_commitment_owned(
55        this: Insert<Self>,
56        index: u64,
57        commitment: StateCommitment,
58    ) -> Self {
59        Top {
60            inner: Nested::uninitialized_out_of_order_insert_commitment_owned(
61                this.map(|tier| tier.inner),
62                index,
63                commitment,
64            ),
65        }
66    }
67}
68
69impl<Item: GetHash + UncheckedSetHash + Clone> UncheckedSetHash for Top<Item> {
70    fn unchecked_set_hash(&mut self, index: u64, height: u8, hash: Hash) {
71        self.inner.unchecked_set_hash(index, height, hash)
72    }
73
74    fn finish_initialize(&mut self) {
75        self.inner.finish_initialize()
76    }
77}