delta_base_sdk/sdl.rs
1//! # State Diff List (SDL)
2//!
3//! This module provides types and utilities for working with [State Diff Lists
4//! (SDLs)](`primitives::diff::list::StateDiffList`).
5
6use crate::core::Shard;
7use primitives::type_aliases::SdlId;
8use proto_types::{
9 error::{
10 HashSnafu,
11 ProtoError,
12 WronglyFormattedDataSnafu,
13 },
14 sdl::SdlUpdate as WireUpdate,
15};
16use snafu::{
17 OptionExt,
18 ResultExt,
19};
20
21// Re-export of types to be exposed by the base SDK
22pub use primitives::{
23 diff::{
24 aggregator::AggregatedStateDiff,
25 list::StateDiffList,
26 StateDiff,
27 },
28 proofs::sdl_proof::{
29 SDLProof,
30 VerificationKey,
31 },
32};
33pub use proto_types::sdl::SdlStatus;
34
35/// Update notification for a [StateDiffList] status or metadata
36///
37/// [SdlUpdate] represents a notification about a change to a SDL's status
38/// in the network. It is typically received through the events stream
39/// and allows clients to track the progress of their submitted SDLs.
40#[derive(Debug, Clone, Copy)]
41pub struct SdlUpdate {
42 /// Unique identifier of the SDL
43 pub id: SdlId,
44
45 /// Shard identifier that emitted this SDL
46 ///
47 /// Indicates which shard was responsible for creating and
48 /// submitting this SDL to the network.
49 pub originator: Shard,
50
51 /// Current processing status of the SDL
52 ///
53 /// Represents the SDL's status in the network's processing pipeline,
54 /// such as submitted, accepted, rejected, or proven.
55 pub status: SdlStatus,
56}
57
58/// Conversion from protocol buffer representation to native SDK type
59impl TryFrom<WireUpdate> for SdlUpdate {
60 type Error = ProtoError;
61
62 fn try_from(value: WireUpdate) -> Result<Self, Self::Error> {
63 Ok(Self {
64 id: value.sdl_id.try_into().context(HashSnafu)?,
65 originator: value.originator_shard,
66 status: value
67 .status
68 .try_into()
69 .ok()
70 .context(WronglyFormattedDataSnafu {
71 field: "status".to_string(),
72 })?,
73 })
74 }
75}