mithril_aggregator/database/repository/
single_signature_repository.rs1use std::sync::Arc;
2
3use mithril_common::entities::SingleSignatures;
4use mithril_common::StdResult;
5use mithril_persistence::sqlite::{ConnectionExtensions, SqliteConnection};
6
7use crate::database::query::UpdateSingleSignatureRecordQuery;
8use crate::database::record::{OpenMessageRecord, SingleSignatureRecord};
9
10pub struct SingleSignatureRepository {
12 connection: Arc<SqliteConnection>,
13}
14
15impl SingleSignatureRepository {
16 pub fn new(connection: Arc<SqliteConnection>) -> Self {
18 Self { connection }
19 }
20
21 pub async fn create_single_signature(
23 &self,
24 single_signature: &SingleSignatures,
25 open_message: &OpenMessageRecord,
26 ) -> StdResult<SingleSignatureRecord> {
27 let single_signature = SingleSignatureRecord::try_from_single_signatures(
28 single_signature,
29 &open_message.open_message_id,
30 open_message.epoch.offset_to_signer_retrieval_epoch()?,
31 )?;
32 let record = self.connection.fetch_first(UpdateSingleSignatureRecordQuery::one(single_signature.clone()))?
33 .unwrap_or_else(|| {
34 panic!(
35 "No entity returned by the persister, single_signature_record = {single_signature:?}"
36 )
37 }) ;
38
39 Ok(record)
40 }
41}