use blueprint_client_tangle::TangleEvent;
use blueprint_runner::config::{Protocol, ProtocolSettings};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ProtocolType {
Tangle,
Eigenlayer,
}
impl From<Protocol> for ProtocolType {
fn from(protocol: Protocol) -> Self {
match protocol {
Protocol::Tangle => ProtocolType::Tangle,
Protocol::Eigenlayer => ProtocolType::Eigenlayer,
_ => unreachable!("Protocol not supported"),
}
}
}
impl From<ProtocolType> for Protocol {
fn from(protocol_type: ProtocolType) -> Self {
match protocol_type {
ProtocolType::Tangle => Protocol::Tangle,
ProtocolType::Eigenlayer => Protocol::Eigenlayer,
}
}
}
impl From<&ProtocolSettings> for ProtocolType {
fn from(settings: &ProtocolSettings) -> Self {
match settings {
ProtocolSettings::Eigenlayer(_) => ProtocolType::Eigenlayer,
_ => ProtocolType::Tangle,
}
}
}
#[derive(Debug, Clone)]
pub enum ProtocolEvent {
Tangle(TangleProtocolEvent),
Eigenlayer(EigenlayerProtocolEvent),
}
#[derive(Debug, Clone)]
pub struct TangleProtocolEvent {
pub block_number: u64,
pub block_hash: alloy_primitives::B256,
pub timestamp: u64,
pub logs: Vec<alloy_rpc_types::Log>,
pub inner: TangleEvent,
}
#[derive(Debug, Clone)]
pub struct EigenlayerProtocolEvent {
pub block_number: u64,
pub block_hash: Vec<u8>,
pub logs: Vec<alloy_rpc_types::Log>,
}
impl ProtocolEvent {
#[must_use]
pub fn as_tangle(&self) -> Option<&TangleProtocolEvent> {
match self {
ProtocolEvent::Tangle(evt) => Some(evt),
_ => None,
}
}
#[must_use]
pub fn as_eigenlayer(&self) -> Option<&EigenlayerProtocolEvent> {
match self {
ProtocolEvent::Eigenlayer(evt) => Some(evt),
_ => None,
}
}
#[must_use]
pub fn block_number(&self) -> u64 {
match self {
ProtocolEvent::Tangle(evt) => evt.block_number,
ProtocolEvent::Eigenlayer(evt) => evt.block_number,
}
}
}