Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Feb 20, 2023
1 parent b32fecc commit 20c9216
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 58 deletions.
52 changes: 20 additions & 32 deletions mithril-aggregator/src/command_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ use mithril_common::{
};

use crate::{
configuration::EraConfiguration,
event_store::{self, TransmitterService},
tools::{EraTools, EraToolsDependency, GenesisTools, GenesisToolsDependency},
tools::{EraTools, GenesisTools, GenesisToolsDependency},
AggregatorConfig, AggregatorRunner, AggregatorRuntime, CertificatePendingStore,
CertificateStore, Configuration, DefaultConfiguration, DependencyManager, GenesisConfiguration,
GzipSnapshotter, MithrilSignerRegisterer, MultiSignerImpl, ProtocolParametersStore,
Expand Down Expand Up @@ -104,16 +103,6 @@ fn setup_genesis_dependencies(
Ok(dependencies)
}

fn setup_era_dependencies(
_config: &EraConfiguration,
) -> Result<EraToolsDependency, Box<dyn std::error::Error>> {
let dependencies = EraToolsDependency {
era_markers_verifier: None,
};

Ok(dependencies)
}

async fn do_first_launch_initialization_if_needed(
chain_observer: Arc<dyn ChainObserver>,
protocol_parameters_store: Arc<ProtocolParametersStore>,
Expand Down Expand Up @@ -707,22 +696,27 @@ impl EraSubCommand {

/// Era list command
#[derive(Parser, Debug, Clone)]
pub struct ListEraSubCommand {}
pub struct ListEraSubCommand {
/// Enable JSON output.
#[clap(long)]
json: bool,
}

impl ListEraSubCommand {
pub async fn execute(
&self,
config_builder: ConfigBuilder<DefaultState>,
_config_builder: ConfigBuilder<DefaultState>,
) -> Result<(), Box<dyn Error>> {
let config: EraConfiguration = config_builder
.build()
.map_err(|e| format!("configuration build error: {e}"))?
.try_deserialize()
.map_err(|e| format!("configuration deserialize error: {e}"))?;
debug!("LIST ERA command"; "config" => format!("{config:?}"));
let dependencies = setup_era_dependencies(&config)?;
let era_tools = EraTools::from_dependencies(dependencies).await?;
print!("{}", era_tools.get_supported_eras_list()?);
debug!("LIST ERA command");
let era_tools = EraTools::new();
let eras = era_tools.get_supported_eras_list()?;

if self.json {
println!("{}", serde_json::to_string(&eras)?);
} else {
println!("Supported Eras:");
println!("{eras:#?}");
}

Ok(())
}
Expand All @@ -747,16 +741,10 @@ pub struct GenerateTxDatumEraSubCommand {
impl GenerateTxDatumEraSubCommand {
pub async fn execute(
&self,
config_builder: ConfigBuilder<DefaultState>,
_config_builder: ConfigBuilder<DefaultState>,
) -> Result<(), Box<dyn Error>> {
let config: EraConfiguration = config_builder
.build()
.map_err(|e| format!("configuration build error: {e}"))?
.try_deserialize()
.map_err(|e| format!("configuration deserialize error: {e}"))?;
debug!("GENERATE TXDATUM ERA command"; "config" => format!("{config:?}"));
let dependencies = setup_era_dependencies(&config)?;
let era_tools = EraTools::from_dependencies(dependencies).await?;
debug!("GENERATETXDATUM ERA command");
let era_tools = EraTools::new();

let era_markers_secret_key = key_decode_hex(&self.era_markers_secret_key)?;
let era_markers_signer = EraMarkersSigner::from_secret_key(era_markers_secret_key);
Expand Down
7 changes: 0 additions & 7 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,6 @@ impl GenesisConfiguration {
}
}

/// Configuration expected for Era commands.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EraConfiguration {
/// Era markers verification key
pub era_markers_verification_key: Option<String>,
}

/// Default configuration with all the default values for configurations.
#[derive(Debug, Clone)]
pub struct DefaultConfiguration {
Expand Down
24 changes: 6 additions & 18 deletions mithril-aggregator/src/tools/era.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
use std::{error::Error, sync::Arc};
use std::error::Error;

use mithril_common::{
chain_observer::{TxDatumBuilder, TxDatumFieldValue},
crypto_helper::{key_encode_hex, EraMarkersSigner, EraMarkersVerifier},
crypto_helper::{key_encode_hex, EraMarkersSigner},
entities::Epoch,
era::{adapters::EraMarkersPayloadCardanoChain, EraMarker, SupportedEra},
};

type EraToolsResult<R> = Result<R, Box<dyn Error>>;

pub struct EraToolsDependency {
/// Era markers signature verifier service.
pub era_markers_verifier: Option<Arc<EraMarkersVerifier>>,
}

pub struct EraTools {}

impl EraTools {
pub fn new() -> Self {
Self {}
}

pub async fn from_dependencies(_dependencies: EraToolsDependency) -> EraToolsResult<Self> {
Ok(Self::new())
}

/// Get list of supported eras
pub fn get_supported_eras_list(&self) -> EraToolsResult<String> {
Ok(serde_json::to_string(&SupportedEra::eras())?)
pub fn get_supported_eras_list(&self) -> EraToolsResult<Vec<SupportedEra>> {
Ok(SupportedEra::eras())
}

/// Generate TxDatum for eras
/// Generate TxDatum for eras with sanity check of epochs
pub fn generate_tx_datum(
&self,
current_era_epoch: Epoch,
Expand Down Expand Up @@ -78,12 +69,9 @@ mod tests {
#[test]
fn get_supported_eras_list() {
let era_tools = build_tools();
let supported_eras_list_serialized = era_tools
let supported_eras_list = era_tools
.get_supported_eras_list()
.expect("get_supported_eras_list should not fail");
let supported_eras_list: Vec<SupportedEra> =
serde_json::from_str(&supported_eras_list_serialized)
.expect("supported_eras_list_serialized should be a valid JSON");
assert_eq!(supported_eras_list, SupportedEra::eras());
}

Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod genesis;
mod remote_file_uploader;

pub use digest_helpers::extract_digest_from_path;
pub use era::{EraTools, EraToolsDependency};
pub use era::EraTools;
pub use genesis::{GenesisTools, GenesisToolsDependency};
pub use remote_file_uploader::{GcpFileUploader, RemoteFileUploader};

Expand Down

0 comments on commit 20c9216

Please sign in to comment.