1use crate::{
2 database::database_description::DatabaseDescription,
3 state::{
4 generic_database::GenericDatabase,
5 iterable_key_value_view::IterableKeyValueViewWrapper,
6 key_value_view::KeyValueViewWrapper,
7 },
8};
9use fuel_core_storage::{
10 Result as StorageResult,
11 iter::{
12 IterDirection,
13 IterableStore,
14 },
15 kv_store::StorageColumn,
16 transactional::StorageChanges,
17};
18use std::fmt::Debug;
19
20pub mod data_source;
21pub mod generic_database;
22#[cfg(feature = "rocksdb")]
23pub mod historical_rocksdb;
24pub mod in_memory;
25pub mod iterable_key_value_view;
26pub mod key_value_view;
27#[cfg(feature = "rocksdb")]
28pub mod rocks_db;
29#[cfg(feature = "rocksdb")]
30pub mod rocks_db_key_iterator;
31
32pub type ColumnType<Description> = <Description as DatabaseDescription>::Column;
33pub type HeightType<Description> = <Description as DatabaseDescription>::Height;
34
35pub type IterableKeyValueView<Column, BlockHeight> =
37 GenericDatabase<IterableKeyValueViewWrapper<Column>, BlockHeight>;
38
39pub type KeyValueView<Column, BlockHeight> =
41 GenericDatabase<KeyValueViewWrapper<Column>, BlockHeight>;
42
43impl<Column, Height> IterableKeyValueView<Column, Height>
44where
45 Column: StorageColumn + 'static,
46{
47 pub fn into_key_value_view(self) -> KeyValueView<Column, Height> {
49 let (iterable, metadata) = self.into_inner();
50 let storage = KeyValueViewWrapper::new(iterable);
51 KeyValueView::from_storage_and_metadata(storage, metadata)
52 }
53}
54
55pub trait TransactableStorage<Height>: IterableStore + Debug + Send + Sync {
56 fn commit_changes(
58 &self,
59 height: Option<Height>,
60 changes: StorageChanges,
61 ) -> StorageResult<()>;
62
63 fn view_at_height(
64 &self,
65 height: &Height,
66 ) -> StorageResult<KeyValueView<Self::Column, Height>>;
67
68 fn latest_view(&self) -> StorageResult<IterableKeyValueView<Self::Column, Height>>;
69
70 fn rollback_block_to(&self, height: &Height) -> StorageResult<()>;
71
72 fn shutdown(&self) {
73 }
75}
76
77#[cfg(feature = "test-helpers")]
79impl<Height, S> TransactableStorage<Height>
80 for fuel_core_storage::transactional::StorageTransaction<S>
81where
82 S: IterableStore + Debug + Send + Sync,
83{
84 fn commit_changes(&self, _: Option<Height>, _: StorageChanges) -> StorageResult<()> {
85 unimplemented!()
86 }
87
88 fn view_at_height(
89 &self,
90 _: &Height,
91 ) -> StorageResult<KeyValueView<Self::Column, Height>> {
92 unimplemented!()
93 }
94
95 fn latest_view(&self) -> StorageResult<IterableKeyValueView<Self::Column, Height>> {
96 unimplemented!()
97 }
98 fn rollback_block_to(&self, _: &Height) -> StorageResult<()> {
99 unimplemented!()
100 }
101}