kona_derive/types/
signals.rsuse op_alloy_genesis::SystemConfig;
use op_alloy_protocol::{BlockInfo, L2BlockInfo};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(clippy::large_enum_variant)]
pub enum Signal {
Reset(ResetSignal),
Activation(ActivationSignal),
FlushChannel,
}
impl Signal {
pub const fn with_system_config(self, system_config: SystemConfig) -> Self {
match self {
Self::Reset(reset) => reset.with_system_config(system_config).signal(),
Self::Activation(activation) => activation.with_system_config(system_config).signal(),
Self::FlushChannel => Self::FlushChannel,
}
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct ResetSignal {
pub l2_safe_head: L2BlockInfo,
pub l1_origin: BlockInfo,
pub system_config: Option<SystemConfig>,
}
impl ResetSignal {
pub const fn signal(self) -> Signal {
Signal::Reset(self)
}
pub const fn with_system_config(self, system_config: SystemConfig) -> Self {
Self { system_config: Some(system_config), ..self }
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct ActivationSignal {
pub l2_safe_head: L2BlockInfo,
pub l1_origin: BlockInfo,
pub system_config: Option<SystemConfig>,
}
impl ActivationSignal {
pub const fn signal(self) -> Signal {
Signal::Activation(self)
}
pub const fn with_system_config(self, system_config: SystemConfig) -> Self {
Self { system_config: Some(system_config), ..self }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_reset_signal() {
let signal = ResetSignal::default();
assert_eq!(signal.signal(), Signal::Reset(signal));
}
#[test]
fn test_activation_signal() {
let signal = ActivationSignal::default();
assert_eq!(signal.signal(), Signal::Activation(signal));
}
#[test]
fn test_signal_with_system_config() {
let signal = ResetSignal::default();
let system_config = SystemConfig::default();
assert_eq!(
signal.with_system_config(system_config).signal(),
Signal::Reset(ResetSignal { system_config: Some(system_config), ..signal })
);
let signal = ActivationSignal::default();
let system_config = SystemConfig::default();
assert_eq!(
signal.with_system_config(system_config).signal(),
Signal::Activation(ActivationSignal { system_config: Some(system_config), ..signal })
);
assert_eq!(Signal::FlushChannel.with_system_config(system_config), Signal::FlushChannel);
}
}