Skip to main content

miden_client/grpc_support/
mod.rs

1use alloc::string::String;
2#[cfg(feature = "tonic")]
3use core::time::Duration;
4
5#[cfg(feature = "tonic")]
6pub use crate::RemoteTransactionProver;
7
8/// Default remote prover endpoint for mainnet.
9pub const MAINNET_PROVER_ENDPOINT: &str = "https://tx-prover.mainnet.miden.io";
10
11/// Default remote prover endpoint for testnet.
12pub const TESTNET_PROVER_ENDPOINT: &str = "https://tx-prover.testnet.miden.io";
13
14/// Default remote prover endpoint for devnet.
15pub const DEVNET_PROVER_ENDPOINT: &str = "https://tx-prover.devnet.miden.io";
16
17/// Default timeout in milliseconds for gRPC connections (10 seconds).
18pub const DEFAULT_GRPC_TIMEOUT_MS: u64 = 10_000;
19
20/// Configuration for lazy note transport initialization.
21///
22/// Since `GrpcNoteTransportClient::connect()` is async, this struct allows us to defer the
23/// connection until `build()` is called.
24pub struct NoteTransportConfig {
25    pub endpoint: String,
26    pub timeout_ms: u64,
27}
28
29// RETRY HELPERS
30// ================================================================================================
31
32/// Returns the delay that the `retry-after` metadata value of `status` requests, in whole seconds.
33#[cfg(feature = "tonic")]
34pub(crate) fn extract_retry_after(status: &tonic::Status) -> Option<Duration> {
35    status
36        .metadata()
37        .get("retry-after")
38        .and_then(|v| v.to_str().ok())
39        .and_then(|s| s.parse::<u64>().ok())
40        .map(Duration::from_secs)
41}
42
43#[cfg(all(feature = "tonic", not(target_arch = "wasm32")))]
44pub(crate) async fn async_sleep(duration: Duration) {
45    tokio::time::sleep(duration).await;
46}
47
48/// On WASM, sleep using browser timers so retry delays are honored.
49#[cfg(all(feature = "tonic", target_arch = "wasm32"))]
50pub(crate) async fn async_sleep(duration: Duration) {
51    gloo_timers::future::sleep(duration).await;
52}