Skip to main content

quai_rpc/
lib.rs

1//! Explicit shard routing and a bounded JSON-RPC transport.
2//!
3//! Routing has no network side effects. Native HTTP and WebSocket transports are
4//! optional; native futures are Send while browser adapters have a separate bound.
5
6/// General resource requests with explicit limits and lifecycle.
7pub mod fetch;
8
9mod quantity;
10mod routing;
11mod transport;
12
13pub use quantity::{QuantityError, U256, parse_quantity};
14pub use routing::{Endpoint, RouteError, Routing, parse_use_pathing};
15pub use transport::{BatchResult, MAX_BATCH_CALLS, RemoteError, RpcError, Transport};
16
17#[cfg(not(target_arch = "wasm32"))]
18mod dyn_transport;
19#[cfg(not(target_arch = "wasm32"))]
20pub use dyn_transport::DynTransport;
21
22#[cfg(all(feature = "http", not(target_arch = "wasm32")))]
23mod http;
24#[cfg(all(feature = "http", not(target_arch = "wasm32")))]
25pub use http::{HttpConfig, HttpProxy, HttpTransport};
26
27#[cfg(all(feature = "ws", not(target_arch = "wasm32")))]
28mod websocket;
29#[cfg(all(feature = "ws", not(target_arch = "wasm32")))]
30pub use websocket::{WsConfig, WsSubscription, WsSubscriptionKind, WsTransport};
31
32/// Internal decoders exposed for fuzzing only.
33///
34/// Not public API: the `fuzzing` feature is off by default, these items are
35/// hidden from documentation, and their signatures may change without notice.
36/// They exist so the fuzz harness can reach the JSON-RPC envelope decoders,
37/// which every byte a remote node sends passes through, without widening the
38/// supported surface for ordinary consumers.
39#[cfg(feature = "fuzzing")]
40#[doc(hidden)]
41pub mod fuzz_internals {
42    /// Decode one JSON-RPC response envelope against its expected request ID.
43    #[cfg(all(feature = "http", not(target_arch = "wasm32")))]
44    pub fn decode_response(
45        bytes: &[u8],
46        expected_id: u64,
47    ) -> Result<serde_json::Value, crate::RpcError> {
48        crate::transport::decode_response(bytes, expected_id)
49    }
50
51    /// Decode a JSON-RPC batch response against its issued ID window.
52    #[cfg(all(feature = "http", not(target_arch = "wasm32")))]
53    pub fn decode_batch(bytes: &[u8], first: u64, count: usize) -> crate::BatchResult {
54        crate::http::decode_batch(bytes, first, count)
55    }
56
57    /// Route WebSocket frames through the session dispatcher against a
58    /// synthetic session that `layout` selects, asserting reply routing.
59    #[cfg(all(feature = "ws", not(target_arch = "wasm32")))]
60    pub fn dispatch_frames(layout: u8, frames: &[&[u8]]) {
61        crate::websocket::fuzz_dispatch(layout, frames)
62    }
63}