1use std::{any::Any, collections::BTreeMap};
6
7use async_trait::async_trait;
8
9use crate::{
10 errors::IndexerError,
11 handlers::{EpochToCommit, TransactionObjectChangesToCommit},
12 models::{
13 display::StoredDisplay,
14 event_indices::OptimisticEventIndices,
15 events::OptimisticEvent,
16 obj_indices::StoredObjectVersion,
17 objects::{StoredDeletedObject, StoredObject},
18 transactions::{OptimisticTransaction, TxInsertionOrder},
19 tx_indices::OptimisticTxIndices,
20 },
21 types::{
22 EventIndex, IndexedCheckpoint, IndexedEvent, IndexedPackage, IndexedTransaction, TxIndex,
23 },
24};
25
26#[expect(clippy::large_enum_variant)]
27pub enum ObjectsToCommit {
28 MutatedObject(StoredObject),
29 DeletedObject(StoredDeletedObject),
30}
31
32#[async_trait]
33pub trait IndexerStore: Any + Clone + Sync + Send + 'static {
34 async fn get_latest_checkpoint_sequence_number(&self) -> Result<Option<u64>, IndexerError>;
35
36 async fn get_available_epoch_range(&self) -> Result<(u64, u64), IndexerError>;
37
38 async fn get_available_checkpoint_range(&self) -> Result<(u64, u64), IndexerError>;
39
40 async fn get_latest_object_snapshot_checkpoint_sequence_number(
41 &self,
42 ) -> Result<Option<u64>, IndexerError>;
43
44 async fn get_chain_identifier(&self) -> Result<Option<Vec<u8>>, IndexerError>;
45
46 fn persist_protocol_configs_and_feature_flags(
47 &self,
48 chain_id: Vec<u8>,
49 ) -> Result<(), IndexerError>;
50
51 async fn persist_objects(
52 &self,
53 object_changes: Vec<TransactionObjectChangesToCommit>,
54 ) -> Result<(), IndexerError>;
55
56 async fn persist_object_history(
57 &self,
58 object_changes: Vec<TransactionObjectChangesToCommit>,
59 ) -> Result<(), IndexerError>;
60
61 async fn persist_object_versions(
62 &self,
63 object_versions: Vec<StoredObjectVersion>,
64 ) -> Result<(), IndexerError>;
65
66 async fn persist_objects_snapshot(
67 &self,
68 object_changes: Vec<TransactionObjectChangesToCommit>,
69 ) -> Result<(), IndexerError>;
70
71 async fn persist_checkpoints(
72 &self,
73 checkpoints: Vec<IndexedCheckpoint>,
74 ) -> Result<(), IndexerError>;
75
76 async fn persist_transactions(
77 &self,
78 transactions: Vec<IndexedTransaction>,
79 ) -> Result<(), IndexerError>;
80
81 async fn persist_optimistic_transaction(
82 &self,
83 transaction: OptimisticTransaction,
84 ) -> Result<(), IndexerError>;
85
86 async fn persist_tx_insertion_order(
87 &self,
88 tx_order: Vec<TxInsertionOrder>,
89 ) -> Result<(), IndexerError>;
90
91 async fn persist_tx_indices(&self, indices: Vec<TxIndex>) -> Result<(), IndexerError>;
92
93 async fn persist_optimistic_tx_indices(
94 &self,
95 indices: OptimisticTxIndices,
96 ) -> Result<(), IndexerError>;
97
98 async fn persist_events(&self, events: Vec<IndexedEvent>) -> Result<(), IndexerError>;
99
100 async fn persist_optimistic_events(
101 &self,
102 events: Vec<OptimisticEvent>,
103 ) -> Result<(), IndexerError>;
104
105 async fn persist_event_indices(
106 &self,
107 event_indices: Vec<EventIndex>,
108 ) -> Result<(), IndexerError>;
109
110 async fn persist_optimistic_event_indices(
111 &self,
112 indices: OptimisticEventIndices,
113 ) -> Result<(), IndexerError>;
114
115 async fn persist_displays(
116 &self,
117 display_updates: BTreeMap<String, StoredDisplay>,
118 ) -> Result<(), IndexerError>;
119
120 async fn persist_packages(&self, packages: Vec<IndexedPackage>) -> Result<(), IndexerError>;
121
122 async fn persist_epoch(&self, epoch: EpochToCommit) -> Result<(), IndexerError>;
123
124 async fn advance_epoch(&self, epoch: EpochToCommit) -> Result<(), IndexerError>;
125
126 async fn prune_epoch(&self, epoch: u64) -> Result<(), IndexerError>;
127
128 async fn get_network_total_transactions_by_end_of_epoch(
129 &self,
130 epoch: u64,
131 ) -> Result<u64, IndexerError>;
132
133 async fn refresh_participation_metrics(&self) -> Result<(), IndexerError>;
134
135 fn as_any(&self) -> &dyn Any;
136}