zoe_client/services/
blob_store.rs

1mod blob_service;
2mod multi_relay_blob_service;
3
4pub use blob_service::BlobService;
5pub use multi_relay_blob_service::MultiRelayBlobService;
6
7use async_trait::async_trait;
8use zoe_wire_protocol::{BlobError as WireError, BlobId};
9
10#[cfg(any(feature = "mock", test))]
11use mockall::{automock, predicate::*};
12
13#[derive(Debug, thiserror::Error)]
14pub enum BlobError {
15    #[error("Blob not found: {hash}")]
16    NotFound { hash: BlobId },
17
18    #[error("IO error: {0}")]
19    IoError(std::io::Error),
20
21    #[error("Serialization error: {0}")]
22    SerializationError(String),
23
24    #[error("RPC error: {0}")]
25    RpcError(tarpc::client::RpcError),
26
27    #[error("Wire blob error: {0}")]
28    WireError(WireError),
29}
30
31pub type Result<T> = std::result::Result<T, BlobError>;
32
33/// Trait for blob storage operations, enabling mocking in tests
34#[cfg_attr(any(feature = "mock", test), automock(type Error = BlobError;))]
35#[async_trait]
36pub trait BlobStore: Send + Sync {
37    /// Download a blob by its ID
38    async fn get_blob(&self, blob_id: &BlobId) -> std::result::Result<Vec<u8>, BlobError>;
39
40    /// Upload a blob and return its hash
41    async fn upload_blob(&self, blob: &[u8]) -> std::result::Result<BlobId, BlobError>;
42}