snarkvm_ledger_debug/
contains.rs

1// Copyright (C) 2019-2023 Aleo Systems 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// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use super::*;
16
17impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
18    /// Returns `true` if the given state root exists.
19    pub fn contains_state_root(&self, state_root: &N::StateRoot) -> Result<bool> {
20        self.vm.block_store().contains_state_root(state_root)
21    }
22
23    /// Returns `true` if the given block height exists.
24    pub fn contains_block_height(&self, height: u32) -> Result<bool> {
25        self.vm.block_store().contains_block_height(height)
26    }
27
28    /// Returns `true` if the given block hash exists.
29    pub fn contains_block_hash(&self, block_hash: &N::BlockHash) -> Result<bool> {
30        self.vm.block_store().contains_block_hash(block_hash)
31    }
32
33    /// Returns `true` if the given batch certificate ID exists.
34    pub fn contains_certificate(&self, certificate_id: &Field<N>) -> Result<bool> {
35        self.vm.block_store().contains_certificate(certificate_id)
36    }
37
38    /// Returns `true` if the given program ID exists.
39    pub fn contains_program_id(&self, program_id: &ProgramID<N>) -> Result<bool> {
40        self.vm.transaction_store().contains_program_id(program_id)
41    }
42
43    /// Returns `true` if the transmission exists in the ledger.
44    pub fn contains_transmission(&self, transmission_id: &TransmissionID<N>) -> Result<bool> {
45        match transmission_id {
46            TransmissionID::Ratification => Ok(false),
47            TransmissionID::Solution(puzzle_commitment) => self.contains_puzzle_commitment(puzzle_commitment),
48            TransmissionID::Transaction(transaction_id) => self.contains_transaction_id(transaction_id),
49        }
50    }
51
52    /// Returns `true` if the given puzzle commitment exists.
53    pub fn contains_puzzle_commitment(&self, puzzle_commitment: &PuzzleCommitment<N>) -> Result<bool> {
54        self.vm.block_store().contains_puzzle_commitment(puzzle_commitment)
55    }
56
57    /* Transaction */
58
59    /// Returns `true` if the given transaction ID exists.
60    pub fn contains_transaction_id(&self, transaction_id: &N::TransactionID) -> Result<bool> {
61        self.vm.block_store().contains_transaction_id(transaction_id)
62    }
63
64    /* Transition */
65
66    /// Returns `true` if the given transition ID exists.
67    pub fn contains_transition_id(&self, transition_id: &N::TransitionID) -> Result<bool> {
68        self.vm.transition_store().contains_transition_id(transition_id)
69    }
70
71    /* Input */
72
73    /// Returns `true` if the given input ID exists.
74    pub fn contains_input_id(&self, input_id: &Field<N>) -> Result<bool> {
75        self.vm.transition_store().contains_input_id(input_id)
76    }
77
78    /// Returns `true` if the given serial number exists.
79    pub fn contains_serial_number(&self, serial_number: &Field<N>) -> Result<bool> {
80        self.vm.transition_store().contains_serial_number(serial_number)
81    }
82
83    /// Returns `true` if the given tag exists.
84    pub fn contains_tag(&self, tag: &Field<N>) -> Result<bool> {
85        self.vm.transition_store().contains_tag(tag)
86    }
87
88    /* Output */
89
90    /// Returns `true` if the given output ID exists.
91    pub fn contains_output_id(&self, output_id: &Field<N>) -> Result<bool> {
92        self.vm.transition_store().contains_output_id(output_id)
93    }
94
95    /// Returns `true` if the given commitment exists.
96    pub fn contains_commitment(&self, commitment: &Field<N>) -> Result<bool> {
97        self.vm.transition_store().contains_commitment(commitment)
98    }
99
100    /// Returns `true` if the given checksum exists.
101    pub fn contains_checksum(&self, checksum: &Field<N>) -> bool {
102        self.vm.transition_store().contains_checksum(checksum)
103    }
104
105    /// Returns `true` if the given nonce exists.
106    pub fn contains_nonce(&self, nonce: &Group<N>) -> Result<bool> {
107        self.vm.transition_store().contains_nonce(nonce)
108    }
109
110    /* Metadata */
111
112    /// Returns `true` if the given transition public key exists.
113    pub fn contains_tpk(&self, tpk: &Group<N>) -> Result<bool> {
114        self.vm.transition_store().contains_tpk(tpk)
115    }
116
117    /// Returns `true` if the given transition commitment exists.
118    pub fn contains_tcm(&self, tcm: &Field<N>) -> Result<bool> {
119        self.vm.transition_store().contains_tcm(tcm)
120    }
121}