remove state for tutorial

This commit is contained in:
kashepavadan 2026-05-26 00:22:44 -04:00
parent 2fe8c9f310
commit 86ba386c81

View File

@ -1,5 +1,5 @@
use lb_core::mantle::ops::channel::MsgId;
use lb_zone_sdk::{sequencer::SequencerCheckpoint, state::InscriptionInfo};
use lb_zone_sdk::state::InscriptionInfo;
use crate::message::Msg;
@ -31,76 +31,6 @@ pub trait ZoneState: Send {
fn published(&self) -> &[Msg];
fn adopted(&self) -> &[Msg];
fn finalized(&self) -> &[Msg];
fn save_checkpoint(&mut self, checkpoint: SequencerCheckpoint);
fn load_checkpoint(&self) -> Option<&SequencerCheckpoint>;
}
/// In-memory implementation of [`ZoneState`].
#[derive(Default)]
pub struct InMemoryZoneState {
published: Vec<Msg>,
adopted: Vec<Msg>,
finalized: Vec<Msg>,
checkpoint: Option<SequencerCheckpoint>,
}
impl ZoneState for InMemoryZoneState {
fn on_published(&mut self, info: &InscriptionInfo) {
self.published
.push(Msg::from_payload(info.this_msg, &info.payload));
}
fn on_adopted(&mut self, adopted: &[InscriptionInfo]) {
for info in adopted {
if !self.adopted.iter().any(|m| m.msg_id == info.this_msg) {
self.adopted
.push(Msg::from_payload(info.this_msg, &info.payload));
}
}
}
fn on_orphaned(&mut self, msg_id: &MsgId) {
if let Some(i) = self.published.iter().position(|m| &m.msg_id == msg_id) {
self.published.remove(i);
}
}
fn on_finalized(&mut self, inscriptions: &[InscriptionInfo]) {
for info in inscriptions {
if let Some(i) = self
.published
.iter()
.position(|m| m.msg_id == info.this_msg)
{
self.published.remove(i);
} else if let Some(i) = self.adopted.iter().position(|m| m.msg_id == info.this_msg) {
self.adopted.remove(i);
}
if !self.finalized.iter().any(|m| m.msg_id == info.this_msg) {
self.finalized
.push(Msg::from_payload(info.this_msg, &info.payload));
}
}
}
fn published(&self) -> &[Msg] {
&self.published
}
fn adopted(&self) -> &[Msg] {
&self.adopted
}
fn finalized(&self) -> &[Msg] {
&self.finalized
}
fn save_checkpoint(&mut self, checkpoint: SequencerCheckpoint) {
self.checkpoint = Some(checkpoint);
}
fn load_checkpoint(&self) -> Option<&SequencerCheckpoint> {
self.checkpoint.as_ref()
}
}
// Your code here