/ ledger / query / src / traits.rs
traits.rs
 1  // Copyright (c) 2019-2025 Alpha-Delta Network Inc.
 2  // This file is part of the alphavm 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  
16  use alphavm_console::{network::Network, prelude::Result, program::StatePath, types::Field};
17  
18  #[cfg_attr(feature = "async", async_trait::async_trait(?Send))]
19  pub trait QueryTrait<N: Network> {
20      /// Returns the current state root.
21      fn current_state_root(&self) -> Result<N::StateRoot>;
22  
23      /// Returns the current state root.
24      #[cfg(feature = "async")]
25      async fn current_state_root_async(&self) -> Result<N::StateRoot>;
26  
27      /// Returns a state path for the given `commitment`.
28      fn get_state_path_for_commitment(&self, commitment: &Field<N>) -> Result<StatePath<N>>;
29  
30      /// Returns a state path for the given `commitment`.
31      #[cfg(feature = "async")]
32      async fn get_state_path_for_commitment_async(&self, commitment: &Field<N>) -> Result<StatePath<N>>;
33  
34      /// Returns a list of state paths for the given list of `commitment`s.
35      fn get_state_paths_for_commitments(&self, commitments: &[Field<N>]) -> Result<Vec<StatePath<N>>>;
36  
37      /// Returns a list of state paths for the given list of `commitment`s.
38      #[cfg(feature = "async")]
39      async fn get_state_paths_for_commitments_async(&self, commitments: &[Field<N>]) -> Result<Vec<StatePath<N>>>;
40  
41      /// Returns the current block height
42      fn current_block_height(&self) -> Result<u32>;
43  
44      /// Returns the current block height
45      #[cfg(feature = "async")]
46      async fn current_block_height_async(&self) -> Result<u32>;
47  }