snarkvm_ledger/
contains.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 `true` if the given state root exists.
20    pub fn contains_state_root(&self, state_root: &N::StateRoot) -> Result<bool> {
21        self.vm.block_store().contains_state_root(state_root)
22    }
23
24    /// Returns `true` if the given block height exists.
25    pub fn contains_block_height(&self, height: u32) -> Result<bool> {
26        self.vm.block_store().contains_block_height(height)
27    }
28
29    /// Returns `true` if the given block hash exists.
30    pub fn contains_block_hash(&self, block_hash: &N::BlockHash) -> Result<bool> {
31        self.vm.block_store().contains_block_hash(block_hash)
32    }
33
34    /// Returns `true` if the given batch certificate ID exists.
35    pub fn contains_certificate(&self, certificate_id: &Field<N>) -> Result<bool> {
36        self.vm.block_store().contains_certificate(certificate_id)
37    }
38
39    /// Returns `true` if the given program ID exists.
40    pub fn contains_program_id(&self, program_id: &ProgramID<N>) -> Result<bool> {
41        self.vm.transaction_store().contains_program_id(program_id)
42    }
43
44    /// Returns `true` if the transmission exists in the ledger.
45    pub fn contains_transmission(&self, transmission_id: &TransmissionID<N>) -> Result<bool> {
46        match transmission_id {
47            TransmissionID::Ratification => Ok(false),
48            TransmissionID::Solution(solution_id, _) => self.contains_solution_id(solution_id),
49            TransmissionID::Transaction(transaction_id, _) => self.contains_transaction_id(transaction_id),
50        }
51    }
52
53    /// Returns `true` if the given solution ID exists.
54    pub fn contains_solution_id(&self, solution_id: &SolutionID<N>) -> Result<bool> {
55        self.vm.block_store().contains_solution_id(solution_id)
56    }
57
58    /* Transaction */
59
60    /// Returns `true` if the given transaction ID exists.
61    pub fn contains_transaction_id(&self, transaction_id: &N::TransactionID) -> Result<bool> {
62        self.vm.block_store().contains_transaction_id(transaction_id)
63    }
64
65    /* Transition */
66
67    /// Returns `true` if the given transition ID exists.
68    pub fn contains_transition_id(&self, transition_id: &N::TransitionID) -> Result<bool> {
69        self.vm.transition_store().contains_transition_id(transition_id)
70    }
71
72    /* Input */
73
74    /// Returns `true` if the given input ID exists.
75    pub fn contains_input_id(&self, input_id: &Field<N>) -> Result<bool> {
76        self.vm.transition_store().contains_input_id(input_id)
77    }
78
79    /// Returns `true` if the given serial number exists.
80    pub fn contains_serial_number(&self, serial_number: &Field<N>) -> Result<bool> {
81        self.vm.transition_store().contains_serial_number(serial_number)
82    }
83
84    /// Returns `true` if the given tag exists.
85    pub fn contains_tag(&self, tag: &Field<N>) -> Result<bool> {
86        self.vm.transition_store().contains_tag(tag)
87    }
88
89    /* Output */
90
91    /// Returns `true` if the given output ID exists.
92    pub fn contains_output_id(&self, output_id: &Field<N>) -> Result<bool> {
93        self.vm.transition_store().contains_output_id(output_id)
94    }
95
96    /// Returns `true` if the given commitment exists.
97    pub fn contains_commitment(&self, commitment: &Field<N>) -> Result<bool> {
98        self.vm.transition_store().contains_commitment(commitment)
99    }
100
101    /// Returns `true` if the given checksum exists.
102    pub fn contains_checksum(&self, checksum: &Field<N>) -> bool {
103        self.vm.transition_store().contains_checksum(checksum)
104    }
105
106    /// Returns `true` if the given nonce exists.
107    pub fn contains_nonce(&self, nonce: &Group<N>) -> Result<bool> {
108        self.vm.transition_store().contains_nonce(nonce)
109    }
110
111    /* Metadata */
112
113    /// Returns `true` if the given transition public key exists.
114    pub fn contains_tpk(&self, tpk: &Group<N>) -> Result<bool> {
115        self.vm.transition_store().contains_tpk(tpk)
116    }
117
118    /// Returns `true` if the given transition commitment exists.
119    pub fn contains_tcm(&self, tcm: &Field<N>) -> Result<bool> {
120        self.vm.transition_store().contains_tcm(tcm)
121    }
122}