Skip to content

Commit

Permalink
refactor: move BeaconToSign to entities module in signer
Browse files Browse the repository at this point in the history
  • Loading branch information
Alenar committed Oct 1, 2024
1 parent 701bc8c commit 376358c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 27 deletions.
2 changes: 1 addition & 1 deletion mithril-signer/src/database/record/signed_beacon_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mithril_common::entities::{Epoch, SignedEntityType};
use mithril_persistence::database::Hydrator;
use mithril_persistence::sqlite::{HydrationError, Projection, SqLiteEntity};

use crate::services::BeaconToSign;
use crate::entities::BeaconToSign;

/// Database record of a beacon signed by the signer
#[derive(Debug, Clone, PartialEq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::database::query::{
DeleteSignedBeaconRecordQuery, GetSignedBeaconQuery, InsertSignedBeaconRecordQuery,
};
use crate::database::record::SignedBeaconRecord;
use crate::services::{BeaconToSign, EpochPruningTask, SignedBeaconStore};
use crate::entities::BeaconToSign;
use crate::services::{EpochPruningTask, SignedBeaconStore};

/// A [SignedBeaconStore] implementation using SQLite.
pub struct SignedBeaconRepository {
Expand Down
31 changes: 31 additions & 0 deletions mithril-signer/src/entities/beacon_to_sign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use chrono::{DateTime, Utc};

use mithril_common::entities::{Epoch, SignedEntityType};

/// Beacon to sign
#[derive(Debug, Clone, PartialEq)]
pub struct BeaconToSign {
/// The epoch when the beacon was issued
pub epoch: Epoch,

/// The signed entity type to sign
pub signed_entity_type: SignedEntityType,

/// Datetime when the beacon was initiated
pub initiated_at: DateTime<Utc>,
}

impl BeaconToSign {
/// Create a new `BeaconToSign`
pub fn new(
epoch: Epoch,
signed_entity_type: SignedEntityType,
initiated_at: DateTime<Utc>,
) -> Self {
Self {
epoch,
signed_entity_type,
initiated_at,
}
}
}
2 changes: 2 additions & 0 deletions mithril-signer/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
//! This module provide domain entities for the services & state machine.

mod beacon_to_sign;
mod signer_epoch_settings;

pub use beacon_to_sign::*;
pub use signer_epoch_settings::*;
4 changes: 2 additions & 2 deletions mithril-signer/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use mithril_common::StdResult;
use mithril_persistence::store::StakeStorer;

use crate::dependency_injection::SignerDependencyContainer;
use crate::entities::SignerEpochSettings;
use crate::services::{BeaconToSign, EpochService, MithrilProtocolInitializerBuilder};
use crate::entities::{BeaconToSign, SignerEpochSettings};
use crate::services::{EpochService, MithrilProtocolInitializerBuilder};
use crate::Configuration;

/// This trait is mainly intended for mocking.
Expand Down
5 changes: 2 additions & 3 deletions mithril-signer/src/runtime/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use mithril_common::{
entities::{Epoch, SignedEntityType, TimePoint},
};

use crate::services::BeaconToSign;
use crate::{entities::SignerEpochSettings, MetricsService};
use crate::entities::{BeaconToSign, SignerEpochSettings};
use crate::MetricsService;

use super::{Runner, RuntimeError};

Expand Down Expand Up @@ -498,7 +498,6 @@ mod tests {
use mithril_common::test_utils::fake_data;

use crate::runtime::runner::MockSignerRunner;
use crate::services::BeaconToSign;

use super::*;

Expand Down
26 changes: 6 additions & 20 deletions mithril-signer/src/services/certifier.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use chrono::Utc;
use std::sync::Arc;

use mithril_common::entities::{Epoch, SignedEntityConfig, SignedEntityType, TimePoint};
use mithril_common::entities::{SignedEntityConfig, SignedEntityType, TimePoint};
use mithril_common::signed_entity_type_lock::SignedEntityTypeLock;
use mithril_common::{StdResult, TickerService};

/// Beacon to sign
#[derive(Debug, Clone, PartialEq)]
pub struct BeaconToSign {
/// The epoch when the beacon was issued
pub epoch: Epoch,

/// The signed entity type to sign
pub signed_entity_type: SignedEntityType,

/// Datetime when the beacon was initiated
pub initiated_at: DateTime<Utc>,
}
use crate::entities::BeaconToSign;

/// Certifier Service
///
Expand Down Expand Up @@ -114,11 +103,8 @@ impl CertifierService for SignerCertifierService {
Ok(None)
} else {
let signed_entity_type = available_signed_entity_types[0].clone();
let beacon_to_sign = BeaconToSign {
epoch: time_point.epoch,
signed_entity_type,
initiated_at: Utc::now(),
};
let beacon_to_sign =
BeaconToSign::new(time_point.epoch, signed_entity_type, Utc::now());

Ok(Some(beacon_to_sign))
}
Expand All @@ -134,7 +120,7 @@ impl CertifierService for SignerCertifierService {
#[cfg(test)]
mod tests {
use mithril_common::entities::{
CardanoTransactionsSigningConfig, ChainPoint, SignedEntityTypeDiscriminants,
CardanoTransactionsSigningConfig, ChainPoint, Epoch, SignedEntityTypeDiscriminants,
};

use super::{tests::tests_tooling::*, *};
Expand Down

0 comments on commit 376358c

Please sign in to comment.