Skip to main content

sol_parser_sdk/shredstream/proto/
mod.rs

1//! ShredStream protobuf 定义
2
3pub mod shredstream {
4    //! ShredStream gRPC 服务定义
5
6    use tonic::codegen::*;
7
8    /// Entry 订阅请求
9    #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
10    pub struct SubscribeEntriesRequest {}
11
12    /// Entry 数据
13    #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
14    pub struct Entry {
15        /// 槽位号
16        #[prost(uint64, tag = "1")]
17        pub slot: u64,
18        /// 序列化的 Entry 数据(Vec<SolanaEntry> 的 bincode 编码)
19        #[prost(bytes = "vec", tag = "2")]
20        pub entries: ::prost::alloc::vec::Vec<u8>,
21    }
22
23    /// ShredStream Proxy 客户端
24    #[derive(Debug, Clone)]
25    pub struct ShredstreamProxyClient<T> {
26        inner: tonic::client::Grpc<T>,
27    }
28
29    impl ShredstreamProxyClient<tonic::transport::Channel> {
30        /// 连接到指定端点
31        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
32        where
33            D: TryInto<tonic::transport::Endpoint>,
34            D::Error: Into<StdError>,
35        {
36            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
37            Ok(Self::new(conn))
38        }
39    }
40
41    impl<T> ShredstreamProxyClient<T>
42    where
43        T: tonic::client::GrpcService<tonic::body::Body>,
44        T::Error: Into<StdError>,
45        T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
46        <T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
47    {
48        pub fn new(inner: T) -> Self {
49            let inner = tonic::client::Grpc::new(inner);
50            Self { inner }
51        }
52
53        /// 订阅 Entry 流
54        pub async fn subscribe_entries(
55            &mut self,
56            request: impl tonic::IntoRequest<SubscribeEntriesRequest>,
57        ) -> std::result::Result<tonic::Response<tonic::codec::Streaming<Entry>>, tonic::Status>
58        {
59            self.inner.ready().await.map_err(|e| {
60                tonic::Status::unknown(format!("Service was not ready: {}", e.into()))
61            })?;
62            let codec = tonic::codec::ProstCodec::default();
63            let path = http::uri::PathAndQuery::from_static(
64                "/shredstream.ShredstreamProxy/SubscribeEntries",
65            );
66            let mut req = request.into_request();
67            req.extensions_mut()
68                .insert(GrpcMethod::new("shredstream.ShredstreamProxy", "SubscribeEntries"));
69            self.inner.server_streaming(req, path, codec).await
70        }
71    }
72}
73
74pub use shredstream::{Entry, ShredstreamProxyClient, SubscribeEntriesRequest};