snarkvm_ledger/
iterators.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
16use super::*;
17
18impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
19    /// Returns an iterator over the state roots, for all blocks in `self`.
20    pub fn state_roots(&self) -> impl '_ + Iterator<Item = Cow<'_, N::StateRoot>> {
21        self.vm.block_store().state_roots()
22    }
23
24    /// Returns an iterator over the solution IDs, for all blocks in `self`.
25    pub fn solution_ids(&self) -> impl '_ + Iterator<Item = Cow<'_, SolutionID<N>>> {
26        self.vm.block_store().solution_ids()
27    }
28
29    /* Transaction */
30
31    /// Returns an iterator over the program IDs, for all transactions in `self`.
32    pub fn program_ids(&self) -> impl '_ + Iterator<Item = Cow<'_, ProgramID<N>>> {
33        self.vm.transaction_store().program_ids()
34    }
35
36    /// Returns an iterator over the programs, for all transactions in `self`.
37    pub fn programs(&self) -> impl '_ + Iterator<Item = Cow<'_, Program<N>>> {
38        self.vm.transaction_store().programs()
39    }
40
41    /// Returns an iterator over the transaction IDs, for all transactions in `self`.
42    pub fn transaction_ids(&self) -> impl '_ + Iterator<Item = Cow<'_, N::TransactionID>> {
43        self.vm.transaction_store().transaction_ids()
44    }
45
46    /* Transition */
47
48    /// Returns an iterator over the transition IDs, for all transitions.
49    pub fn transition_ids(&self) -> impl '_ + Iterator<Item = Cow<'_, N::TransitionID>> {
50        self.vm.transition_store().transition_ids()
51    }
52
53    /* Input */
54
55    /// Returns an iterator over the input IDs, for all transition inputs.
56    pub fn input_ids(&self) -> impl '_ + Iterator<Item = Cow<'_, Field<N>>> {
57        self.vm.transition_store().input_ids()
58    }
59
60    /// Returns an iterator over the serial numbers, for all transition inputs that are records.
61    pub fn serial_numbers(&self) -> impl '_ + Iterator<Item = Cow<'_, Field<N>>> {
62        self.vm.transition_store().serial_numbers()
63    }
64
65    /// Returns an iterator over the tags, for all transition inputs that are records.
66    pub fn tags(&self) -> impl '_ + Iterator<Item = Cow<'_, Field<N>>> {
67        self.vm.transition_store().tags()
68    }
69
70    /* Output */
71
72    /// Returns an iterator over the output IDs, for all transition outputs that are records.
73    pub fn output_ids(&self) -> impl '_ + Iterator<Item = Cow<'_, Field<N>>> {
74        self.vm.transition_store().output_ids()
75    }
76
77    /// Returns an iterator over the commitments, for all transition outputs that are records.
78    pub fn commitments(&self) -> impl '_ + Iterator<Item = Cow<'_, Field<N>>> {
79        self.vm.transition_store().commitments()
80    }
81
82    /// Returns an iterator over the nonces, for all transition outputs that are records.
83    pub fn nonces(&self) -> impl '_ + Iterator<Item = Cow<'_, Group<N>>> {
84        self.vm.transition_store().nonces()
85    }
86
87    /// Returns an iterator over the `(commitment, record)` pairs, for all transition outputs that are records.
88    #[allow(clippy::type_complexity)]
89    pub fn records(&self) -> impl '_ + Iterator<Item = (Cow<'_, Field<N>>, Cow<'_, Record<N, Ciphertext<N>>>)> {
90        self.vm.transition_store().records()
91    }
92
93    /* Metadata */
94
95    /// Returns an iterator over the transition public keys, for all transactions.
96    pub fn transition_public_keys(&self) -> impl '_ + Iterator<Item = Cow<'_, Group<N>>> {
97        self.vm.transition_store().tpks()
98    }
99}