use hyperstack_interpreter::Mutation;
use smallvec::SmallVec;
use tracing::Span;
#[derive(Debug, Clone, Copy, Default)]
pub struct SlotContext {
pub slot: u64,
pub slot_index: u64,
}
impl SlotContext {
pub fn new(slot: u64, slot_index: u64) -> Self {
Self { slot, slot_index }
}
pub fn to_seq_string(&self) -> String {
format!("{}:{:012}", self.slot, self.slot_index)
}
}
#[derive(Debug)]
pub struct MutationBatch {
pub span: Span,
pub mutations: SmallVec<[Mutation; 6]>,
pub slot_context: Option<SlotContext>,
pub event_context: Option<EventContext>,
}
#[derive(Debug, Clone)]
pub struct EventContext {
pub program: String,
pub event_kind: String,
pub event_type: String,
pub account: Option<String>,
pub accounts_count: Option<usize>,
}
impl MutationBatch {
pub fn new(mutations: SmallVec<[Mutation; 6]>) -> Self {
Self {
span: Span::current(),
mutations,
slot_context: None,
event_context: None,
}
}
pub fn with_span(span: Span, mutations: SmallVec<[Mutation; 6]>) -> Self {
Self {
span,
mutations,
slot_context: None,
event_context: None,
}
}
pub fn with_slot_context(
mutations: SmallVec<[Mutation; 6]>,
slot_context: SlotContext,
) -> Self {
Self {
span: Span::current(),
mutations,
slot_context: Some(slot_context),
event_context: None,
}
}
pub fn with_event_context(mut self, event_context: EventContext) -> Self {
self.event_context = Some(event_context);
self
}
pub fn len(&self) -> usize {
self.mutations.len()
}
pub fn is_empty(&self) -> bool {
self.mutations.is_empty()
}
}