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        /// 设置最大解码消息大小
54        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
55            self.inner = self.inner.max_decoding_message_size(limit);
56            self
57        }
58
59        /// 设置最大编码消息大小
60        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
61            self.inner = self.inner.max_encoding_message_size(limit);
62            self
63        }
64
65        /// 订阅 Entry 流
66        pub async fn subscribe_entries(
67            &mut self,
68            request: impl tonic::IntoRequest<SubscribeEntriesRequest>,
69        ) -> std::result::Result<tonic::Response<tonic::codec::Streaming<Entry>>, tonic::Status>
70        {
71            self.inner.ready().await.map_err(|e| {
72                tonic::Status::unknown(format!("Service was not ready: {}", e.into()))
73            })?;
74            let codec = tonic::codec::ProstCodec::default();
75            let path = http::uri::PathAndQuery::from_static(
76                "/shredstream.ShredstreamProxy/SubscribeEntries",
77            );
78            let mut req = request.into_request();
79            req.extensions_mut()
80                .insert(GrpcMethod::new("shredstream.ShredstreamProxy", "SubscribeEntries"));
81            self.inner.server_streaming(req, path, codec).await
82        }
83    }
84}
85
86pub use shredstream::{Entry, ShredstreamProxyClient, SubscribeEntriesRequest};