penumbra_sdk_tct/internal/complete/
leaf.rs1use crate::prelude::*;
2
3#[derive(Clone, Copy, Derivative, Serialize, Deserialize)]
5#[derivative(Debug = "transparent")]
6pub struct Leaf<Item>(pub(in super::super) Item);
7
8impl<Item> Leaf<Item> {
9 pub fn new(item: Item) -> Self {
11 Self(item)
12 }
13}
14
15impl<Item: GetHash> GetHash for Leaf<Item> {
16 #[inline]
17 fn hash(&self) -> Hash {
18 self.0.hash()
19 }
20
21 #[inline]
22 fn cached_hash(&self) -> Option<Hash> {
23 self.0.cached_hash()
24 }
25}
26
27impl<Item: Height> Height for Leaf<Item> {
28 type Height = Item::Height;
29}
30
31impl<Item: Complete> Complete for Leaf<Item> {
32 type Focus = frontier::Leaf<<Item as Complete>::Focus>;
33}
34
35impl<Item: Witness> Witness for Leaf<Item> {
36 #[inline]
37 fn witness(&self, index: impl Into<u64>) -> Option<(AuthPath<Self>, Hash)> {
38 self.0.witness(index)
39 }
40}
41
42impl<Item: ForgetOwned> ForgetOwned for Leaf<Item> {
43 fn forget_owned(
44 self,
45 forgotten: Option<Forgotten>,
46 index: impl Into<u64>,
47 ) -> (Insert<Self>, bool) {
48 let (item, forgotten) = self.0.forget_owned(forgotten, index);
49 (item.map(Leaf), forgotten)
50 }
51}
52
53impl<Item> GetPosition for Leaf<Item> {
54 fn position(&self) -> Option<u64> {
55 None
56 }
57}
58
59impl<'tree, Item: Height + structure::Any<'tree>> structure::Any<'tree> for Leaf<Item> {
60 fn kind(&self) -> Kind {
61 self.0.kind()
62 }
63
64 fn forgotten(&self) -> Forgotten {
65 self.0.forgotten()
66 }
67
68 fn children(&'tree self) -> Vec<HashOrNode<'tree>> {
69 self.0.children()
70 }
71}
72
73impl<Item: OutOfOrderOwned> OutOfOrderOwned for Leaf<Item> {
74 fn uninitialized_out_of_order_insert_commitment_owned(
75 this: Insert<Self>,
76 index: u64,
77 commitment: StateCommitment,
78 ) -> Self {
79 Leaf(Item::uninitialized_out_of_order_insert_commitment_owned(
80 this.map(|leaf| leaf.0),
81 index,
82 commitment,
83 ))
84 }
85}
86
87impl<Item: UncheckedSetHash> UncheckedSetHash for Leaf<Item> {
88 fn unchecked_set_hash(&mut self, index: u64, height: u8, hash: Hash) {
89 self.0.unchecked_set_hash(index, height, hash)
90 }
91
92 fn finish_initialize(&mut self) {
93 self.0.finish_initialize()
94 }
95}