Skip to content

Commit

Permalink
chore: pass enum variants in stages instead of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Oct 23, 2023
1 parent 2be4154 commit 36f14aa
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
4 changes: 3 additions & 1 deletion crates/primitives/src/components/challenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use serde::{Deserialize, Serialize};
use strum::EnumIter;

/// Challenger Agent Implementations
#[derive(Default, Clone, PartialEq, EnumVariantsStrings, Deserialize, Serialize, EnumIter)]
#[derive(
Default, Copy, Clone, PartialEq, EnumVariantsStrings, Deserialize, Serialize, EnumIter,
)]
#[serde(rename_all = "kebab-case")]
#[enum_variants_strings_transform(transform = "kebab_case")]
pub enum ChallengerAgent {
Expand Down
4 changes: 3 additions & 1 deletion crates/primitives/src/components/layer_two.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use strum::EnumIter;
/// The OP Stack L2 client is a minimally modified version of the L1 client
/// that supports deposit transactions as well as a few other small OP-specific
/// changes.
#[derive(Default, Clone, PartialEq, EnumVariantsStrings, Deserialize, Serialize, EnumIter)]
#[derive(
Default, Copy, Clone, PartialEq, EnumVariantsStrings, Deserialize, Serialize, EnumIter,
)]
#[serde(rename_all = "kebab-case")]
#[enum_variants_strings_transform(transform = "kebab_case")]
pub enum L2Client {
Expand Down
4 changes: 3 additions & 1 deletion crates/primitives/src/components/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use strum::EnumIter;
///
/// The OP Stack rollup client performs the derivation of the rollup state
/// from the L1 and L2 clients.
#[derive(Default, Clone, PartialEq, EnumVariantsStrings, Deserialize, Serialize, EnumIter)]
#[derive(
Default, Copy, Clone, PartialEq, EnumVariantsStrings, Deserialize, Serialize, EnumIter,
)]
#[serde(rename_all = "kebab-case")]
#[enum_variants_strings_transform(transform = "kebab_case")]
pub enum RollupClient {
Expand Down
6 changes: 3 additions & 3 deletions crates/stages/src/stages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ impl Stages<'_> {
Box::new(contracts::Contracts::new()),
Box::new(l2_exec::Executor::new(
self.config.l2_client_port,
self.config.l2_client.to_string(),
self.config.l2_client,
)),
Box::new(rollup::Rollup::new(
self.config.rollup_client_port,
self.config.rollup_client.to_string(),
self.config.rollup_client,
)),
Box::new(proposer::Proposer::new(Arc::clone(&artifacts))),
Box::new(batcher::Batcher::new(
Expand All @@ -104,7 +104,7 @@ impl Stages<'_> {
)),
Box::new(challenger::Challenger::new(
Arc::clone(&artifacts),
self.config.challenger.to_string(),
self.config.challenger,
)),
Box::new(stateviz::Stateviz::new(Arc::clone(&artifacts))),
]
Expand Down
8 changes: 4 additions & 4 deletions crates/stages/src/stages/challenger.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use async_trait::async_trait;
use eyre::Result;
use op_primitives::Artifacts;
use op_primitives::{Artifacts, ChallengerAgent};
use std::process::Command;
use std::sync::Arc;

/// Challenger Stage
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Challenger {
artifacts: Arc<Artifacts>,
challenger: String,
challenger: ChallengerAgent,
}

#[async_trait]
Expand All @@ -30,7 +30,7 @@ impl crate::Stage for Challenger {
.env("PWD", &docker_dir)
.env("L2OO_ADDRESS", addresses["L2OutputOracleProxy"].to_string())
.env("DGF_ADDRESS", addresses["DisputeGameFactory"].to_string())
.env("CHALLENGER_AGENT_CHOICE", &self.challenger)
.env("CHALLENGER_AGENT_CHOICE", &self.challenger.to_string())
.current_dir(docker_dir)
.output()?;

Expand All @@ -48,7 +48,7 @@ impl crate::Stage for Challenger {

impl Challenger {
/// Creates a new challenger stage.
pub fn new(artifacts: Arc<Artifacts>, challenger: String) -> Self {
pub fn new(artifacts: Arc<Artifacts>, challenger: ChallengerAgent) -> Self {
Self {
artifacts,
challenger,
Expand Down
7 changes: 4 additions & 3 deletions crates/stages/src/stages/l2_exec.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use async_trait::async_trait;
use eyre::Result;
use op_primitives::L2Client;
use std::process::Command;

/// Layer 2 Execution Client Stage
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Executor {
l2_port: Option<u16>,
l2_client: String,
l2_client: L2Client,
}

#[async_trait]
Expand All @@ -23,7 +24,7 @@ impl crate::Stage for Executor {
let start_l2 = Command::new("docker-compose")
.args(["up", "-d", "--no-deps", "--build", "l2"])
.env("PWD", &docker_dir)
.env("L2_CLIENT_CHOICE", &self.l2_client)
.env("L2_CLIENT_CHOICE", &self.l2_client.to_string())
.current_dir(docker_dir)
.output()?;

Expand All @@ -41,7 +42,7 @@ impl crate::Stage for Executor {

impl Executor {
/// Creates a new stage.
pub fn new(l2_port: Option<u16>, l2_client: String) -> Self {
pub fn new(l2_port: Option<u16>, l2_client: L2Client) -> Self {
Self { l2_port, l2_client }
}
}
7 changes: 4 additions & 3 deletions crates/stages/src/stages/rollup.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use async_trait::async_trait;
use eyre::Result;
use op_primitives::RollupClient;
use std::process::Command;

/// Rollup Stage
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Rollup {
rollup_port: Option<u16>,
rollup_client: String,
rollup_client: RollupClient,
}

#[async_trait]
Expand All @@ -24,7 +25,7 @@ impl crate::Stage for Rollup {
let start_rollup = Command::new("docker-compose")
.args(["up", "-d", "--no-deps", "--build", "rollup-client"])
.env("PWD", &docker_dir)
.env("ROLLUP_CLIENT_CHOICE", &self.rollup_client)
.env("ROLLUP_CLIENT_CHOICE", &self.rollup_client.to_string())
.current_dir(docker_dir)
.output()?;

Expand All @@ -42,7 +43,7 @@ impl crate::Stage for Rollup {

impl Rollup {
/// Creates a new stage.
pub fn new(rollup_port: Option<u16>, rollup_client: String) -> Self {
pub fn new(rollup_port: Option<u16>, rollup_client: RollupClient) -> Self {
Self {
rollup_port,
rollup_client,
Expand Down

0 comments on commit 36f14aa

Please sign in to comment.