Skip to main content

BatchStore

Trait BatchStore 

Source
pub trait BatchStore {
    type Error: Error;

    // Required methods
    fn get(&self, id: &BatchId) -> Result<Option<Batch>, Self::Error>;
    fn put(&self, batch: Batch) -> Result<(), Self::Error>;
    fn remove(&self, id: &BatchId) -> Result<bool, Self::Error>;
    fn contains(&self, id: &BatchId) -> Result<bool, Self::Error>;
    fn context(&self) -> Result<PostageContext, Self::Error>;
    fn set_context(&self, state: PostageContext) -> Result<(), Self::Error>;
    fn batch_ids(&self) -> Result<Vec<BatchId>, Self::Error>;
    fn count(&self) -> Result<usize, Self::Error>;
}
Available on crate feature std only.
Expand description

A trait for storing and retrieving batches.

Implementations may persist batches in memory, on disk, or retrieve them from a remote source such as a blockchain node.

§Synchronous Design

The methods are synchronous. The known backends (in memory, redb) are themselves synchronous, so there is no genuinely async work to drive here; any async behaviour belongs at the true edges (a gRPC service, an FFI boundary) where it is added by the edge, not by the store. Keeping the core synchronous avoids colouring every caller with async, keeps the futures Send-free on the wasm path, and makes this trait naturally object-safe (it has an associated Error and no generic methods), a property the previous async-in-trait shape did not have.

Required Associated Types§

Source

type Error: Error

The error type returned by store operations.

Required Methods§

Source

fn get(&self, id: &BatchId) -> Result<Option<Batch>, Self::Error>

Retrieves a batch by its ID.

Returns None if the batch doesn’t exist.

Source

fn put(&self, batch: Batch) -> Result<(), Self::Error>

Stores or updates a batch.

Source

fn remove(&self, id: &BatchId) -> Result<bool, Self::Error>

Removes a batch from the store.

Returns true if the batch existed and was removed.

Source

fn contains(&self, id: &BatchId) -> Result<bool, Self::Error>

Checks if a batch exists in the store.

Source

fn context(&self) -> Result<PostageContext, Self::Error>

Returns the current postage context.

Source

fn set_context(&self, state: PostageContext) -> Result<(), Self::Error>

Updates the postage context.

Source

fn batch_ids(&self) -> Result<Vec<BatchId>, Self::Error>

Returns all batch IDs in the store.

Source

fn count(&self) -> Result<usize, Self::Error>

Returns the number of batches in the store.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§