use anyhow::Result;
use std::any::Any;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum BroadcastEventKind {
MappingUpdate,
StakingReward,
}
#[derive(Copy, Clone, Debug)]
pub enum BroadcastEvent<'a> {
MappingUpdate { program_id: &'a [u8], mapping_name: &'a [u8], key: &'a [u8], value: &'a [u8], block_height: u32 },
StakingReward { staker: &'a [u8], validator: &'a [u8], reward: u64, new_stake: u64, block_height: u32 },
}
impl BroadcastEvent<'_> {
pub fn kind(&self) -> BroadcastEventKind {
match self {
BroadcastEvent::MappingUpdate { .. } => BroadcastEventKind::MappingUpdate,
BroadcastEvent::StakingReward { .. } => BroadcastEventKind::StakingReward,
}
}
}
pub trait SlipstreamPlugin: Any + Send + Sync + std::fmt::Debug {
fn name(&self) -> &'static str;
fn on_load(&mut self, _config_file: &str, _is_reload: bool) -> Result<()> {
Ok(())
}
fn on_unload(&mut self) {}
fn subscribed_events(&self) -> &[BroadcastEventKind] {
&[]
}
fn on_broadcast(&self, _event: BroadcastEvent<'_>) -> Result<()> {
Ok(())
}
}