snarkvm_console_program/state_path/header_leaf/
mod.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16mod bytes;
17mod serialize;
18mod string;
19mod to_bits;
20
21use snarkvm_console_network::prelude::*;
22use snarkvm_console_types::Field;
23
24/// The Merkle leaf for the block header.
25#[derive(Copy, Clone, PartialEq, Eq)]
26pub struct HeaderLeaf<N: Network> {
27    /// The index of the Merkle leaf.
28    index: u8,
29    /// The ID.
30    id: Field<N>,
31}
32
33impl<N: Network> HeaderLeaf<N> {
34    /// Initializes a new instance of `HeaderLeaf`.
35    pub const fn new(index: u8, id: Field<N>) -> Self {
36        Self { index, id }
37    }
38
39    /// Returns the index of the Merkle leaf.
40    pub const fn index(&self) -> u8 {
41        self.index
42    }
43
44    /// Returns the ID in the Merkle leaf.
45    pub const fn id(&self) -> Field<N> {
46        self.id
47    }
48}
49
50#[cfg(test)]
51mod test_helpers {
52    use super::*;
53    use snarkvm_console_network::MainnetV0;
54
55    type CurrentNetwork = MainnetV0;
56
57    pub(super) fn sample_leaf(rng: &mut TestRng) -> HeaderLeaf<CurrentNetwork> {
58        // Construct a new leaf.
59        HeaderLeaf::new(rng.gen(), Uniform::rand(rng))
60    }
61}