Skip to main content

miden_remote_prover_client/
lib.rs

1#![no_std]
2// We allow unused imports here in order because this `macro_use` only makes sense for code
3// generated by prost under certain circumstances (when `tx-prover` is enabled and the environment
4// is not wasm)
5#![expect(unused_imports)]
6#[macro_use]
7extern crate alloc;
8
9use alloc::boxed::Box;
10use alloc::string::{String, ToString};
11use core::error::Error as CoreError;
12
13#[cfg(feature = "std")]
14extern crate std;
15
16use thiserror::Error;
17
18mod remote_prover;
19
20#[cfg(feature = "batch-prover")]
21pub use remote_prover::batch_prover::RemoteBatchProver;
22#[cfg(feature = "block-prover")]
23pub use remote_prover::block_prover::RemoteBlockProver;
24#[cfg(feature = "tx-prover")]
25pub use remote_prover::tx_prover::RemoteTransactionProver;
26
27/// ERRORS
28/// ===============================================================================================
29
30#[derive(Debug, Error)]
31pub enum RemoteProverClientError {
32    /// Indicates that the provided gRPC server endpoint is invalid.
33    #[error("invalid uri {0}")]
34    InvalidEndpoint(String),
35    #[error("failed to connect to prover {0}")]
36    /// Indicates that the connection to the server failed.
37    ConnectionFailed(#[source] Box<dyn CoreError + Send + Sync + 'static>),
38    /// Custom error variant for errors not covered by the other variants.
39    #[error("{error_msg}")]
40    Other {
41        error_msg: Box<str>,
42        // thiserror will return this when calling `Error::source` on `RemoteProverClientError`.
43        source: Option<Box<dyn CoreError + Send + Sync + 'static>>,
44    },
45}
46
47impl From<RemoteProverClientError> for String {
48    fn from(err: RemoteProverClientError) -> Self {
49        err.to_string()
50    }
51}
52
53impl RemoteProverClientError {
54    /// Creates a custom error using the [`RemoteProverClientError::Other`] variant from an error
55    /// message.
56    pub fn other(message: impl Into<String>) -> Self {
57        let message: String = message.into();
58        Self::Other { error_msg: message.into(), source: None }
59    }
60
61    /// Creates a custom error using the [`RemoteProverClientError::Other`] variant from an error
62    /// message and a source error.
63    pub fn other_with_source(
64        message: impl Into<String>,
65        source: impl CoreError + Send + Sync + 'static,
66    ) -> Self {
67        let message: String = message.into();
68        Self::Other {
69            error_msg: message.into(),
70            source: Some(Box::new(source)),
71        }
72    }
73}