grid_sdk/commits/store/
mod.rs1#[cfg(feature = "diesel")]
16pub(in crate) mod diesel;
17mod error;
18
19#[cfg(feature = "diesel")]
20pub use self::diesel::{DieselCommitStore, DieselConnectionCommitStore};
21pub use error::CommitStoreError;
22
23#[derive(Clone, Debug, Serialize, PartialEq)]
25pub struct Commit {
26 pub commit_id: String,
27 pub commit_num: i64,
28 pub service_id: Option<String>,
29}
30
31#[derive(Clone, Debug, Serialize, PartialEq)]
32pub struct ChainRecord {
33 pub start_commit_num: i64,
34 pub end_commit_num: i64,
35 pub service_id: Option<String>,
36}
37
38#[derive(Clone, Eq, PartialEq)]
40pub enum StateChange {
41 Set { key: String, value: Vec<u8> },
42 Delete { key: String },
43}
44
45#[derive(Clone)]
47pub struct CommitEvent {
48 pub service_id: Option<String>,
50 pub id: String,
52 pub height: Option<u64>,
55 pub state_changes: Vec<StateChange>,
57}
58
59pub trait CommitStore {
60 fn add_commit(&self, commit: Commit) -> Result<(), CommitStoreError>;
66
67 fn get_commit_by_commit_num(&self, commit_num: i64)
73 -> Result<Option<Commit>, CommitStoreError>;
74
75 fn get_current_commit_id(&self) -> Result<Option<String>, CommitStoreError>;
77
78 fn get_current_service_commits(&self) -> Result<Vec<Commit>, CommitStoreError>;
83
84 fn get_next_commit_num(&self) -> Result<i64, CommitStoreError>;
86
87 fn resolve_fork(&self, commit_num: i64) -> Result<(), CommitStoreError>;
93
94 fn create_db_commit_from_commit_event(
100 &self,
101 event: &CommitEvent,
102 ) -> Result<Option<Commit>, CommitStoreError>;
103}
104
105impl<CS> CommitStore for Box<CS>
106where
107 CS: CommitStore + ?Sized,
108{
109 fn add_commit(&self, commit: Commit) -> Result<(), CommitStoreError> {
110 (**self).add_commit(commit)
111 }
112
113 fn get_commit_by_commit_num(
114 &self,
115 commit_num: i64,
116 ) -> Result<Option<Commit>, CommitStoreError> {
117 (**self).get_commit_by_commit_num(commit_num)
118 }
119
120 fn get_current_commit_id(&self) -> Result<Option<String>, CommitStoreError> {
121 (**self).get_current_commit_id()
122 }
123
124 fn get_current_service_commits(&self) -> Result<Vec<Commit>, CommitStoreError> {
125 (**self).get_current_service_commits()
126 }
127
128 fn get_next_commit_num(&self) -> Result<i64, CommitStoreError> {
129 (**self).get_next_commit_num()
130 }
131
132 fn resolve_fork(&self, commit_num: i64) -> Result<(), CommitStoreError> {
133 (**self).resolve_fork(commit_num)
134 }
135
136 fn create_db_commit_from_commit_event(
137 &self,
138 event: &CommitEvent,
139 ) -> Result<Option<Commit>, CommitStoreError> {
140 (**self).create_db_commit_from_commit_event(event)
141 }
142}