miden_proving_service_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#![allow(unused_imports)]
6#[macro_use]
7extern crate alloc;
8
9use alloc::{
10    boxed::Box,
11    string::{String, ToString},
12};
13use core::error::Error as CoreError;
14
15#[cfg(feature = "std")]
16extern crate std;
17
18use thiserror::Error;
19
20pub mod proving_service;
21
22/// Protobuf definition for the Miden proving service
23pub const PROVING_SERVICE_PROTO: &str = include_str!("../proto/proving_service.proto");
24
25/// ERRORS
26/// ===============================================================================================
27
28#[derive(Debug, Error)]
29pub enum RemoteProverError {
30    /// Indicates that the provided gRPC server endpoint is invalid.
31    #[error("invalid uri {0}")]
32    InvalidEndpoint(String),
33    #[error("failed to connect to prover {0}")]
34    /// Indicates that the connection to the server failed.
35    ConnectionFailed(#[source] Box<dyn CoreError + Send + Sync + 'static>),
36    /// Custom error variant for errors not covered by the other variants.
37    #[error("{error_msg}")]
38    Other {
39        error_msg: Box<str>,
40        // thiserror will return this when calling `Error::source` on `RemoteProverError`.
41        source: Option<Box<dyn CoreError + Send + Sync + 'static>>,
42    },
43}
44
45impl From<RemoteProverError> for String {
46    fn from(err: RemoteProverError) -> Self {
47        err.to_string()
48    }
49}
50
51impl RemoteProverError {
52    /// Creates a custom error using the [`RemoteProverError::Other`] variant from an error
53    /// message.
54    pub fn other(message: impl Into<String>) -> Self {
55        let message: String = message.into();
56        Self::Other { error_msg: message.into(), source: None }
57    }
58
59    /// Creates a custom error using the [`RemoteProverError::Other`] variant from an error
60    /// message and a source error.
61    pub fn other_with_source(
62        message: impl Into<String>,
63        source: impl CoreError + Send + Sync + 'static,
64    ) -> Self {
65        let message: String = message.into();
66        Self::Other {
67            error_msg: message.into(),
68            source: Some(Box::new(source)),
69        }
70    }
71}