-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2126 from input-output-hk/sfa/2118/get_rid_of_sto…
…re_adpater_in_signer Get rid of store adapter in signer
- Loading branch information
Showing
35 changed files
with
1,590 additions
and
546 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ pub mod record; | |
pub mod repository; | ||
#[cfg(test)] | ||
pub(crate) mod test_helper; | ||
#[cfg(test)] | ||
pub(crate) mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
//! Signer related database queries | ||
|
||
mod protocol_initializer; | ||
mod signed_beacon; | ||
mod stake_pool; | ||
|
||
pub use protocol_initializer::*; | ||
pub use signed_beacon::*; | ||
pub use stake_pool::*; |
42 changes: 42 additions & 0 deletions
42
mithril-signer/src/database/query/protocol_initializer/delete_protocol_initializer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use sqlite::Value; | ||
|
||
use mithril_common::entities::Epoch; | ||
use mithril_persistence::sqlite::{Query, SourceAlias, SqLiteEntity, WhereCondition}; | ||
|
||
use crate::database::record::ProtocolInitializerRecord; | ||
|
||
/// Query to delete old [ProtocolInitializer] from the sqlite database | ||
pub struct DeleteProtocolInitializerQuery { | ||
condition: WhereCondition, | ||
} | ||
|
||
impl Query for DeleteProtocolInitializerQuery { | ||
type Entity = ProtocolInitializerRecord; | ||
|
||
fn filters(&self) -> WhereCondition { | ||
self.condition.clone() | ||
} | ||
|
||
fn get_definition(&self, condition: &str) -> String { | ||
// it is important to alias the fields with the same name as the table | ||
// since the table cannot be aliased in a RETURNING statement in SQLite. | ||
let projection = Self::Entity::get_projection().expand(SourceAlias::new(&[( | ||
"{:protocol_initializer:}", | ||
"protocol_initializer", | ||
)])); | ||
|
||
format!("delete from protocol_initializer where {condition} returning {projection}") | ||
} | ||
} | ||
|
||
impl DeleteProtocolInitializerQuery { | ||
/// Create the SQL query to prune data older than the given Epoch. | ||
pub fn below_epoch_threshold(epoch_threshold: Epoch) -> Self { | ||
let condition = WhereCondition::new( | ||
"epoch < ?*", | ||
vec![Value::Integer(epoch_threshold.try_into().unwrap())], | ||
); | ||
|
||
Self { condition } | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
mithril-signer/src/database/query/protocol_initializer/get_protocol_initializer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use sqlite::Value; | ||
|
||
use mithril_common::entities::Epoch; | ||
use mithril_persistence::sqlite::{Query, SourceAlias, SqLiteEntity, WhereCondition}; | ||
|
||
use crate::database::record::ProtocolInitializerRecord; | ||
|
||
/// Simple queries to retrieve [ProtocolInitializer] from the sqlite database. | ||
pub struct GetProtocolInitializerQuery { | ||
condition: WhereCondition, | ||
limit: Option<usize>, | ||
} | ||
|
||
impl GetProtocolInitializerQuery { | ||
/// Get protocol initializer that match the epoch. | ||
pub fn for_epoch(epoch: Epoch) -> Self { | ||
let epoch_i64: i64 = epoch.try_into().unwrap(); | ||
let condition = WhereCondition::new( | ||
"protocol_initializer.epoch = ?", | ||
vec![Value::Integer(epoch_i64)], | ||
); | ||
|
||
Self { | ||
condition, | ||
limit: None, | ||
} | ||
} | ||
|
||
pub fn last_n(limit: usize) -> Self { | ||
let condition = WhereCondition::default(); | ||
Self { | ||
condition, | ||
limit: Some(limit), | ||
} | ||
} | ||
} | ||
|
||
impl Query for GetProtocolInitializerQuery { | ||
type Entity = ProtocolInitializerRecord; | ||
|
||
fn filters(&self) -> WhereCondition { | ||
self.condition.clone() | ||
} | ||
|
||
fn get_definition(&self, condition: &str) -> String { | ||
let aliases = SourceAlias::new(&[("{:protocol_initializer:}", "protocol_initializer")]); | ||
let projection = Self::Entity::get_projection().expand(aliases); | ||
let limit = self | ||
.limit | ||
.map_or("".to_string(), |limit| format!(" limit {}", limit)); | ||
format!("select {projection} from protocol_initializer where {condition} order by rowid desc{limit}") | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
mithril-signer/src/database/query/protocol_initializer/insert_protocol_initializer.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use sqlite::Value; | ||
|
||
use mithril_common::StdResult; | ||
use mithril_persistence::sqlite::{Query, SourceAlias, SqLiteEntity, WhereCondition}; | ||
|
||
use crate::database::record::ProtocolInitializerRecord; | ||
|
||
/// Query to insert or replace [ProtocolInitializerRecord] in the sqlite database | ||
pub struct InsertOrReplaceProtocolInitializerQuery { | ||
condition: WhereCondition, | ||
} | ||
|
||
impl InsertOrReplaceProtocolInitializerQuery { | ||
pub fn one(record: ProtocolInitializerRecord) -> StdResult<Self> { | ||
let value = serde_json::to_string(&record.protocol_initializer).unwrap(); | ||
let condition = WhereCondition::new( | ||
"(epoch, protocol, created_at) values (?*, ?*, ?*)", | ||
vec![ | ||
Value::Integer(record.epoch.try_into()?), | ||
Value::String(value), | ||
Value::String(record.created_at.to_rfc3339()), | ||
], | ||
); | ||
|
||
Ok(Self { condition }) | ||
} | ||
} | ||
|
||
impl Query for InsertOrReplaceProtocolInitializerQuery { | ||
type Entity = ProtocolInitializerRecord; | ||
|
||
fn filters(&self) -> WhereCondition { | ||
self.condition.clone() | ||
} | ||
|
||
fn get_definition(&self, condition: &str) -> String { | ||
// it is important to alias the fields with the same name as the table | ||
// since the table cannot be aliased in a RETURNING statement in SQLite. | ||
let projection = Self::Entity::get_projection().expand(SourceAlias::new(&[( | ||
"{:protocol_initializer:}", | ||
"protocol_initializer", | ||
)])); | ||
|
||
format!("insert or replace into protocol_initializer {condition} returning {projection}") | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
mithril-signer/src/database/query/protocol_initializer/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod delete_protocol_initializer; | ||
mod get_protocol_initializer; | ||
mod insert_protocol_initializer; | ||
|
||
pub use delete_protocol_initializer::*; | ||
pub use get_protocol_initializer::*; | ||
pub use insert_protocol_initializer::*; |
Oops, something went wrong.